Skip to content

Instantly share code, notes, and snippets.

@youqad
Last active March 5, 2026 23:37
Show Gist options
  • Select an option

  • Save youqad/d120c2231647e999dbe005a7757f2b27 to your computer and use it in GitHub Desktop.

Select an option

Save youqad/d120c2231647e999dbe005a7757f2b27 to your computer and use it in GitHub Desktop.
Bit-reversal tree challenge: GPT-5.2 Pro one-shot results (static artifacts only)
{
"taelin_typescript": {
"passed": true,
"elapsed_seconds": 315.0,
"tokens": {
"input": 401,
"output": 4460
},
"model": "gpt-5.2-pro",
"response_model": "gpt-5.2-pro-2025-12-11",
"response_id": "resp_0d5b5a25dd96b7200069aa07225904819d98846481fe63cba8",
"response_created_at": 1772750626.0,
"request_id": "req_ecadd8a246c841fd80420ae22d43adeb",
"verification": "[[[[0,8],[4,12]],[[2,10],[6,14]]],[[[1,9],[5,13]],[[3,11],[7,15]]]]\nTest1: true\nTest2: true\nTest3: true\nTest4: true\nTest5: true\nALL TESTS PASSED"
},
"python_with_helper": {
"passed": true,
"elapsed_seconds": 251.3,
"tokens": {
"input": 994,
"output": 4886
},
"model": "gpt-5.2-pro",
"response_model": "gpt-5.2-pro-2025-12-11",
"response_id": "resp_065b65c99a4617ca0069aa085d4dc88190820b4c3fdc1d35ad",
"response_created_at": 1772750941.0,
"request_id": "req_ac6602e67c3d45118502252f7c12f4f5",
"verification": "All Hypothesis property-based tests passed"
},
"python_no_helper": {
"passed": true,
"elapsed_seconds": 382.5,
"tokens": {
"input": 952,
"output": 10359
},
"model": "gpt-5.2-pro",
"response_model": "gpt-5.2-pro-2025-12-11",
"response_id": "resp_0ca0d10b694eee920069aa0958b9d8819fb7cd90e17c81afca",
"response_created_at": 1772751192.0,
"request_id": "req_4a3e1fce3f234835bdb2de389347d0b1",
"verification": "All Hypothesis property-based tests passed"
},
"haskell_with_helper": {
"passed": true,
"elapsed_seconds": 354.4,
"tokens": {
"input": 1000,
"output": 14197
},
"model": "gpt-5.2-pro",
"response_model": "gpt-5.2-pro-2025-12-11",
"response_id": "resp_05409fa25762e9f80069aa0ad7436881a3ba1a568a837e8cf8",
"response_created_at": 1772751575.0,
"request_id": "req_5fca37c278bd402d86eb55cca954b458",
"verification": "Test1 (depth=3, sequential): True\nTest2 (depth=3, shuffled): True\nTest3 (depth=4, shuffled): True\nTest4 (depth=2, sequential): True\nTest5 (depth=1, sequential): True\nALL TESTS PASSED"
},
"haskell_no_helper": {
"passed": true,
"elapsed_seconds": 222.9,
"tokens": {
"input": 984,
"output": 4604
},
"model": "gpt-5.2-pro",
"response_model": "gpt-5.2-pro-2025-12-11",
"response_id": "resp_0e2cf106732f9e4c0069aa0c3a57b881929c20b313c4d007c0",
"response_created_at": 1772751930.0,
"request_id": "req_80159f6dc28048648801d391bced36fa",
"verification": "Test1 (depth=3, sequential): True\nTest2 (depth=3, shuffled): True\nTest3 (depth=4, shuffled): True\nTest4 (depth=2, sequential): True\nTest5 (depth=1, sequential): True\nALL TESTS PASSED"
}
}

Bit-Reversal Tree Challenge: All 5 Prompts Solved One-Shot by GPT-5.2 Pro

Date: 2026-03-05
Model: gpt-5.2-pro (via OpenAI Responses API)
Provider-returned model: gpt-5.2-pro-2025-12-11
Settings: temperature=1, one-shot, no feedback rounds
Repository: https://github.com/youqad/bit-reversal-trees

