an esoteric programming language
Every Puzzle program is the same two characters, repeated: f and a run of backticks. What the program does depends entirely on how many backticks there are — and on whether you can write a function that figures that out.
The whole language is a trick of JavaScript grammar. A tagged template like f`hi` is just
f called with a strings array. Chain more backticks on and each result gets called again as the
next tag — f`````` calls f, then calls whatever it returned, then
calls whatever that returned. A Puzzle program is nothing but that chain, stretched out to a specific length.
Count every backtick in the program and divide by two. That gives a single non‑negative integer, N — the
number of tag calls in the chain, including the very first call to f itself.
N is not just a length. Treat N itself as a base‑256 number and expand it back into its bytes, most significant byte first. Those bytes, read as UTF‑8, are the source code of a tinylisp program.
Execute the decoded text as tinylisp. tinylisp is the host language for Puzzle — the same interpreter backs
this page's runTinylisp and runFromChainLength helpers below,
so you don't need to write a Lisp from scratch to solve this.
What you do need to write is f.
Nothing above is hidden — this is the entire specification. The difficulty is not in the rules, it's in
implementing f so that the chain behaves correctly. Figuring out how
f can know it has seen the last call is the puzzle. There's no hint for it here.
Write a short tinylisp program and turn it into a Puzzle program. Because N grows exponentially with byte length (roughly 256 per extra byte), only very short programs are practical to actually run — that's a property of the language, not a bug in this page.
Primitives available: quote atom eq car
cdr cons cond if lambda label
define, arithmetic + - * / mod < > =, and print.
Leading NUL bytes in your source will not survive encoding — N can't represent them.
Implement f below. It will be invoked exactly the way a real Puzzle
program invokes it: as the head of a tagged‑template chain, 2N backticks long, N calls
total. Two helpers are available inside your code:
runTinylisp(sourceString) — parses and runs tinylisp source text directly.runFromChainLength(n) — given a chain length (a Number or BigInt), decodes it
back into bytes and runs the result as tinylisp for you.The stub below is deliberately empty. There is no scaffolding for counting calls or detecting the end of the chain — that's the part to design.
Runs the most recently encoded Puzzle program against your current f,
by literally constructing f followed by that many backticks and evaluating it — the
real JavaScript grammar, not a simulation of it.