3 ms·
The moment we've been waiting for. Who else remembers how to fizzbuzz? We're gonna be rich.
by ibejoeb 1mo ago
The moment we've been waiting for. Who else remembers how to fizzbuzz? We're gonna be rich.
- rrrx3 1mo agohttps://github.com/enterprisequalitycoding/fizzbuzzenterpriseedition https://github.com/enterprisequalitycoding/fizzbuzzenterpris...
- embedding-shape 1mo agoOn 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)
- NitpickLawyer 1mo agoPerl6: say "Fizz"x$_%%(2+1)~"Buzz"x$_%%(4+1)||$_ for 1..100 from here - https://github.com/rsha256/shortest-fizzbuzz/blob/master/Perl6.pl https://github.com/rsha256/shortest-fizzbuzz/blob/master/Per...
- danbruc 1mo agoWhy does this use 2+1 and 4+1 instead of 3 and 5?
- wilkystyle 1mo agoPython: [(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.
- gilleain 1mo ago>>> len("[(x%3<1)'Fizz'+(x%5<1)'Buzz'or x for x in range(1,101)]") 57
- winrid 1mo agoyou 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'
- embedding-shape 1mo ago> but not valid fizzbuzz then Well, if we let that requirement be broken, I'll present an even shorter JS version: 1
- winrid 1mo agojust thought it was fun. thanks for your reply.
- chrisguilbeau 1mo agoLLM: wrt frst 100fizzbuzz
- embedding-shape 1mo agoActually 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
- JaumeGreen 1mo ago"golf fizbuz" works well, giving a 54 Python one for i in range(1,101):print("Fizz"*(i%3<1)+"Buzz"*(i%5<1)or i) "golf fizzbuzz" gave a 46 perl one print$_%15?$_%3?$_%5?$_:Buzz:Fizz:FizzBuzz,$/for 1..100 Both "code fizzbuzz" and just "fizbuz" gave this longer python one-liner print('\n'.join("Fizz"*(i%3==0)+"Buzz"*(i%5==0) or str(i) for i in range(1, 101))) 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.
- embedding-shape 1mo agoWhenever I try those short prompts, I get bunch of text + the code itself, but way more than just the code. Which model specifically are you doing this with?
- JaumeGreen 1mo agoI'm getting the text too, of course. Several variations of the code with it usually. Trying to get an AI give ONLY a simple answer and not several is "boring" to me, as for me AI is a supplement to my reasoning ability, not a substitute. Appending "code only" seems to work, at least with "golf fizbuz code only" gave me this one liner, which is long, but at least doesn't have the text that you dislike. for i in range(1,101):print('FizzBuzz'[i%3*4:8-i%5*4]or i)
- deleted 1mo ago[deleted]
- deleted 1mo ago[deleted]
- nprateem 1mo agoI do! > openai.messages("write fizzbuzz in python") Bingo