Summary

# Prompt Language Helper? Result Time Output tokens
1 Victor's approved prompt TypeScript Bit param PASS 315.0s 4460
2 My with-helper prompt Python bool flag PASS 251.3s 4886
3 My no-helper prompt (HARDER) Python NONE PASS 382.5s 10359
4 My with-helper prompt Haskell Bool param PASS 354.4s 14197
5 My "no-helper" variant Haskell optional PASS 222.9s 4604

All 5 prompts produce correct solutions, verified via automated testing.

Provenance

The important new thing in this bundle is that gpt5.2-pro_all_prompts_results.json now includes, for each of the five calls:

  • response_model
  • response_id
  • response_created_at
  • request_id

These come from the API response / request layer itself (that is, they are not just local labels I typed by hand), and they do not expose the API key.

All five calls in this run report the same provider-returned model snapshot:

  • gpt-5.2-pro-2025-12-11

Verification methods

  • Python prompts (#2, #3): Hypothesis property-based testing with randomized perfect binary trees up to depth 4.
  • Haskell prompts (#4, #5): runhaskell with 5 test cases at depths 1-4, comparing against a reference bit-reversal permutation implementation.
  • TypeScript prompt (#1): node execution with the same 5 test cases and reference implementation.

Why the Python no-helper prompt is harder than Victor's

Victor's approved TypeScript prompt provides the type signature function invert<A>(bit: Bit, tree: Tree<A>): Tree<A>, which gives the AI:

  • The knowledge that a boolean / bit parameter exists
  • The hint that the function takes (Bit, Tree) -> Tree

My Python no-helper prompt (python_prompt_no_helper.md) says:

"It must NOT rely on any helper function or inner function, it must be a self-contained single recursive function invert(tree: Tree) -> Tree."

There is no extra bit of state, that is harder than Victor's prompt.

For the Haskell "no-helper" variant, the situation is slightly different: the prompt still allows one possible exception, namely a single helper inner function of type Bool -> Tree a -> Tree a if needed. So that Haskell variant should be described as a stricter follow-up prompt in spirit, but not as a literal no-helper prompt in the same strong sense as the Python one.

Raw outputs

The exact saved model outputs for this run are published alongside this report:

  • gpt5.2-pro_taelin_typescript_response.txt
  • gpt5.2-pro_python_with_helper_response.txt
  • gpt5.2-pro_python_no_helper_response.txt
  • gpt5.2-pro_haskell_with_helper_response.txt
  • gpt5.2-pro_haskell_no_helper_response.txt

Reproducibility

All prompts are in the public repo: https://github.com/youqad/bit-reversal-trees

```haskell
invert :: Tree a -> Tree a
invert (Leaf x) = Leaf x
invert t@(Node _ _) = Node (invert (pick False t)) (invert (pick True t))
where
-- pick b t = subtree consisting of exactly the leaves whose *last* step is b,
-- with that last step dropped (so the depth decreases by 1).
pick :: Bool -> Tree a -> Tree a
pick _ (Leaf x) = Leaf x -- not expected for perfect trees, but keeps the function total
pick b (Node l r) =
case (l, r) of
(Leaf x, Leaf y) -> if b then Leaf y else Leaf x
_ -> Node (pick b l) (pick b r)
```
(If you want the provided `main` to compile, make sure `Tree` derives `Show`, e.g. `data Tree a = ... deriving (Show, Eq)`.)
```haskell
-- Type `Tree` of perfect binary trees
data Tree a = Leaf a | Node (Tree a) (Tree a)
deriving (Show, Eq)
-- Implement the `invert` function as follows:
invert :: Tree a -> Tree a
invert tree = invertHelper True tree
where
-- invertHelper True = bit-reversal
-- invertHelper False = perfect interleave of the two subtrees packed into a Node
invertHelper :: Bool -> Tree a -> Tree a
invertHelper _ (Leaf x) = Leaf x
-- Bit-reversal step: invert both halves, then interleave them
invertHelper True (Node l r) =
invertHelper False (Node (invertHelper True l) (invertHelper True r))
-- Interleave step:
-- interleave (Leaf a) (Leaf b) = Node (Leaf a) (Leaf b)
-- interleave (Node a b) (Node c d) = Node (interleave a c) (interleave b d)
invertHelper False (Node l r) =
case (l, r) of
(Leaf a, Leaf b) -> Node (Leaf a) (Leaf b)
(Node l0 l1, Node r0 r1) ->
Node (invertHelper False (Node l0 r0))
(invertHelper False (Node l1 r1))
```
This satisfies `invertHelper True tree ==` the bit-reversed tree, uses only recursion, and keeps `invert` pure and standalone (only calling `invertHelper`).
```python
def invert(tree: Tree) -> Tree:
# Special "split wrapper" mode: Node(Leaf(None), t) returns Node(E, O),
# where E contains leaves at even indices and O at odd indices (by LSB).
if isinstance(tree, Node) and isinstance(tree.left, Leaf) and tree.left.value is None:
t = tree.right
# Not expected for perfect trees in normal use, but kept total.
if isinstance(t, Leaf):
return Node(Leaf(t.value), Leaf(t.value))
# Bottom level: Node(Leaf(a), Leaf(b)) -> (Leaf(a), Leaf(b))
if isinstance(t.left, Leaf) and isinstance(t.right, Leaf):
return Node(Leaf(t.left.value), Leaf(t.right.value))
# Recurse and combine:
lp = invert(Node(Leaf(None), t.left)) # -> Node(E_left, O_left)
rp = invert(Node(Leaf(None), t.right)) # -> Node(E_right, O_right)
return Node(Node(lp.left, rp.left), Node(lp.right, rp.right))
# Normal bit-reversal mode.
if isinstance(tree, Leaf):
return Leaf(tree.value)
pair = invert(Node(Leaf(None), tree)) # pair = Node(E, O)
return Node(invert(pair.left), invert(pair.right))
```
```python
def invert(tree: Tree) -> Tree:
def invert_helper(tree: Tree, flag: bool) -> Tree:
# flag == True : compute bit-reversal permutation
# flag == False : "zip" two same-height trees given as Node(a, b)
if flag:
if isinstance(tree, Leaf):
return Leaf(tree.value)
# bitrev(Node(L, R)) = zip(bitrev(L), bitrev(R))
l2 = invert_helper(tree.left, True)
r2 = invert_helper(tree.right, True)
return invert_helper(Node(l2, r2), False)
# flag == False: zip(a, b), encoded as tree == Node(a, b)
a, b = tree.left, tree.right
if isinstance(a, Leaf) and isinstance(b, Leaf):
return Node(Leaf(a.value), Leaf(b.value))
if isinstance(a, Node) and isinstance(b, Node):
return Node(
invert_helper(Node(a.left, b.left), False),
invert_helper(Node(a.right, b.right), False),
)
raise TypeError("invert_helper: mismatched tree shapes (expected perfect binary trees)")
return invert_helper(tree, True)
```
```ts
type Nat = number;
type Bit = false | true;
type Tree<A> = [Tree<A>, Tree<A>] | Nat;
// bit=true => full bit-reversal
// bit=false => one "LSB split" step (evens on the left, odds on the right)
function invert<A>(bit: Bit, tree: Tree<A>): Tree<A> {
if (Array.isArray(tree)) {
const [l, r] = tree;
if (bit) {
const grouped = invert(false, tree);
if (Array.isArray(grouped)) {
const [even, odd] = grouped;
return [invert(true, even), invert(true, odd)];
} else {
return grouped;
}
} else {
if (Array.isArray(l)) {
const left = invert(false, l);
const right = invert(false, r);
if (Array.isArray(left)) {
const [le, lo] = left;
if (Array.isArray(right)) {
const [re, ro] = right;
return [[le, re], [lo, ro]];
}
}
// Fallback for non-perfect trees (shouldn't happen for valid inputs)
return tree;
} else {
// depth-1 base: [x,y] already splits into evens=[x], odds=[y]
return [l, r];
}
}
} else {
return tree;
}
}
// A test:
const tree: Tree<Nat> =
[[[[0,1],[2,3]],[[4,5],[6,7]]],[[[8,9],[10,11]],[[12,13],[14,15]]]];
console.log(JSON.stringify(invert(true, tree)));
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment