Spaces:
Running
Running
Rename to Scott Wu Math; add eval results; mobile layout fixes
Browse filesFiles changed (14)
- Dockerfile+5-5
- README.md+47-10
- __init__.py+3-3
- client.py+4-4
- models.py+1-1
- openenv.yaml+2-2
- pyproject.toml+6-6
- scripts/build_tasks.py+4-4
- server/app.py+4-4
- server/environment.py+2-2
- server/web/app.css+3-1
- server/web/app.js+1-1
- server/web/card.html+2-2
- server/web/index.html+2-2
1234567891011121314# Card Arithmetic: OpenEnv server + play page. Pure Python, no GPU.# docker build -t card-arithmetic . && docker run -p 7860:7860 card-arithmeticFROM python:3.12-slimENV PYTHONDONTWRITEBYTECODE=1 PYTHONUNBUFFERED=1 PORT=7860RUN useradd -m -u 1000 userWORKDIR /home/user/appCOPY --chown=user . ./card_arithmeticRUN pip install --no-cache-dir ./card_arithmeticUSER userEXPOSE 7860CMD ["sh", "-c", "uvicorn card_arithmetic.server.app:app --host 0.0.0.0 --port ${PORT} --proxy-headers --forwarded-allow-ips='*'"]1234567891011121314# Scott Wu Math: OpenEnv server + play page. Pure Python, no GPU.# docker build -t scott-wu-math . && docker run -p 7860:7860 scott-wu-mathFROM python:3.12-slimENV PYTHONDONTWRITEBYTECODE=1 PYTHONUNBUFFERED=1 PORT=7860RUN useradd -m -u 1000 userWORKDIR /home/user/appCOPY --chown=user . ./scott_wu_mathRUN pip install --no-cache-dir ./scott_wu_mathUSER userEXPOSE 7860CMD ["sh", "-c", "uvicorn scott_wu_math.server.app:app --host 0.0.0.0 --port ${PORT} --proxy-headers --forwarded-allow-ips='*'"]
123451 unmodified line789101112131 unmodified line15161718192021222324252665 unmodified lines92939495969798991003 unmodified lines10410510610710810911011111211311 unmodified lines125126127128129130131132133134135136137138139---title: Card Arithmeticemoji: 🃏colorFrom: greencolorTo: gray1 unmodified lineapp_port: 7860pinned: falselicense: apache-2.0short_description: Make the year from 8 playing cards with + − × ÷. OpenEnv.tags:- openenv- reinforcement-learning1 unmodified line- reasoning---# Card ArithmeticDeal some playing cards, name a number, and make that number from the cards with + − × ÷, using everycard exactly once. People and language models play the same environment: the page at `/` drives thesame OpenEnv session over `/ws` that an agent does.## Where it comes fromIn a clip filmed at a pub, Cognition's CEO Scott Wu explains the game he plays with a deck of cards.65 unmodified lines## Use it```pythonfrom card_arithmetic import CardAction, CardArithmeticEnvwith CardArithmeticEnv(base_url="https://fineenvs-cardarithmetic.hf.space").sync() as env:obs = env.reset(split="video", index=1).observationprint(obs.prompt)result = env.step(CardAction(expression="(((12 - 10) * (6 + 4) * 10 + 8) * 11 - 7) * 3"))3 unmodified linesOver plain WebSocket (what the play page does): connect to `/ws`, send`{"type": "reset", "data": {"level": "four-digit"}}`, then `{"type": "step", "data": {"expression": "..."}}`.Task discovery follows OpenEnv's Task API: `GET /card_arithmetic/splits`, `POST /card_arithmetic/tasks`with `{"split": "test"}`, and so on. Task listings leave out the reference solutions.For text-only RL (no server), `card_arithmetic.game.reward.grade(expression, card_values, target)` and`extract_answer(completion)` are the same grader as a plain function, and `game.prompts.messages(cards, target)`builds the same prompt.11 unmodified lines```bashpip install -e .uvicorn card_arithmetic.server.app:app --port 8012 # play at http://localhost:8012python scripts/build_tasks.py # rebuild data/tasks (deterministic)pytest```## Evaluations`eval/rollout.py` in the [FineEnvs repository](https://github.com/adithya-s-k/FineEnvs/tree/main/12-card-arithmetic)runs OpenAI, Anthropic and open models on Hugging Face Inference Providers against a running server, inparallel, one OpenEnv session per episode.<!-- results -->123451 unmodified line789101112131 unmodified line15161718192021222324252627282965 unmodified lines95969798991001011021033 unmodified lines10710810911011111211311411511611 unmodified lines128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176---title: Scott Wu Mathemoji: 🃏colorFrom: greencolorTo: gray1 unmodified lineapp_port: 7860pinned: falselicense: apache-2.0short_description: Scott Wu's card game as an OpenEnv RL environmenttags:- openenv- reinforcement-learning1 unmodified line- reasoning---# Scott Wu MathDeal some playing cards, name a number, and make that number from the cards with + − × ÷, using everycard exactly once. People and language models play the same environment: the page at `/` drives thesame OpenEnv session over `/ws` that an agent does.Named after the game Scott Wu plays in the clip below, as a fan tribute. It is not affiliated with orendorsed by Scott Wu or Cognition.## Where it comes fromIn a clip filmed at a pub, Cognition's CEO Scott Wu explains the game he plays with a deck of cards.65 unmodified lines## Use it```pythonfrom scott_wu_math import CardAction, ScottWuMathEnvwith ScottWuMathEnv(base_url="https://fineenvs-scottwumath.hf.space").sync() as env:obs = env.reset(split="video", index=1).observationprint(obs.prompt)result = env.step(CardAction(expression="(((12 - 10) * (6 + 4) * 10 + 8) * 11 - 7) * 3"))3 unmodified linesOver plain WebSocket (what the play page does): connect to `/ws`, send`{"type": "reset", "data": {"level": "four-digit"}}`, then `{"type": "step", "data": {"expression": "..."}}`.Task discovery follows OpenEnv's Task API: `GET /scott_wu_math/splits`, `POST /scott_wu_math/tasks`with `{"split": "test"}`, and so on. Task listings leave out the reference solutions.For text-only RL (no server), `scott_wu_math.game.reward.grade(expression, card_values, target)` and`extract_answer(completion)` are the same grader as a plain function, and `game.prompts.messages(cards, target)`builds the same prompt.11 unmodified lines```bashpip install -e .uvicorn scott_wu_math.server.app:app --port 8012 # play at http://localhost:8012python scripts/build_tasks.py # rebuild data/tasks (deterministic)pytest```## Evaluations`eval/rollout.py` in the [FineEnvs repository](https://github.com/adithya-s-k/FineEnvs/tree/main/12-scott-wu-math)runs OpenAI, Anthropic and open models on Hugging Face Inference Providers against a running server, inparallel, one OpenEnv session per episode.### Results (2026-10-23)Twelve models on the first five `test` deals of each level (20 deals, one sample each) and on the two`video` hands (three samples each), in three modes:- **Reasoning**: the model's own reasoning at high effort, up to 32k output tokens.- **No reasoning**: reasoning switched off, or as low as the API allows (`*`), up to 32k tokens, so themodel may still work it out in its visible reply.- **At once**: no reasoning, a system line asking for the answer tag alone, and 300 output tokens: themental-arithmetic version of the game.| Model | Reasoning | No reasoning | At once | Video hands: reasoning / none / at once ||---|---|---|---|---|| GPT-6.1 Sol | 20/20 | 20/20* | 14/20* | 6/6 / 6/6 / 3/6 || Claude Opus 5.5 | 20/20 | 19/20* | 8/20* | 6/6 / 6/6 / 5/6 || GLM-5.3 | 17/20 | 19/20 | 5/20 | 6/6 / 5/6 / 0/6 || Qwen3.8 2.4T | 20/20 | 19/20 | 4/20 | 6/6 / 5/6 / 0/6 || Claude Sonnet 5.5 | 20/20 | 15/20 | 4/20 | 6/6 / 4/6 / 0/6 || Claude Haiku 5.5 | 20/20 | 11/20 | 3/20 | 6/6 / 5/6 / 0/6 || Kimi K2.6 | 19/20 | 20/20 | 2/20 | 6/6 / 6/6 / 0/6 || DeepSeek V4 Pro | 20/20 | 10/20 | 2/20 | 6/6 / 3/6 / 0/6 || gpt-oss-120b | 16/20 | 6/20* | 2/20* | 6/6 / 1/6 / 0/6 || GPT-6 Luna | 20/20 | 2/20 | 2/20 | 5/6 / 0/6 / 0/6 || Qwen3.8 27B | 18/20 | 20/20 | 1/20 | 6/6 / 6/6 / 0/6 || Gemma 4 31B | 19/20 | 18/20 | 1/20 | 5/6 / 5/6 / 0/6 |`*` lowest effort the API allows: GPT-6.1 Sol and gpt-oss-120b at `low`, Claude Opus 5.5 at `low` (itsthinking cannot be disabled). Open models ran on Hugging Face Inference Providers (Qwen3.8 2.4T and KimiK2.6 on DeepInfra; DeepSeek V4 Pro, GLM-5.3 and Qwen3.8 27B on Novita; gpt-oss-120b on Cerebras; Gemma 431B on DeepInfra). Gemma and Kimi each lost one or two episodes to provider errors, counted as failures.With reasoning the game is close to solved: every model makes 6,843 on the first try. Answering at onceseparates them: only GPT-6.1 Sol and Claude Opus 5.5, which still reason briefly at their lowest effort,get far; most other models start working out loud and run out of room. That gap, and the no-reasoningcolumn for the smaller models, is where there is something to train.
123456"""Card Arithmetic: an OpenEnv environment for mental arithmetic with playing cards."""from .client import CardArithmeticEnvfrom .models import CardAction, CardObservation, CardState__all__ = ["CardAction", "CardArithmeticEnv", "CardObservation", "CardState"]123456"""Scott Wu Math: an OpenEnv environment for mental arithmetic with playing cards."""from .client import ScottWuMathEnvfrom .models import CardAction, CardObservation, CardState__all__ = ["CardAction", "ScottWuMathEnv", "CardObservation", "CardState"]
1234567810 unmodified lines19202122232425"""Client for a running Card Arithmetic server (local, Docker or a Hugging Face Space).from card_arithmetic import CardAction, CardArithmeticEnvwith CardArithmeticEnv(base_url="http://localhost:8012").sync() as env:obs = env.reset(level="four-digit", seed=7).observationprint(obs.prompt)result = env.step(CardAction(expression="..."))10 unmodified linesfrom .models import CardAction, CardObservation, CardStateclass CardArithmeticEnv(EnvClient[CardAction, CardObservation, CardState]):def _step_payload(self, action: CardAction) -> Dict[str, Any]:return action.model_dump(exclude={"metadata"})1234567810 unmodified lines19202122232425"""Client for a running Scott Wu Math server (local, Docker or a Hugging Face Space).from scott_wu_math import CardAction, ScottWuMathEnvwith ScottWuMathEnv(base_url="http://localhost:8012").sync() as env:obs = env.reset(level="four-digit", seed=7).observationprint(obs.prompt)result = env.step(CardAction(expression="..."))10 unmodified linesfrom .models import CardAction, CardObservation, CardStateclass ScottWuMathEnv(EnvClient[CardAction, CardObservation, CardState]):def _step_payload(self, action: CardAction) -> Dict[str, Any]:return action.model_dump(exclude={"metadata"})
1234"""Action, observation and state of the Card Arithmetic environment."""from __future__ import annotations1234"""Action, observation and state of the Scott Wu Math environment."""from __future__ import annotations
123456spec_version: 1name: card_arithmetictype: spaceruntime: fastapiapp: card_arithmetic.server.app:appport: 8000123456spec_version: 1name: scott_wu_mathtype: spaceruntime: fastapiapp: scott_wu_math.server.app:appport: 8000
2 unmodified lines34567899 unmodified lines192021222324252627282930313233342 unmodified linesbuild-backend = "setuptools.build_meta"[project]name = "card-arithmetic"version = "0.1.0"description = "OpenEnv environment: make a target number from playing cards with + - * /, every card once"requires-python = ">=3.11"9 unmodified lineseval = ["openai>=1.50.0", "python-dotenv>=1.0.0"][project.scripts]card-arithmetic-server = "card_arithmetic.server.app:main"[tool.setuptools]include-package-data = truepackages = ["card_arithmetic", "card_arithmetic.server", "card_arithmetic.game"]package-dir = { "card_arithmetic" = ".", "card_arithmetic.server" = "server", "card_arithmetic.game" = "game" }[tool.setuptools.package-data]card_arithmetic = ["data/tasks/*.jsonl", "README.md", "openenv.yaml"]"card_arithmetic.server" = ["web/*"][tool.pytest.ini_options]testpaths = ["tests"]2 unmodified lines34567899 unmodified lines192021222324252627282930313233342 unmodified linesbuild-backend = "setuptools.build_meta"[project]name = "scott-wu-math"version = "0.1.0"description = "OpenEnv environment: make a target number from playing cards with + - * /, every card once"requires-python = ">=3.11"9 unmodified lineseval = ["openai>=1.50.0", "python-dotenv>=1.0.0"][project.scripts]scott-wu-math-server = "scott_wu_math.server.app:main"[tool.setuptools]include-package-data = truepackages = ["scott_wu_math", "scott_wu_math.server", "scott_wu_math.game"]package-dir = { "scott_wu_math" = ".", "scott_wu_math.server" = "server", "scott_wu_math.game" = "game" }[tool.setuptools.package-data]scott_wu_math = ["data/tasks/*.jsonl", "README.md", "openenv.yaml"]"scott_wu_math.server" = ["web/*"][tool.pytest.ini_options]testpaths = ["tests"]
1234569 unmodified lines161718192021222324"""Build the fixed task splits in data/tasks/.python -m card_arithmetic.scripts.build_tasks # or: python scripts/build_tasks.py from the env dirtest: 50 deals per level (200), seed 2026train: 1,000 deals per level (4,000), seed 7, none sharing an id with test9 unmodified linesHERE = Path(__file__).resolve().parents[1]sys.path.insert(0, str(HERE.parent))from card_arithmetic.game.cards import Card # noqa: E402from card_arithmetic.game.expr import parse, steps, to_text # noqa: E402from card_arithmetic.game.tasks import LEVELS, make_task # noqa: E402OUT = HERE / "data" / "tasks"1234569 unmodified lines161718192021222324"""Build the fixed task splits in data/tasks/.python -m scott_wu_math.scripts.build_tasks # or: python scripts/build_tasks.py from the env dirtest: 50 deals per level (200), seed 2026train: 1,000 deals per level (4,000), seed 7, none sharing an id with test9 unmodified linesHERE = Path(__file__).resolve().parents[1]sys.path.insert(0, str(HERE.parent))from scott_wu_math.game.cards import Card # noqa: E402from scott_wu_math.game.expr import parse, steps, to_text # noqa: E402from scott_wu_math.game.tasks import LEVELS, make_task # noqa: E402OUT = HERE / "data" / "tasks"
1234566 unmodified lines131415161718192 unmodified lines22232425262728293031"""FastAPI app: the OpenEnv API (/reset, /step, /state, /ws, /schema, task routes) plus the play page at /.uvicorn card_arithmetic.server.app:app --port 8012"""from __future__ import annotations6 unmodified linesfrom openenv.core.env_server.http_server import create_appfrom ..models import CardAction, CardObservation, CardStatefrom .environment import CardArithmeticEnvironmentWEB = Path(__file__).resolve().parent / "web"README = Path(__file__).resolve().parents[1] / "README.md"2 unmodified linesos.environ["ENABLE_WEB_INTERFACE"] = "false"app = create_app(CardArithmeticEnvironment,CardAction,CardObservation,env_name="card_arithmetic",max_concurrent_envs=int(os.getenv("MAX_CONCURRENT_ENVS", "256")),state_cls=CardState,)1234566 unmodified lines131415161718192 unmodified lines22232425262728293031"""FastAPI app: the OpenEnv API (/reset, /step, /state, /ws, /schema, task routes) plus the play page at /.uvicorn scott_wu_math.server.app:app --port 8012"""from __future__ import annotations6 unmodified linesfrom openenv.core.env_server.http_server import create_appfrom ..models import CardAction, CardObservation, CardStatefrom .environment import ScottWuMathEnvironmentWEB = Path(__file__).resolve().parent / "web"README = Path(__file__).resolve().parents[1] / "README.md"2 unmodified linesos.environ["ENABLE_WEB_INTERFACE"] = "false"app = create_app(ScottWuMathEnvironment,CardAction,CardObservation,env_name="scott_wu_math",max_concurrent_envs=int(os.getenv("MAX_CONCURRENT_ENVS", "256")),state_cls=CardState,)
123431 unmodified lines36373839404142"""Card Arithmetic: deal cards, name a target, make it with + - * / using every card once.One episode is one deal and one graded submission. `reset` deals (from a split of the task set,from a level, or for a custom target or hand); `step` takes the final expression, grades it once,31 unmodified linesreturn _TASKS[split]class CardArithmeticEnvironment(Environment[CardAction, CardObservation, CardState]):SUPPORTS_CONCURRENT_SESSIONS = Truedef __init__(self) -> None:123431 unmodified lines36373839404142"""Scott Wu Math: deal cards, name a target, make it with + - * / using every card once.One episode is one deal and one graded submission. `reset` deals (from a split of the task set,from a level, or for a custom target or hand); `step` takes the final expression, grades it once,31 unmodified linesreturn _TASKS[split]class ScottWuMathEnvironment(Environment[CardAction, CardObservation, CardState]):SUPPORTS_CONCURRENT_SESSIONS = Truedef __init__(self) -> None:
238 unmodified lines239240241242243244245238 unmodified lines.table { padding: 14px 12px; min-height: 0; }.target { font-size: 28px; }.piles { gap: 10px 8px; }.pile { --cw: clamp(60px, calc((100cqw - 3 * 8px) / 4), 84px); }.typed { flex-wrap: wrap; }.typed label { flex-basis: 100%; }.steps.compact { padding-left: 22px; }238 unmodified lines239240241242243244245246247238 unmodified lines.table { padding: 14px 12px; min-height: 0; }.target { font-size: 28px; }.piles { gap: 10px 8px; }.pile { --per: min(var(--n, 8), 5); --cw: clamp(54px, calc((100cqw - (var(--per) - 1) * 8px) / var(--per)), 84px); }.controls { display: grid; grid-template-columns: 1fr 1fr; }.controls .grow { display: none; }.typed { flex-wrap: wrap; }.typed label { flex-basis: 100%; }.steps.compact { padding-left: 22px; }
279 unmodified lines280281282283284285286279 unmodified lines}// ---- per-browser record --------------------------------------------------------const STORE = "card-arithmetic-stats-v1";function load() { try { return JSON.parse(localStorage.getItem(STORE)) || {}; } catch { return {}; } }function record(task, solved, secs) {const all = load(), key = task.task_id.startsWith("video-") ? "video" : task.level;279 unmodified lines280281282283284285286279 unmodified lines}// ---- per-browser record --------------------------------------------------------const STORE = "scott-wu-math-stats-v1";function load() { try { return JSON.parse(localStorage.getItem(STORE)) || {}; } catch { return {}; } }function record(task, solved, secs) {const all = load(), key = task.task_id.startsWith("video-") ? "video" : task.level;
2 unmodified lines345678913 unmodified lines232425262728292 unmodified lines<head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>Card Arithmetic · Environment card</title><link rel="stylesheet" href="/static/app.css"><style>.doc { max-width: 820px; margin: 0 auto; padding: 24px 24px 64px; }13 unmodified lines</head><body><header class="bar"><div class="brand"><a href="/" style="text-decoration:none">Card Arithmetic</a></div><nav><a href="/">Play</a><a href="/static/card.html" aria-current="page">Environment card</a><a href="/docs">API</a></nav></header><article class="doc" id="doc">Loading…</article>2 unmodified lines345678913 unmodified lines232425262728292 unmodified lines<head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>Scott Wu Math · Environment card</title><link rel="stylesheet" href="/static/app.css"><style>.doc { max-width: 820px; margin: 0 auto; padding: 24px 24px 64px; }13 unmodified lines</head><body><header class="bar"><div class="brand"><a href="/" style="text-decoration:none">Scott Wu Math</a></div><nav><a href="/">Play</a><a href="/static/card.html" aria-current="page">Environment card</a><a href="/docs">API</a></nav></header><article class="doc" id="doc">Loading…</article>
2 unmodified lines3456789101112131415162 unmodified lines<head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>Card Arithmetic</title><meta name="description" content="Make the target from playing cards with + − × ÷, every card once. An OpenEnv environment people and language models play the same way."><link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Crect x='5' y='2' width='22' height='28' rx='3' fill='%23fff' stroke='%23222' stroke-width='2'/%3E%3Ctext x='16' y='22' font-size='14' text-anchor='middle' fill='%23c0392b'%3E%E2%99%A5%3C/text%3E%3C/svg%3E"><link rel="stylesheet" href="/static/app.css"></head><body><header class="bar"><div class="brand">Card Arithmetic</div><nav><a href="#rules" id="rules-link">Rules</a><a href="/static/card.html">Environment card</a>2 unmodified lines3456789101112131415162 unmodified lines<head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>Scott Wu Math</title><meta name="description" content="Make the target from playing cards with + − × ÷, every card once. An OpenEnv environment people and language models play the same way."><link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Crect x='5' y='2' width='22' height='28' rx='3' fill='%23fff' stroke='%23222' stroke-width='2'/%3E%3Ctext x='16' y='22' font-size='14' text-anchor='middle' fill='%23c0392b'%3E%E2%99%A5%3C/text%3E%3C/svg%3E"><link rel="stylesheet" href="/static/app.css"></head><body><header class="bar"><div class="brand">Scott Wu Math</div><nav><a href="#rules" id="rules-link">Rules</a><a href="/static/card.html">Environment card</a>
Dockerfile+5-5
README.md+47-10
__init__.py+3-3
client.py+4-4
models.py+1-1
openenv.yaml+2-2
pyproject.toml+6-6
scripts/build_tasks.py+4-4
server/app.py+4-4
server/environment.py+2-2
server/web/app.css+3-1
server/web/app.js+1-1
server/web/card.html+2-2
server/web/index.html+2-2