Abuzz with FizzBuzz

Abuzz with FizzBuzz

Publish Date: Nov 10 '24
3 2

zeekar asked about FizzBuzz ideas ( redlib.zaggy.nl ) in raku.

¡ Exercism to the rescue ! The programming practice site has some seventy exercises to try in raku. One of particular interest here is the Raindrops exercise ( exercism.org ) — which is FizzBuzz ( en.wikipedia.org ) in disguise.

Caleb Miller's solution

Paraphrasing @steffan153 's concise solution ( exercism.org ) :

say ([~] <Fizz Buzz> Zx $_ <<%%<< <3 5> or $_) for 1..100
Enter fullscreen mode Exit fullscreen mode

The somewhat unintuitive magic here is that the string repetition operator x can be used to repeat Fizz or Buzz "boolean times". 🧐

¿ What on earth ( docs.raku.org ) ?

Raku happily numifies ( perldoc.perl.org ) the booleans to integers — True becomes 1 and False becomes 0.

+True, +False
# (1 0)
Enter fullscreen mode Exit fullscreen mode

I remain in wonder at the thoughtful consideration of raku's edge-case handling. I didn't imagine that booleans would be cast to integer and so help in the reduction.

Boundaries are an opportunity to experience growth but all too often elicit carelessness. I sense raku's mindful approach here as extending consideration beyond concern for the common case to include the common edge-case.

The dance is joined when interplay and interrelatedness are akin to first-class citizens… and so I've come to describe raku not as a multi-paradigm language but as a synthesis or constellated language.

Comments 2 total

  • raiph
    raiphNov 11, 2024

    Paraphrasing @steffan153's concise solution:

    Challenge accepted!

    Just kidding, but I like to think the following is reasonably "Clear Golf", as I've explained back on the reddit thread:

    say "{'Fizz' when *%%3}{'Buzz' when *%%5}" or $_ for 1..100;
    
    Enter fullscreen mode Exit fullscreen mode
Add comment