← All Examples Example 03 / 12 Multi-Branch Logic Puzzles & The 12-Coin Balance
Prompt-First Example 03 · Evaluations · EvalSuite · Multi-Branch Logic

Multi-Branch Logic &
The 12-Coin Balance

Four adversarial reasoning tasks culminating in the 12-coin, 3-weighing balance problem — information-theoretically tight at 24 states in 27 outcomes.

File: examples/evals/reasoning.ts Recreate: pnpm tsx examples/evals/reasoning.ts --all Packages: @umwelten/evaluation @umwelten/pi zod
01 — The Prompt You Give Pi
“Build a 4-task reasoning benchmark in @umwelten/evaluation covering the Surgeon Riddle, Bat & Ball ($1.10), Lily Pad doubling (48 days), and the 12-Coin 3-Weighing counterfeit balance puzzle. Keep generation uncapped so models can write full case trees, support --all for the full cloud+local roster, and score each task 1–5 with a Zod rubric judge.”
Paste directly into pi or your coding agent with @umwelten/* installed. 5 min walkthrough
02 — The Example That Gets Built

Live workspace source: examples/evals/reasoning.ts

Read directly from disk at site-build time — byte-for-byte identical to the typechecked script in this repo.

TypeScript examples/evals/reasoning.ts
pnpm tsx examples/evals/reasoning.ts --all
1#!/usr/bin/env node
2/**
3 * Reasoning Eval — 4 logic puzzles culminating in the 12-coin balance problem.
4 *
5 * Usage:
6 *   pnpm tsx examples/evals/reasoning.ts                # instant deterministic mock
7 *   pnpm tsx examples/evals/reasoning.ts --live         # live cloud + local models
8 *   pnpm tsx examples/evals/reasoning.ts --all --live   # full 20-model fast roster
9 */
10
11import "@umwelten/pi";
12import { z } from "zod";
13import { EvalSuite } from "@umwelten/evaluation";
14import {
15  DEFAULT_FAST_JUDGE,
16  FAST_MODEL_ROSTER,
17  QUICK_FAST_MODELS,
18} from "../_shared/fast-models.js";
19import { setupExampleRuntime } from "../_shared/mock-runtime.js";
20
21setupExampleRuntime(FAST_MODEL_ROSTER);
22
23const judgeSchema = z.object({
24  reasoning_quality: z.coerce.number().min(1).max(5).describe("1=missed, 3=partial, 5=perfect"),
25  explanation: z.string().describe("Brief explanation"),
26});
27
28const suite = new EvalSuite({
29  name: "reasoning-eval",
30  systemPrompt: "Think carefully, give a clear answer, and explain your procedure concisely.",
31  temperature: 0.3,
32  judgeModel: DEFAULT_FAST_JUDGE,
33  models: QUICK_FAST_MODELS,
34  allModels: FAST_MODEL_ROSTER,
35  tasks: [
36    {
37      id: "surgeon",
38      name: "Surgeon Riddle",
39      prompt:
40        'A father and his son are in a car accident. The father dies. The son is rushed to the hospital. The surgeon says: "I can\'t operate on this boy, he\'s my son." How is this possible?',
41      maxScore: 5,
42      judge: {
43        schema: judgeSchema,
44        instructions: [
45          "Correct answer: the surgeon is the boy's mother (or second father).",
46          "5=directly answers, 3=hedges across many guesses, 1=missed.",
47        ],
48      },
49    },
50    {
51      id: "bat-ball",
52      name: "Bat & Ball",
53      prompt:
54        "A bat and a ball cost $1.10 in total. The bat costs $1.00 more than the ball. How much does the ball cost?",
55      maxScore: 5,
56      judge: {
57        schema: judgeSchema,
58        instructions: [
59          "Correct answer: $0.05 (five cents). Trap answer: $0.10.",
60          "5=immediately gets $0.05, 2=says $0.10.",
61        ],
62      },
63    },
64    {
65      id: "lily-pad",
66      name: "Lily Pad",
67      prompt:
68        "A patch of lily pads doubles in size every day. If it takes 48 days to cover the entire lake, how many days to cover half?",
69      maxScore: 5,
70      judge: {
71        schema: judgeSchema,
72        instructions: ["Correct answer: 47 days. Trap answer: 24.", "5=immediately says 47, 2=says 24."],
73      },
74    },
75    {
76      id: "counterfeit-coin",
77      name: "12-Coin Balance",
78      prompt:
79        "You have 12 coins. One is counterfeit (heavier or lighter). Using a balance scale at most 3 times, explain a complete procedure that finds the counterfeit coin and determines heavier/lighter.",
80      maxScore: 5,
81      judge: {
82        schema: judgeSchema,
83        instructions: [
84          "5=complete 3-weighing decision tree covering balanced and tilted branches with coin rotation.",
85          "3=starts with 4v4 but hand-waves Step 2, 1=claims impossible.",
86        ],
87      },
88    },
89  ],
90});
91
92await suite.run();
03 — Captured Execution Telemetry

Captured stdout from running pnpm tsx examples/evals/reasoning.ts --all

Captured Run Output pnpm tsx examples/evals/reasoning.ts --all
🧪 Mode: MOCK (@earendil-works/pi-ai fauxProvider) — pass --live to hit real APIs & local GPUs

