GPT-6.2 Astra 首次在代码高尔夫上超越谷歌人类纪录

原标题:GPT-6.2 Astra is the first model to beat Googlers' code golf records
62AI 研判分

作者用谷歌内部代码高尔夫周赛的 256 道题构建新基准,所有前沿模型都能给出可运行解,但代码长度得分差距悬殊(47.975% 至 91.934%)。GPT-6.2 Astra 成为首个在代码高尔夫上超越 2015 年谷歌人类纪录的前沿模型,说明该任务能有效衡量模型在已有可用解后继续寻找更优解的能力。

报道正文

本文目录12 个章节

TL;DR: Every model with a complete run can solve these problems. They differ a lot in how short they can make their solutions, even with the same tools and time limit. That's what I want to measure: can a model keep finding better ideas after it has code that already works?

No answers to memorize

These problems come from go/codegolf, a weekly contest that code golf enthusiasts at Google ran for their colleagues. They appear online here for the first time, and the site doesn't show the human solutions. There's no public set of answers for a model to memorize; it has to work out a solution for itself.

Getting a working solution

Frontier models don't have much trouble getting these problems right. Every model with a complete run has an accepted solution in all 256 cells. If I only counted passing solutions, they would all have the same result.

But their scores range from 47.975% to 91.934% across all eight languages, and from 52.911% to 92.265% on JS/PY/C++ (JavaScript, Python and C++ alone). Once a solution works, there's still the question of how much shorter it could be. That's where the models start to differ.

Scoring by byte count

  • Exact. Either the program passes or it doesn't. If it passes, we count its bytes. There's no human rater or LLM judge deciding whether it's good code, and no points for style.
  • Fine-grained. Saving one byte always helps. The squared score makes the difference between a close solution and an even closer one matter.
  • Open-ended. We don't know the shortest possible answers. "Best known" just means nobody has found anything shorter yet. Models have already beaten the 2015 human record in 93 cells. Getting every problem right doesn't end the competition, and a new record gives everyone else something to aim for.

Less boilerplate to golf

In some contests, you spend part of your byte count on getting the input in and the output out. I like go/codegolf's format because it leaves very little of that overhead. I kept the same format for the four added languages:

  • A function, not a program. You define a function; the wrapper handles input and output. Top-level code still runs, so you can use global variables and precomputed tables, or write a recursive solution.
  • A fixed name: g. The name costs one byte, and a recursive call is just g(…). Recursion is often the shortest approach, though getting a very short recursive function right can be difficult.
  • Libraries already imported. The C++, Haskell, Racket and Ruby templates import most of the useful standard libraries. The Python template imports nothing, so using even re costs import re. Sometimes it's still worth it.
  • Nearly every byte is part of the solution. With I/O, naming and most imports taken care of, you're mostly golfing the code that solves the problem, rather than the code needed to run it.

Knowing the language and the runtime

When you're trying to save a byte, details that rarely matter in ordinary code can become useful: operator precedence, implicit conversions, an obscure builtin, a non-standard extension, or what a particular compiler does with undefined behavior. The original languages use old runtimes, including a 2015 C++ toolchain, Python 2.7 and GHC 7.8. Knowing how a modern version behaves isn't enough. The model has to know, or try out, what works in the version it's actually using.

Trying things out

A lot of golfing involves questions you can answer by running a few lines of code:

  1. Will this interpreter accept this syntax? Will the compiler let me leave that out?
  2. Try it in the playground or make a submission.
  3. If it works, see where else you can use it.

Sometimes the experiment needs a program of its own. Golfers write searches for a magic number or magic string that encodes a lookup table, or for the shortest expression that gives the right result using a few operators. A model that never runs these experiments will miss some of the same savings.

Finding a different approach

