A gentle introduction to the Elf Calculator: instructions, registers, shorter programs and the submission file.
Every December, Kaggle runs a Santa-themed optimisation competition. The 2026 edition, the Elf Calculator, is a puzzle in arithmetic program synthesis: given some starting numbers, write the shortest possible program of additions, subtractions, multiplications and divisions that produces a list of target numbers. The idea fits on one line, yet finding truly short programs turns into a rich search and optimisation problem.
This article starts from the simplest possible programs, 1 + 1 and 1 + 1 + 1, explains the machine the programs run on, builds up the main tricks for shortening programs one level at a time, and finishes with a complete worked example of the CSV file that gets submitted to Kaggle.
| Item | Detail |
|---|---|
| Goal | For each puzzle, write a program that produces every target value at least once |
| Operations | + - * / on whole numbers |
| Puzzles | 1,000 scored puzzles, plus a set of practice puzzles |
| Data files | puzzles.csv, practice_puzzles.csv, sample_submission.csv |
| Score | Total number of instructions across all 1,000 programs (lower is better) |
| Submission | A CSV with columns id,program, one row per puzzle |
Because the score is a plain sum, every instruction saved on any puzzle improves the score by exactly one. A competitor who trims one instruction from each of the 1,000 puzzles gains 1,000 points.
The programs run on a tiny abstract machine. It has two parts: a bank of registers that hold numbers, and a list of instructions that combine them.
A register is a numbered storage slot. Each puzzle supplies a register count, which is 48 for the competition data, so the registers are r0 to r47. The starting values are loaded into registers before the program runs, and every other register starts empty. Here is the register file at the start of a puzzle whose only start value is 1:
Every instruction is a list of four items: [op, source_i, source_j, destination]. The operator is one of the four arithmetic signs and the other three items are register numbers, not values. The instruction reads the two source registers, applies the operator and writes the result into the destination register.
Each instruction takes exactly two inputs, so it is a lot like a single line of assembly code. The same register may appear in both source positions, which is how a value is doubled (['+', 1, 1, 2]) or squared (['*', 1, 1, 2]).
- Read before write. Both sources are read before the destination is overwritten, so
['+', 0, 0, 0]safely doubles r0 in place. - No empty reads. A register can only be used as a source once it holds a value.
- Positive integers only. Every result must be a whole number greater than zero and no larger than the puzzle’s
value_limit. Subtraction must not go to zero or below. - Exact division. Division is only allowed when it leaves no remainder.
- Targets appear once. A target only has to show up in some register at some point; it may be overwritten later.
- Size limits. At most 4,096 instructions and 128 KiB of text per program.
The trace below follows the five-instruction program for the target 100 (Level 7 in the next section). Bold marks the register written at each step; a dot marks an empty register.
| Step | Instruction | r0 | r1 | r2 | r3 | r4 | r5 |
|---|---|---|---|---|---|---|---|
| start | 1 | · | · | · | · | · | |
| 1 | ['+', 0, 0, 1] | 1 | 2 | · | · | · | · |
| 2 | ['+', 1, 0, 2] | 1 | 2 | 3 | · | · | · |
| 3 | ['+', 1, 2, 3] | 1 | 2 | 3 | 5 | · | · |
| 4 | ['*', 3, 1, 4] | 1 | 2 | 3 | 5 | 10 | · |
| 5 | ['*', 4, 4, 5] | 1 | 2 | 3 | 5 | 10 | 100 |
Each level below shows the puzzle, the obvious program, a shorter one and the trick that makes the difference. Programs appear twice: in a readable form with values filled in, and in the official four-item form that goes into the submission file. Every program here has been run through a checker, and a brute-force search confirms that each shortened program is the shortest possible.
Start: [1] Targets: [2]
The smallest possible puzzle. Register r0 holds the start value 1 and the target is 2. One instruction adds r0 to itself and writes the answer into the empty register r1.
1 instruction Trick: One instruction, two inputs, one output.
r1 = r0 + r0 → 1 + 1 = 2['+', 0, 0, 1]Start: [1] Targets: [3]
On paper 1 + 1 + 1 looks like one expression, but every instruction takes exactly two inputs. The expression therefore costs two instructions: first 1 + 1, then that result + 1.
2 instructions Trick: An expression with k operands costs k − 1 instructions.
r1 = r0 + r0 → 1 + 1 = 2
r2 = r1 + r0 → 2 + 1 = 3['+', 0, 0, 1]
['+', 1, 0, 2]Start: [1] Targets: [4]
Writing 4 as 1 + 1 + 1 + 1 costs three instructions. Adding the 2 to itself costs two.
Naive: 1 + 1 + 1 + 1 = 3 instructions. Shortened: 2. Trick: Doubling: add a register to itself.
r1 = r0 + r0 → 1 + 1 = 2
r2 = r1 + r1 → 2 + 2 = 4['+', 0, 0, 1]
['+', 1, 1, 2]Start: [1] Targets: [8]
Adding 1 seven times costs seven instructions. Doubling three times (2, 4, 8) costs three.
Naive: 1 + 1 + … + 1 (eight ones) = 7 instructions. Shortened: 3. Trick: Repeated doubling reaches 2k in k steps.
r1 = r0 + r0 → 1 + 1 = 2
r2 = r1 + r1 → 2 + 2 = 4
r3 = r2 + r2 → 4 + 4 = 8['+', 0, 0, 1]
['+', 1, 1, 2]
['+', 2, 2, 3]Start: [1] Targets: [16]
Doubling needs four steps (2, 4, 8, 16). Multiplying 4 by itself skips a step.
Naive: 2, 4, 8, 16 by doubling = 4 instructions. Shortened: 3. Trick: Squaring: multiply a register by itself.
r1 = r0 + r0 → 1 + 1 = 2
r2 = r1 + r1 → 2 + 2 = 4
r3 = r2 × r2 → 4 × 4 = 16['+', 0, 0, 1]
['+', 1, 1, 2]
['*', 2, 2, 3]Start: [1] Targets: [4, 5]
With two targets, building each one from scratch costs 2 + 3 = 5 instructions. Once 4 exists, 5 is just 4 + 1.
Naive: 4 from scratch, then 5 from scratch = 5 instructions. Shortened: 3. Trick: Reuse: build the next target from an earlier one.
r1 = r0 + r0 → 1 + 1 = 2
r2 = r1 + r1 → 2 + 2 = 4
r3 = r2 + r0 → 4 + 1 = 5['+', 0, 0, 1]
['+', 1, 1, 2]
['+', 2, 0, 3]Start: [1] Targets: [100]
The binary method doubles six times to reach 64, then adds 32 and 4: eight instructions. Factoring 100 = 10 × 10 and 10 = 5 × 2 needs only five.
Naive: 1 → 2 → 4 → … → 64, then 64 + 32 + 4 = 8 instructions. Shortened: 5. Trick: Factoring: multiply small factors.
r1 = r0 + r0 → 1 + 1 = 2
r2 = r1 + r0 → 2 + 1 = 3
r3 = r1 + r2 → 2 + 3 = 5
r4 = r3 × r1 → 5 × 2 = 10
r5 = r4 × r4 → 10 × 10 = 100['+', 0, 0, 1]
['+', 1, 0, 2]
['+', 1, 2, 3]
['*', 3, 1, 4]
['*', 4, 4, 5]Start: [3] Targets: [30]
Doubling gives 6, 12, 24, then 24 + 6 = 30 in four instructions. Going past the target to 36 = 6 × 6 and subtracting 6 needs three.
Naive: 6, 12, 24, then 24 + 6 = 4 instructions. Shortened: 3. Trick: Overshoot and subtract.
r1 = r0 + r0 → 3 + 3 = 6
r2 = r1 × r1 → 6 × 6 = 36
r3 = r2 − r1 → 36 − 6 = 30['+', 0, 0, 1]
['*', 1, 1, 2]
['-', 2, 1, 3]Start: [2] Targets: [16, 17, 34]
Built separately, 16 costs 2 instructions, 17 costs 4 and 34 costs 4: ten in total. Dividing 2 by itself gives a 1 to work with, and each target then grows from the previous one: 16, then 16 + 1 = 17, then 17 + 17 = 34.
Naive: each target built from scratch = 10 instructions. Shortened: 5. Trick: Anchor reuse, plus division to make a 1.
r1 = r0 × r0 → 2 × 2 = 4
r2 = r0 ÷ r0 → 2 ÷ 2 = 1
r3 = r1 × r1 → 4 × 4 = 16
r4 = r3 + r2 → 16 + 1 = 17
r5 = r4 + r4 → 17 + 17 = 34['*', 0, 0, 1]
['/', 0, 0, 2]
['*', 1, 1, 3]
['+', 3, 2, 4]
['+', 4, 4, 5]| Trick | Idea | Example |
|---|---|---|
| Reuse | Build the next value from one already in a register | 4 then 4 + 1 = 5 |
| Doubling | Add a register to itself | 2, 4, 8 |
| Squaring | Multiply a register by itself | 4 × 4 = 16 |
| Factoring | Write the target as a product of small factors | 100 = (2 + 3) × 2 squared |
| Overshoot and subtract | Jump past the target with a big step, then step back | 36 − 6 = 30 |
| Anchor reuse | Grow each target from the previous target | 16 → 17 → 34 |
| Make a 1 | Divide a register by itself for a free small constant | 2 ÷ 2 = 1 |
A submission is a single CSV file with one row per puzzle. Kaggle runs every program, rejects the file if any program breaks a rule, and otherwise reports the total instruction count.
For a complete example, suppose the puzzle file contained just three puzzles, taken from Levels 7, 8 and 9:
| id | Start values | Targets | Best program |
|---|---|---|---|
| 0 | [1] | [100] | 5 instructions |
| 1 | [3] | [30] | 3 instructions |
| 2 | [2] | [16, 17, 34] | 5 instructions |
Each program becomes a list of four-item instructions:
id 0: [["+", 0, 0, 1], ["+", 1, 0, 2], ["+", 1, 2, 3], ["*", 3, 1, 4], ["*", 4, 4, 5]]
id 1: [["+", 0, 0, 1], ["*", 1, 1, 2], ["-", 2, 1, 3]]
id 2: [["*", 0, 0, 1], ["/", 0, 0, 2], ["*", 1, 1, 3], ["+", 3, 2, 4], ["+", 4, 4, 5]]This is the complete submission.csv for the three puzzles, exactly as it sits on disk:
id,program
0,"[[""+"",0,0,1],[""+"",1,0,2],[""+"",1,2,3],[""*"",3,1,4],[""*"",4,4,5]]"
1,"[[""+"",0,0,1],[""*"",1,1,2],[""-"",2,1,3]]"
2,"[[""*"",0,0,1],[""/"",0,0,2],[""*"",1,1,3],[""+"",3,2,4],[""+"",4,4,5]]"Two details stand out. The program cell contains commas, so the CSV writer wraps it in double quotes, and the quotes inside the cell are escaped by doubling them, so "+" becomes ""+"". Writing the file with Python’s csv module takes care of both automatically.
This tiny file scores 5 + 3 + 5 = 13. A real submission has 1,000 rows; a published baseline file is about 21 MB.
import csv, json
programs = {
0: [["+",0,0,1], ["+",1,0,2], ["+",1,2,3], ["*",3,1,4], ["*",4,4,5]], # 100 from {1}
1: [["+",0,0,1], ["*",1,1,2], ["-",2,1,3]], # 30 from {3}
2: [["*",0,0,1], ["/",0,0,2], ["*",1,1,3], ["+",3,2,4], ["+",4,4,5]], # 16, 17, 34 from {2}
}
with open("submission.csv", "w", newline="") as f:
w = csv.writer(f) # handles the quoting for you
w.writerow(["id", "program"])
for pid, prog in sorted(programs.items()):
cell = json.dumps(prog, separators=(",", ":"))
assert len(prog) <= 4096 and len(cell.encode()) <= 128 * 1024
w.writerow([pid, cell])One invalid program typically fails the whole submission, so it pays to run every program through a local checker that applies the rules from Section 2:
def check(start, targets, prog, value_limit, n_regs=48):
reg = [None] * n_regs
reg[:len(start)] = start # assumption: start values fill r0, r1, ...
seen = set(start)
for op, i, j, d in prog:
a, b = reg[i], reg[j] # read both sources first
if a is None or b is None:
raise ValueError("read from an empty register")
if op == "+": v = a + b
elif op == "-": v = a - b
elif op == "*": v = a * b
elif op == "/":
if a % b: raise ValueError("inexact division")
v = a // b
if not 0 < v <= value_limit:
raise ValueError(f"value {v} out of range")
reg[d] = v # then write the destination
seen.add(v)
missing = set(targets) - seen
if missing:
raise ValueError(f"targets never produced: {missing}")
return len(prog) # this puzzle's contribution to the scoreThe file can be uploaded on the competition page under Submit Prediction, submitted from a Kaggle notebook by writing it to /kaggle/working/, or sent with the Kaggle command-line tool:
pip install kaggle # API token goes in ~/.kaggle/kaggle.json
kaggle competitions download -c santa-2026
kaggle competitions submit -c santa-2026 -f submission.csv -m "factoring + anchor reuse"
kaggle competitions submissions -c santa-2026sample_submission.csv and the Data page before submitting.Hand-crafting 1,000 programs is not practical, so competitors write solvers. A typical progression:
- Binary baseline. Make a 1, double repeatedly and add the needed powers of two. Always valid, rarely short, and a useful safety net for every puzzle.
- Factoring and overshoot. Try products of small numbers and nearby larger values that can be stepped back from, keeping whichever is shortest.
- Anchor reuse. Sort the targets and build each one from values already in registers, so a long target list costs little more than its first element.
- Exact search on small cases. Iterative deepening proves the true minimum for short programs and catches clever constructions the heuristics miss.
- Register allocation. With only 48 registers, decide which values to keep and which to overwrite, much like a compiler back end.
The brute-force search used to verify the levels in this article is only a few lines long:
from itertools import combinations_with_replacement as cwr
def shortest(start, targets, limit=10**6, maxdepth=6):
"""Iterative deepening: the fewest instructions that produce every target."""
targets = set(targets)
def ops(a, b):
yield a + b; yield a * b; yield abs(a - b)
if a % b == 0: yield a // b
if b % a == 0: yield b // a
def dfs(vals, d):
if targets <= vals: return 0
if d == 0: return None
for a, b in cwr(sorted(vals), 2):
for v in ops(a, b):
if 0 < v <= limit and v not in vals:
r = dfs(vals | {v}, d - 1)
if r is not None: return r + 1
return None
for d in range(maxdepth + 1):
if dfs(frozenset(start), d) is not None:
return d
print(shortest({1}, [100]), shortest({3}, [30]), shortest({2}, [16, 17, 34])) # 5 3 5It explodes quickly beyond six or seven instructions, which is exactly why the real competition rewards smarter search: beam search, dynamic programming over addition chains, and caching of good sub-programs.
- Kaggle, Santa 2026 competition, Overview, Data and Evaluation pages
- Joe-You-Know/PRTA-Elf-Calculator: instruction form and register count
- chaitanyabfal-ai/elfcalculator: limits, submission columns and baseline size
- robsartin/elf-abacus: verifier rules and anchor reuse
Kaggle Santa 2026 · Python 3.10+
✦ This article was generated with the assistance of Claude by Anthropic ✦
Share this:
- Share on Facebook (Opens in new window) Facebook
- Email a link to a friend (Opens in new window) Email
- Share on LinkedIn (Opens in new window) LinkedIn
- Share on Telegram (Opens in new window) Telegram
- Share on WhatsApp (Opens in new window) WhatsApp
- More
- Share on Bluesky (Opens in new window) Bluesky
- Print (Opens in new window) Print
- Share on Threads (Opens in new window) Threads
- Share on Reddit (Opens in new window) Reddit
- Share on Tumblr (Opens in new window) Tumblr
- Share on Pinterest (Opens in new window) Pinterest
- Share on X (Opens in new window) X
Leave a Reply