Code-golfing FizzBuzz

This is just delightful. @gbaraldi posted on Slack so I got to decipher it without explanation, which took me a while. What a nice puzzle. :clap:

3 Likes

Thanks for the explanation!

Sorry if this was mentioned before (my eyes glaze over a bit at all of this arcana), but does \n count as 2 bytes, or 1? If 1, wouldn’t print(...,"$i\n") be shorter?

No, because you’d need the \n in the Fizz and Buzz parts as well. It’s also bytes of source code that count, so at best you could insert a literal newline byte.

3 Likes

correct, \n is two characters, hence two bytes. It’s better to type in directly the newline in certain cases. Say you have

println("abc\nabc")

this (19bytes) can be shorter (17bytes)

print("abc
abc
")
3 Likes

Of course, if we trust that site not to be trolling us.

The question was about existence of a solution of given lengths using particular methods not whether any possible solutions of specific lengths.

They take code golfing very seriously and the website code is open-source. Loopholes and exploits are fixed readily. I trust that the solution is legit

2 Likes