When code golfing, it can be useful to write numbers succinctly. This challenge involves using a source language to generate code for a target language. For the submission to be valid, it must generate 1,000,001 snippets of code for the target language which evaluate to the integers 0, 1, ..., 1000000 (when evaluated in the source language). Target languages unable to exactly express these constants are excluded from this challenge.
This is meta-golf, your score is the sum of the number of bytes in each snippet. In particular, the length of the source code provided does not affect your score. Feel free to format as you prefer. Similarly, the way you delimit the code snippets is flexible. You can return an array, print one on each line, etc., as long as it's clear which is which.
Because each target language has different rules, submissions only compete with other submissions using the same target language.
Results
Note that different target languages are not competing with one another; I've arranged them by size only for interest.
Target language | Bytes | Contributor |
---|---|---|
(best possible non-byte-based language) | 2,491,449 | N/A |
(best possible byte-based language) | 2,933,952 | N/A |
!@#$%^&*()_+, | 3,932,313 | Fmbalbuena |
Vyxal 3 | 4,791,348 | pacman256 |
Charcoal | 4,982,032 | Neil |
JavaScript | 5,887,526 | Arnauld |
C++ | 5,887,608 | Toby Speight |
(various - baseline) | 5,888,897 | Charles |
Brainfuck | 500,000,500,000 | Charles |
Note: No byte-based target language can have a score better than 2,933,952. A target language constructed information-theoretically perfectly for this challenge would use log(1000001)/log(2) bits for each number for a total of just under 2,491,449 bytes.
Note: If you don't need a source language, just submit your answer as, e.g., "Text → C" and note the delimiter used between programs. But you're guaranteed to need megabytes for this.
1e3
will evaluate to1000.00000
in many languages (and there may be a tiny error in the 10th or 20th significant figure.) Do such floating point numbers count as integers? \$\endgroup\$1e3
is out butfloor(1e3)
is ok.1e5\1
is still a win in PARI/GP. \$\endgroup\$1e3
is exactly1000.0
, no rounding error allowed. It's a compile-time constant, and if the exact value is representable, must have that value, else rounded up or down to nearest representable value in an implementation-defined manner. (Code golf answers get to pick any real implementation). It's not a call to an imprecisepow(10, 3)
function. An implicit conversion of1e3
back toint
will produce1000
, so if the target language is C, you should be good to use scientific notation in numeric literals. \$\endgroup\$int32_t
values takes 4 bytes each, so 4000004 bytes. Or with packed_BitInt(24)
still aligned at byte boundaries, 3000003. (log2(1M) = 19.93 rounds up to 20 bits per number fitting, and as a bonus that's at least nibble-aligned for 2500002.5 bytes) Maybe a varint binary representation, but probably not since most of the numbers are large. I notice you phrased it as 1M+1 separate snippets, so a delta encoding isn't valid. \$\endgroup\$