Often you can't get to the shortest solution by trimming the obvious one. You need a different algorithm, or a different way to represent the data. These are some examples I like from the models' solutions:

  • Carries without carrying. Addition by hand asks how many carries occur when you add two numbers column by column. Each carry turns ten in one column into one in the next, reducing the digit sum by 9. So the answer is (digit sum of a + digit sum of b − digit sum of a+b) ÷ 9, and most models' Python solutions compute exactly that. Gemini 4 Carbon's Python needs neither the subtraction nor the division:
PYTHON
g=lambda a,b:sum(map(int,a+b+52*str(int(a)+int(b))))*6%53

It works modulo 53. Adding the digits of a+b 52 times is the same as subtracting them once, because 52 ≡ −1, and multiplying by 6 is the same as dividing by 9, because 6 × 9 = 54 ≡ 1. There are at most 50 carries, so the remainder is the answer. That's 57 bytes, against 59 for the shortest solution that divides by 9.

  • Comparing rows instead of finding a path. 2×n matrix asks how many blocked cells you have to clear to walk from the top-left to the bottom-right of a two-row grid, given as two strings of 0s and 1s. Most solutions work out the cheapest way to reach each cell, column by column. Claude Opus 5.5's Python walks greedily instead and lets string comparison choose the row:
PYTHON
g=lambda*s:all(s)and(min(s)>='01')+g('0'+min(s)[2:],max(s)[1:])

You always stand on a free cell, so the row you're in starts with 0, and min picks it. If the other row's cell is free too, you could switch rows at no cost, and min picks whichever row's next cell is free. If even that cell is blocked, min(s)>='01' adds 1 for clearing it. Then both rows lose their first column, and the cell you step onto becomes 0. That's 63 bytes. Claude Fable 5.2 and Gemini 4 Neon found the same idea, and the column-by-column solutions take 78 bytes or more.

  • The quaternion group in one number. Quaternions asks for the product of a string of 1, i, j and k, such as ijkj. The usual shortcut numbers 1, i, j and k from 0 to 3. Then XOR gives the letter of a product, and only its sign needs a lookup table. Many models drop the table: they number all eight results, ±1, ±i, ±j and ±k, from 0 to 7, and multiply with x ∘ y = x + 3ˣ·y (mod 8). Bit 2 holds the sign. 3ˣ mod 8 is 1 when x is even and 3 when x is odd, and that twist is what makes i × j = −(j × i). GPT-6.2 Sol's Python does it in 67 bytes; the next shortest Python takes 74:
PYTHON
g=lambda a:'----1kji'[reduce(lambda n,c:n-ord(c)%25*3**n&7,a,4)::4]

ord(c)%25 turns 1, i, j and k into 24, 5, 6 and 7. The code subtracts these steps, so modulo 8 the letters get the numbers 0, 3, 2 and 1, their positions in 1kji. Starting at 4 instead of 0 multiplies the whole product by −1, which suits the output: '----1kji'[n::4] takes every fourth character from position n, giving one character for n from 4 to 7 and two, a minus sign first, for n from 0 to 3.

  • Three exponents from one counter. (−5)-Smooth Numbers asks for the first n positive numbers of the form (−2)ˣ(−3)ʸ(−5)ᶻ, that is, numbers 2ˣ3ʸ5ᶻ with x+y+z even. Most solutions build them with nested loops or by growing a set, then sort. GPT-6.2 Astra's Python gets them all from powers of 4:
PYTHON
g=lambda n:sorted(4**i%(2**999-5)%(2**49-3)for i in range(7000))[:n]

Modulo 2⁹⁹⁹−5, each factor 2⁹⁹⁹ in 4ⁱ = 2²ⁱ turns into a 5. Modulo 2⁴⁹−3, each 2⁴⁹ turns into a 3. So, writing 2i = 999z + 49y + x, 4ⁱ becomes 5ᶻ3ʸ2ˣ. Since 2i is even and 999 and 49 are odd, x+y+z is even too: the sign condition comes for free. When a product doesn't fit below a modulus, the reduction scrambles it, but every scrambled value is above 7 × 10¹⁰, and the largest number the problem needs is 10⁹. That's 68 bytes; the other Python solutions take 70 or more.

  • Counting each neighbour twice. Game of Life asks for the next generation of a board. A cell lives on if it has three live neighbours, or two if it's already alive. Most solutions add up each 3×3 block and compare the sum with 3 and 4. GPT-6.2 Astra's Python counts the block twice:
