Code-golfing FizzBuzz

clever, I had tried \circ with println and max but then required another pair (,)

Getting closer!
60 bytes/chars

1:100 .|>x->println(max("$x","Fizz"^(x%3<1)*"Buzz"^(x%5<1)))

Edit: sorry haven’t seen the post above with this same solution

1 Like

Is there some hidden Unicode character to replace the max function call?

Not that I am able to find, interestingly learning a lot about Julia trying to solve this though so its not all for naught

this could be the one if only we could find a way of broadcasting "$x" without string

for now is 63 bytes/chars

1 Like

Can shorten this one down to 61


Some remarks/observations

My suspicion is "$x" is used.

Defining the exponents for the strings outside the primary call saves parentheses but then adds characters to insert: i.e. f=x%3<1 is the same length as (x%3<1) but then need to use;.

Using the ternary operator a ? b : c certainly takes up too much space

Trying to put it into one string doesn’t work because need to concatenate $x with FizzBuzz and there is no efficient way to then call exactly which indices are wanted, would have been nice given strings behave as arrays

Would be nice if show() works but it much like print displays on a single line. dump() was an option I tried, it prints on new lines but also includes type of the item being printed.

I have found no alternative to using max()

I had wondered if there was a clever way to use 0:99 but can’t seem to find a workaround for this.

1 Like

some other observations:

  • $x needs max and we probably already have the best solution with that idea
  • 0:99 is appealing but I don’t see a way of using it neither. This could be a false friend though, as we’re looking to remove just one byte/char and that blank space after 100 is the obvious target
  • broadcasting over N=1:100 usually yields the best solution, but in this case we’re stuck at 61
  • another sometimes winning approach is to write a recursive solution, but I cannot do better than 68
i<n=102>i+1<println((f=1>i%3)|(b=1>i%5) ? "Fizz"^f*"Buzz"^b : i);1<0
  • we can use gcd for a single check instead of two (66)
f="Fizz";b="Buzz";1:100 .|>i->println([i i f f*b b][gcd(i,15)%11])

Those two solutions are neat.

Searching around for tips for code golfing in Julia, on the Code Golf StackExchange came across discussion for this problem. From the discussion it appears there is a 60char/bye solution using repr and there is a 59char/byte solution using "$x".

another whacky one (65)

1:100 .|>x->println(max("$x",join(("Fizz","Buzz")[x.%[3,5].<1])))

Well for what its worth I freed up one char/byte on

f="Fizz";b="Buzz";1:100 .|>i->println([i i f f*b b][gcd(i,15)%11])
1:100 .|>x->println((x,"FizzBuzz","Fizz",x,"Buzz")[gcd(x,15)%13])


Does it have to be short, or just weird:

t=1:100;t.|>println∘x->["$x","Fizz","Buzz","FizzBuzz"][Dict([1 3 5 0].*t.=>[1 2 3 4])[x%15]]
1 Like

Weird examples are certainly welcome. I’m sure they could get pretty weird, I really want to crack that 59 char/byte solution though.

This one is cool

This one is both weird and breaks all barriers (but of dubious correctness):


This is very cool

Replacing \r with \b gives something visually almost correct

another hint from the leaderboard is that the smallest solution is 59bytes/59chars, so no unicode trickeries.
But there’s a shorter solution with 61bytes/57chars which may imply the use of (3bytes/1char)

1 Like

It has me pretty stumped, I’ve been working on it in-between writing stuff for my thesis.

I feel you xD
I have so many solutions 1byte from best on that website…it drives me crazy

1 Like

The most frustrating is when an idea seems potentially it then realize you’re at 61+ char/bytes haha.

If the approach is different share it even though is not the shortest one. Someone else could find a way to make it work