Comment by embedding-shape
18 hours ago
On the other spectrum, shortest JS fizzbuzz (62 characters):
for(i=0;++i<101;console.log(i%5?f||i:f+'Buzz'))f=i%3?'':'Fizz'
Anyone can beat it? (any language accepted)
18 hours ago
On the other spectrum, shortest JS fizzbuzz (62 characters):
for(i=0;++i<101;console.log(i%5?f||i:f+'Buzz'))f=i%3?'':'Fizz'
Anyone can beat it? (any language accepted)
Perl6: say "Fizz"x$_%%(2+1)~"Buzz"x$_%%(4+1)||$_ for 1..100
from here - https://github.com/rsha256/shortest-fizzbuzz/blob/master/Per...
Why does this use 2+1 and 4+1 instead of 3 and 5?
LLM: wrt frst 100fizzbuzz
Actually kind of curious challenge; what's the shortest prompt you can use, which would produce the shortest possible fizzbuzz?
Edit: counting including the entire assistant reply, any text + code
"golf fizbuz" works well, giving a 54 Python one
"golf fizzbuzz" gave a 46 perl one
Both "code fizzbuzz" and just "fizbuz" gave this longer python one-liner
That's the magic of using a known problem, you don't need to write much and even with incomplete prompts it can be understood. Everything a different new chat in kimi.ai, which was the AI window that I found first among mine.
Not interesting enough, to me, to try with other LLMs or phrases.
3 replies →
My attempt:
> Prompt: mkfzbuzgolf
> LLM Used: Default ChatGPT free LLM
> Output: for i in range(1,101):print("Fizz"*(i%3<1)+"Buzz"*(i%5<1)or i)
So, 11 prompt characters and 62 output.
——-
Did a few more tries and I can get the 4-character string “glfz” (2 tokens) to work surprisingly consistently. But only on ChatGPT
1 reply →
"100fizzbuzz" as the prompt works to satisfys fizz buzz to 100 on Claude.
Python:
[(x%3<1)*'Fizz'+(x%5<1)*'Buzz'or x for x in range(1,101)]
edit: Hacker News stripped the * character. Now it's properly escaped.
>>> len("[(x%3<1)'Fizz'+(x%5<1)'Buzz'or x for x in range(1,101)]")
57
you can flip it and save a few bytes, but not valid fizzbuzz then:
for(i=100;i--;console.log(i%5?f||i:f+'Buzz'))f=i%3?'':'Fizz'
> but not valid fizzbuzz then
Well, if we let that requirement be broken, I'll present an even shorter JS version:
just thought it was fun. thanks for your reply.