Code-golfing FizzBuzz

Just realised there is no Julia soluton to this on Code golf code golf - 1, 2, Fizz, 4, Buzz - Code Golf Stack Exchange


That’s a very weird discussion, dominated by esoteric programming languages.

Incidentally, do people really ask for this in an interview? I would imagine that simply looking at code on someone’s public FOSS contributions would be a much quicker and more specific test. If a significant number of interviewees are filtered out by this in a process, then the interviewers are not using their own time efficiently.


I’ll bite. Here’s a moderately respectable 69 chars:


I just submitted some results to code golf for laughs:

Julia 87 bytes

z(i)=(f=i .%[3,5] .==0;sum(f)>0 ? foldl(*,["Fizz","Buzz"][f]) : i)

Or we could kind of cheat to drop 3 bytes and use show instead of println.
Julia 83 bytes

z(i)=(f=i .%[3,5] .==0;sum(f)>0 ? foldl(*,["Fizz","Buzz"][f]) : i)

or a more legible FP style, poor performing, 91 bytes

F(x)=foldl(*,["Fizz","Buzz"][x .%[3,5] .==0])
N(y)=F(y)=="" ? y : F(y)

Looks like you beat me with 75 bytes! Nice one! Maybe swap out println with show?

maybe this counts :stuck_out_tongue:
71 bytes


Isn’t a FizzBuzz code supposed to give its output in precisely this form?

Think so. But, I dunno if they care if some other things like " 's are in there or not.

My reading of their rules were that we needed to print to stdout in the standard format so I think show is out :slight_smile:

I missed that they were scoring in bytes rather than characters. That’s a bit of a disappointment, it reduces the golfing opportunities a bit. In that case we may as well use == rather than for a total of 71 bytes (also dropping the trailing ; if not using it at the REPL.)


There may be other options. An observation related to one of the python solutions is that "FizzBuzz$i"[n:m] would do the trick for the right n and m.


You can do ‘i%3<1’ for 2 bytes.


Awe well I tried! Awesome solution though!

I also submitted some code golfs to a few other simple ones. I know Julia isn’t made to do this sort of thing, and it’s really an obtuse use of a programming language - but it’s kind of fun and could give some exposure.

I also made a code golf:

1 Like

I find it interesting that the languages that “win” by the code length criterion range from the somewhat obscure to the very esoteric.

OTOH, the “verbose” languages are actually those that most people prefer to program in, especially for nontrivial projects.

There may be a lesson here :wink:


Not sure if people prefer Java or they just learnt it at uni or forced to use it at work.


I couldn’t agree more. Most of those languages make me sick to my stomach! It is interesting to see some of the solutions in the sane languages with usable syntax though.

If I were ever hiring someone and they actually wrote something in brainfuck, hexagony, labrynth, or whatever the hell I would have serious concerns about their ability to color within the lines. I had a running gag at a previous job that if I were ever interviewing someone and they said the word “Mortran” I would immediately close the interview and leave the room.


I have the opposite feeling. I thikk they are pretty smart. But jot sure if they have the patience to do boring work like colouring within the lines.

Oh yes of course! So we have the following for 69 bytes:


It seems likely a different approach would be needed to make much more progress.

Abusing the tools is the fun of it! I really wanted to use more broadcast in the solution like your nice solution where you have foldl and i .%[3,5] .==0 but the reduction consumes a lot of characters. Here’s a related 78 byte solution:


I don’t think that any of those esoteric languages (eg Keg, Mouse 2002, etc) are used to write anything nontrivial (I am not talking about production, just something one would do in 100 LOC in Julia). They may be fun to play with, but I am not sure even their inventors would argue that they would be an improvement over even the dullest mainstream languages.

I can only manage one letter shorter than yours, for 68 (letters, but not bytes) not including the semicolon needed for the REPL:

julia -e '(i->(x="Fizz"^(i%3≈0)*"Buzz"^(i%5≈0);println(x>"" ? x : i))).(1:100)'

Right (I did too) but you can avoid == and use <, and with ≈, this cryptic code doesn’t make up for it:

for i = 1:100 f,b=.≈((i%3,i%5), 0);println("Fizz"^f*"Buzz"^b*"$i"^!(f|b))end

I can’t take full credit for my best solution, as I combined bits from yours and what was actually there in this answer from 2015 from Alex A (which no longer works in current Julia, I had to add spaces, then actually getting 68 bytes, not just letters):

Julia, 64 bytes

for i=1:100 x="Fizz"^(i%3<1)*"Buzz"^(i%5<1);println(x>""?x:i)end

EDIT: Off-topic below, just cool solutions for Julia to beat (but I doubt possible, still some solutions use gcd or square root, so possibly √ in Julia typed \sqrt helps):

Even PHP is hard to beat and I like how they use ö from my Icelandic (or e.g. German) alphabet:

PHP, 54 bytes


Valid for v5.5 onwards. The õ is character 245, a bit inverted \n .

and also:

Python 2, 56

i=0;exec"print i%3/2*'Fizz'+i%5/4*'Buzz'or-~i;i+=1;"*100

Let alone Perl at 45 bytes, or (other) made for golfing languages:

MathGolf, 24 22 bytes


or those that cheat, here by language targeting this problem:

gs2, 1


Update : Added 27-byte answer that doesn’t use f

My favorite newly discovered (after Piet, and Julia) language/solution is though:

Hexagony, 77 76 bytes


Try it online!

Same side length as M L’s solution, but a bit smaller.

answered Mar 24 '18 at 11:40

Jo King

Hexagony, 91 bytes

[…] Fizzbuzz in a size 6 hexagon:


[…] So, here is a 110 seconds long GIF animation at 2 fps, showing the program flow during the first 6 numbers 1, 2, Fizz, 4, Buzz, Fizz , the first 220 ticks of the program (click on the image for the full size):

enter image description here

[…] Hexagony is not that hard to work with. But golfing it can be a pain in the butt. :wink:

It was fun!

answered Mar 5 '16 at 21:56


I can read non-Julia solutions on stackoverflow…

I got it down to 67 bytes with both the for-loop implementation and the iterator implementation, but I’m not seeing a way forward from here either:

for i=1:100;f=i%3<1;b=i%5<1;println(f|b ? "Fizz"^f*"Buzz"^b : i)end
(i->(f=i%3<1;b=i%5<1;println(f|b ? "Fizz"^f*"Buzz"^b : i))).(1:100)

Note that doing f,b=i%3<1,i%5<1 is the same number of characters as f=i%3<1;b=i%5<1.

Lots of variations on the same theme that don’t actually shorten it at all:

g(i,f=i%3<1,b=i%5<1)=println(b|f ? "Fizz"^f*"Buzz"^b : i);g.(1:100)
(g(i,f=i%3<1,b=i%5<1)=println(b|f ? "Fizz"^f*"Buzz"^b : i)).(1:100)

66 is possible:

1:100 .|>i->(f=i%3<1;b=i%5<1;println(f|b ? "Fizz"^f*"Buzz"^b : i))