PYTHON
g=lambda a,p=['z'*99]:[a<p and`g(zip(*r))`[1::3]or+(4<`r*2`.count('1',4)<8)for r in zip(a,p+a,a[1:]+p)]

Each block r is a nested tuple of characters with the cell itself first. In the text form of r*2, the block written out twice, that cell's character is at index 3, so counting 1s from index 4 skips it in the first copy only. For a cell c with N live neighbours, the count is 2N+c, and 4 < 2N+c < 8 is exactly the rule: 5 or 7 for a live cell with two or three neighbours, 6 for an empty cell with three.

One lambda handles both directions. Called with the rows, it zips each row and its neighbours into columns, calls itself on them and reads the digits back out of the resulting list's text with [1::3]. Called with those columns, it counts. The test a<p tells the two cases apart: Python 2 compares a list of strings with ['zzz…'] string by string, but ranks any tuple above any string. The z's also pad the edges, since they aren't 1s. zip stops at its shortest string, though, so a top or bottom row more than 99 cells wide would come out cut short; the test boards are at most 66 wide. That's 103 bytes; GPT-6.2 Sol uses the same count in 108, and the other Python solutions take 121 or more.

  • Raising the bar instead of counting letters. Cracking Caesar asks you to decrypt a Caesar cipher, knowing that e is the most common letter in the plaintext. The usual approach counts the letters, finds the most common one and shifts every letter by its distance from e. Claude Fable 5.2's C++ and Gemini 4 Argon's, both 93 bytes, never count the letters:
CPP
int n,i;string g(string a){for(char&x:n=i++/26,a)n-=x>64&&(--x%32?:x+=26)^5;return n?g(a):a;}

Each call shifts every character after @ back by one and subtracts 1 from n for each one that doesn't become e. x>64 isn't a real letter test: it would also shift [ to Z, although only letters are encrypted. It works because the test messages contain only letters and punctuation that comes before A. n starts at i/26, where i counts the calls, and the function stops when n ends at exactly 0. In the first 26 calls, one full cycle of shifts, that only happens if every letter becomes e; in the next 26, if all but one do; and so on. So the first shift to meet the rising bar is the one with the most e's. Solutions that count the letters and then shift once take 121 bytes or more. This one is slow, up to a few thousand recursive calls on the tests, but that costs no bytes.

  • Complex numbers, now common. Two ideas that only a few models had found when I first wrote this page are now in most models' Python and Ruby solutions.

In Surviving queens, a queen survives if no other queen shares its row, column or diagonal. Put the queen in row r and column c at the complex number r + ci. The directions a queen can move in are the eight multiples of 45°, and raising a difference to the fourth power multiplies its angle by four, which puts exactly those directions on the real axis. So two queens attack each other when (z − w)⁴ is real. In Ruby, comparing a complex number with <=> gives nil unless it's real, and 0 counts as true, so Claude Fable 5.2's Ruby counts the queens x for which q.one?{(it-x)**4<=>0} holds: x itself, with a difference of 0, must be the only queen at a real fourth power.

In The Rolling Dice, a die is back in its starting orientation exactly when one well-chosen point on a sphere around it is back where it started: a point that no rotation of the die other than the identity leaves in place. So instead of tracking six faces, follow that point. Stereographic projection maps the sphere to the complex plane, and a roll in direction k, one of 1, i, −1 and −i, becomes z → (z+k)/(1−z/k). GPT-6.1 Sol's Ruby takes 61 bytes:

RUBY
g=->a{z=2;a.bytes.map{z+=r=1i**(-it/3);z/=2-z/r;z==2?1:0}*''}

1i**(-it/3) turns each letter's character code into its direction, and the two updates together apply the formula. Ruby does this arithmetic exactly, with fractions, so z==2 can test for the starting point directly. Python's complex numbers are floating-point, so the Python versions test for something only the starting point satisfies, such as a real part above 2.

These solutions depend on finding and trying different ideas, then choosing the one that uses the fewest bytes. The fastest or most elegant algorithm isn't necessarily the one you want. Ordinary coding benchmarks rarely give a model a reason to look for this sort of solution.

Why one byte can be hard to remove

In a well-golfed program, the same piece of code often does several jobs. That's how it got so short. It's also why an apparently simple change can break something elsewhere.

Here is GPT-6.1 Sol's 79-byte JavaScript for Nim:

JAVASCRIPT
function g(a){for(i=-1;(d=a[++i],d-=d^eval(a.join('^')))<0;);return[d?i:--d,d]}

The algorithm is the usual one. Let x be the XOR of all the heap sizes. If x is 0, there's no winning move. Otherwise, find the first heap a for which a − (a XOR x) is positive, and take that many stones. But fitting it into this code requires a few tricks:

  • eval(a.join('^')) builds an expression such as 3^5^6 and evaluates it to get x. It's inside the loop test, so it runs again for every heap. That wastes time but saves storing x in a variable.
  • The test reads the next heap into d and turns it into d − (d XOR x) on the spot. Unless x is 0, that's never 0, and it's negative exactly when we're looking at the wrong heap.
  • If x is 0, the first heap gives 0, so the loop stops with i at 0. Then d?i:--d gives −1, and because --d also changes d to −1, the second element is −1 as well.

GPT-6.2 Astra's JavaScript takes one byte less. It uses the same algorithm and tricks, but reads each heap in the loop body instead of the test:

JAVASCRIPT
function g(a){for(i=d=0;(d-=d^eval(a.join('^')))<0;)d=a[i++];return[--i,d||i]}

That one move changes everything around it. The loop now tests before it has read a heap, so d starts at 0, and the first test computes 0 − (0 XOR x) = −x. That starts the loop when x isn't 0 and stops it at once when x is. Reading after testing leaves i one past the heap it found, so the result uses --i. In the losing position the loop never runs: --i turns 0 into −1, and d||i turns d's 0 into the same −1.

Moving the read saves nine bytes in the test, d=a[++i],, and costs eight in the body, d=a[i++]. The new start, i=d=0, is a byte longer than i=-1, and the new result, [--i,d||i], is a byte shorter than [d?i:--d,d]. The saving only appears when the start, the indexing and the losing case all change together. That's common in golfed code: a variable has two meanings, or an expression both updates the state and checks whether we're done. Remove a byte in one place and you may break an assumption somewhere else.

Solutions of the same length can be just as far apart. These are GPT-6.2 Astra's and Claude Fable 5.2's 91-byte JavaScript for Quaternions. Both use the mod 8 multiplication described above:

JAVASCRIPT
function g(a){for(i=x=.5;y=1976%a.charCodeAt(i++);)x+=x%2*y;return(x&4?'-':'')+'1kji'[x&3]}
JAVASCRIPT
function g(a){for(i=t=0;c=a.charCodeAt(i++)%25;)t+=t%2*2*c-c;return["-"[~t&4]]+"1kji"[t&3]}

In Astra's, the .5 does three jobs:

  • charCodeAt drops the fraction from its argument, so i = .5, 1.5, 2.5, … reads characters 0, 1, 2, …. Past the end it returns NaN, and 1976%NaN is NaN, which stops the loop.
  • x%2 is .5 when x's whole part is even and 1.5 when it's odd, so x grows by y/2 or 3y/2: the factor of 3 for odd x, without computing a power. 1976% gives 16, 86, 68 and 50 for 1, i, j and k. They're all even, so their halves are whole numbers, and modulo 8 those halves are 0, 3, 2 and 1, the positions in 1kji.
  • x&4 and x&3 ignore the fraction.

Fable's takes its steps from %25 instead (24, 5, 6 and 7, and NaN at the end) and never lets t rise above 0. Then t%2 is 0 or −1, so t%2*2*c-c multiplies c by −1 or −3: the same twist with the sign reversed. And ["-"[~t&4]] is either ["-"] or [undefined], and the second turns into an empty string when added to "1kji"[t&3].

The two solutions do the same arithmetic in the same length, but neither can borrow a piece from the other: Astra's .5 needs even steps, and Fable's sign trick needs t never to be positive.

To make code like this shorter, the model has to understand why all the pieces work together. A change still has to leave the whole program correct.

Knowing when to keep trying

The first few cuts are usually easy. After that, you can spend a long time trying things without saving a byte. It's tempting to stop there, even when the scoreboard says a shorter solution exists.

Models get 30 minutes per cell and are always shown the best known size. They don't have to use the whole session: the instructions say to keep submitting while they have ideas for improvements, and to stop when they run out. Continuing to come up with things to try matters here.

GPT-6 Sol usually stops after 5 to 10 minutes, even at its highest reasoning effort. With exactly the same prompts, every GPT-5 model, including GPT-5.6 Luna, is still working at the 30-minute limit on most cells. I suspect this explains much of GPT-6 Sol's ranking.

Eight different languages

The language set includes imperative languages, Haskell's functional style, Racket's Lisp prefix notation and the stack-based esoteric language GolfScript, for which there's little training data. Golfing well across all of them takes more than repeating familiar patterns; a model has to apply what it knows in quite different settings.

Human records to compare against

These records came from Googlers who enjoyed code golf and spent a week competing on each problem, with the option to keep challenging afterwards. They put real time into finding shorter solutions. Beating those records means more to me than beating a reference answer nobody tried very hard to golf.

What the results show so far

GPT-6.2 Astra is the first frontier model to surpass the human records on JS/PY/C++, the combined score for JavaScript, Python and C++: 92.265%, compared with 87.533% for humans. So far it's the only model above them. Its lead doesn't rest on one strong language: it scores above the humans in each of the three.

LanguageHumansGPT-6.2 AstraCells humans still hold
JavaScript80.980%90.555%4 of 32
Python90.579%93.049%5 of 32
C++91.039%93.190%5 of 32
JS/PY/C++87.533%92.265%14 of 96

These human records combine the best submissions from the original contest and later challenges, not one person's 30-minute run. Models have beaten them in 62 of the 96 cells, but in 14 the human solution is still shorter than every model's: those are the cells humans still hold. Both counts exclude the unranked oracle.


作者发帖说明(HN):

Back in 2015, when I was still at Google, there was a small group of code-golf enthusiasts spending hours trying to save just one byte on their solutions for weekly code-golf problems. No matter how hard you tried, there always seemed to be another Googler who found a shorter solution. And once a problem entered the challenge phase and every solution became public, it was always astonishing to read how brilliant other people's solutions were.

So I built this benchmark. Frontier models do find a lot of new approaches (and very brilliant ones) to solve these problems. For example, in two problems ("Surviving Queens" and "The Rolling Dice"), frontier models use complex numbers to solve them in Python and Ruby (both languages have built-in complex number support). And for the "(-5)-Smooth Numbers" problem, where you have to write code to list the first n positive integers of the form (-2)^x⋅(-3)^y⋅(-5)^z, most solutions build them with nested loops or by growing a set, then sort. GPT-6.2 Astra gets them all from powers of 4, and earns a sole best with this brilliant solution:

文本
    g=lambda n:sorted(4**i%(2**999-5)%(2**49-3)for i in range(7000))[:n]

It's nice to see GPT-6.2 Astra become the first frontier model to beat the human records in code golfing. Along with other frontier models, it finds a lot of interesting solutions that Googlers back in 2015 didn't. On the other hand, I also believe code golfing can be a good benchmark (not a comprehensive one, of course) for ...