How to resolve the algorithm FizzBuzz step by step in the Raku programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm FizzBuzz step by step in the Raku programming language

Table of Contents

Problem Statement

Write a program that prints the integers from   1   to   100   (inclusive).

But:

The   FizzBuzz   problem was presented as the lowest level of comprehension required to illustrate adequacy.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm FizzBuzz step by step in the Raku programming language

Source code in the raku programming language

for 1 .. 100 {
    when $_ %% (3 & 5) { say 'FizzBuzz'; }
    when $_ %% 3       { say 'Fizz'; }
    when $_ %% 5       { say 'Buzz'; }
    default            { .say; }
}

multi sub fizzbuzz(Int $ where * %% 15) { 'FizzBuzz' }
multi sub fizzbuzz(Int $ where * %%  5) { 'Buzz' }
multi sub fizzbuzz(Int $ where * %%  3) { 'Fizz' }
multi sub fizzbuzz(Int $number        ) { $number }
(1 .. 100)».&fizzbuzz.say;

[1..100].map({[~] ($_%%3, $_%%5) »||» "" Z&&  or $_ })».say

say 'Fizz' x $_ %% 3 ~ 'Buzz' x $_ %% 5 || $_ for 1 .. 100;

say "Fizz"x$_%%3~"Buzz"x$_%%5||$_ for 1..100

.say for
    (
      (flat ('' xx 2, 'Fizz') xx *)
      Z~
      (flat ('' xx 4, 'Buzz') xx *)
    )
    Z||
    1 .. 100;

  

You may also check:How to resolve the algorithm Fraction reduction step by step in the Ada programming language
You may also check:How to resolve the algorithm Quickselect algorithm step by step in the Crystal programming language
You may also check:How to resolve the algorithm Visualize a tree step by step in the Perl programming language
You may also check:How to resolve the algorithm Pernicious numbers step by step in the REXX programming language
You may also check:How to resolve the algorithm Compiler/AST interpreter step by step in the Forth programming language