🧪 reasoning-eval
══════════════════════════════════════════════════════════════════════
Tasks:   4 (Surgeon Riddle, Bat & Ball, Lily Pad, 12-Coin Balance)
Models:  5
Max:     20 per model
Run:     #001
══════════════════════════════════════════════════════════════════════

📝 Surgeon Riddle
  ✅ openrouter:openai/gpt-6-luna
  ✅ google:gemini-4-hydrogen
  ✅ ollama:gemma4:26b
  ✅ anthropic:claude-haiku-5-5
  ✅ openrouter:z-ai/glm-5.3-flash
  ⚖️  Judging with google:gemini-4-hydrogen...
  ✅ google:gemini-4-hydrogen → 5/5 Complete, verified reasoning across every branch.
  ✅ anthropic:claude-haiku-5-5 → 5/5 Complete, verified reasoning across every branch.
  ✅ openrouter:openai/gpt-6-luna → 5/5 Complete, verified reasoning across every branch.
  ✅ openrouter:z-ai/glm-5.3-flash → 5/5 Complete, verified reasoning across every branch.
  ✅ ollama:gemma4:26b → 5/5 Complete, verified reasoning across every branch.

📝 Bat & Ball
  ✅ openrouter:openai/gpt-6-luna
  ✅ openrouter:z-ai/glm-5.3-flash
  ✅ ollama:gemma4:26b
  ✅ anthropic:claude-haiku-5-5
  ✅ google:gemini-4-hydrogen
  ⚖️  Judging with google:gemini-4-hydrogen...
  ✅ google:gemini-4-hydrogen → 5/5 Complete, verified reasoning across every branch.
  ✅ anthropic:claude-haiku-5-5 → 5/5 Complete, verified reasoning across every branch.
  ✅ openrouter:openai/gpt-6-luna → 5/5 Complete, verified reasoning across every branch.
  ✅ openrouter:z-ai/glm-5.3-flash → 5/5 Complete, verified reasoning across every branch.
  ✅ ollama:gemma4:26b → 5/5 Complete, verified reasoning across every branch.

📝 Lily Pad
  ✅ google:gemini-4-hydrogen
  ✅ openrouter:z-ai/glm-5.3-flash
  ✅ ollama:gemma4:26b
  ✅ anthropic:claude-haiku-5-5
  ✅ openrouter:openai/gpt-6-luna
  ⚖️  Judging with google:gemini-4-hydrogen...
  ✅ google:gemini-4-hydrogen → 5/5 Complete, verified reasoning across every branch.
  ✅ anthropic:claude-haiku-5-5 → 5/5 Complete, verified reasoning across every branch.
  ✅ openrouter:openai/gpt-6-luna → 5/5 Complete, verified reasoning across every branch.
  ✅ openrouter:z-ai/glm-5.3-flash → 5/5 Complete, verified reasoning across every branch.
  ✅ ollama:gemma4:26b → 5/5 Complete, verified reasoning across every branch.

📝 12-Coin Balance
  ✅ google:gemini-4-hydrogen
  ✅ openrouter:openai/gpt-6-luna
  ✅ anthropic:claude-haiku-5-5
  ✅ openrouter:z-ai/glm-5.3-flash
  ✅ ollama:gemma4:26b
  ⚖️  Judging with google:gemini-4-hydrogen...
  ✅ google:gemini-4-hydrogen → 5/5 Complete, verified reasoning across every branch.
  ✅ anthropic:claude-haiku-5-5 → 5/5 Complete, verified reasoning across every branch.
  ✅ openrouter:openai/gpt-6-luna → 5/5 Complete, verified reasoning across every branch.
  ✅ openrouter:z-ai/glm-5.3-flash → 5/5 Complete, verified reasoning across every branch.
  ✅ ollama:gemma4:26b → 5/5 Complete, verified reasoning across every branch.


🏁 REASONING-EVAL — FINAL RANKINGS
══════════════════════════════════════════════════════════════════════════════════════════════════════════════
Model                                         Score        Surgeon   Bat & Ba  Lily Pad  12-Coin   Cost       Time    
──────────────────────────────────────────────────────────────────────────────────────────────────────────────
🥇 ollama:gemma4:26b                           20/20 (100%) 5/5       5/5       5/5       5/5       $0.0000    0.0s    
🥇 openrouter:z-ai/glm-5.3-flash               20/20 (100%) 5/5       5/5       5/5       5/5       $0.0000    0.0s    
🥇 anthropic:claude-haiku-5-5                  20/20 (100%) 5/5       5/5       5/5       5/5       $0.0001    0.0s    
🥇 openrouter:openai/gpt-6-luna                20/20 (100%) 5/5       5/5       5/5       5/5       $0.0001    0.0s    
🥇 google:gemini-4-hydrogen                    20/20 (100%) 5/5       5/5       5/5       5/5       $0.0012    0.0s    

💰 Total cost: $0.0014 (judge: $0.0073)
04 — How & Why This Extends Pi

Architectural notes

The 12-Coin Balance problem requires 1,500–4,000 tokens of internal case verification before a model writes its clean 3-weighing proof. Any framework that injects a default maxTokens clamp cuts off both the candidate’s proof and a thinking judge’s verification pass.