Quick actions

cmd+k|ctrl+k

Navigation

Languages

Four is magic

Snippet info

Language

Raku

Visibility

public

Author

fernando-correa

Created

2022-04-15T10:19:58.296657Z

Updated

2022-04-15T10:19:58.296657Z

constant %name-of =
    0 => 'zero',  1 => 'one',
    2 => 'two',   3 => 'three',
    4 => 'four',  5 => 'five',
    6 => 'six',   7 => 'seven',
    8 => 'eight', 9 => 'nine',
;

multi take-magic-four(4) {
    take "four is magic"
}

multi take-magic-four(UInt $num where * < 10) {
    my $name = %name-of{$num};
    my $len  = $name.chars;
    
    take "$name is %name-of{$len}";
    take-magic-four $len
}

sub magic-four(UInt $num where * < 10) {
    gather { take-magic-four($num) }.join: ", "
}

for ^10 -> $num {
    say magic-four $num
}
INFO