(I came across a fun code golf question that wasn’t just about minimizing byte count, and thought people here might enjoy it too.)
Your task is to write as many programs / functions / REPL snippets as you can, where each one outputs / prints / returns an integer. The first program must output the integer
1, the second one
2 and so on.
You can not reuse any characters (except whitespace) between the programs. So, if the first program is:
one(Int), then you may not use the characters’o’, ‘n’, ‘e’, ‘(’, ‘I’, ‘n’, ‘t’, and ‘)’ again in any of the other programs. Note: It’s allowed to use the same character many times in one program.
The winner will be the submission that counts the highest. In case there’s a tie, the winner will be the submission that used the fewest number of bytes in total.
- REPL snippets are allowed!
- The output must be in decimal. You may not output it with scientific notation or some other alternative format. Outputting floats is OK, as long as all digits that are shown behind the decimal point are
4.000is accepted. Inaccuracies due to FPA is accepted, as long as it’s not shown in the output.
ans =, leading and trailing spaces and newlines etc. are allowed.
- You may disregard STDERR, as long as the correct output is returned to STDOUT
- You may choose to output the integer to STDERR, but only if STDOUT is empty.
- Letters are case sensitive
a != A.
- The programs must be independent
- You must use ASCII-digits in the output
Explanations are encouraged!
(The challenge text above is almost entirely from the linked StackExchange post by Stewie Griffin, edited for clarity+to remove rules that didn’t make sense/made it (subjectively) less fun in Julia.)
I made an attempt at it and got up to 13 (but I’d encourage you to attempt it yourself before being influenced by my answer).
For eg., the following would be a valid answer:
2÷2 using Primes prime(one(Int)) 3 4 5 6 7 8 9 10
This counts as a series of REPL snippets that count up to 10. (If you use a multiline snippet for any number, like the snippet for outputting
2 here, I suggest using empty line before and after it for clarity.)
In your post, please mention if you’re posting REPL snippets or programs, and whether it’s in Julia 0.6 or 0.7.
(To moderators: This seemed the forum category that seemed to fit more than the others, so I’ve posted it on Usage. It doesn’t exactly fit under “Off Topic” since it is about Julia and its usage - but I’ll be happy if this inspires a new “Fun with Julia” or similar forum category. )