Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,28 @@
# General case implementation of a "FizzBuzz" class.
# Defaults to standard FizzBuzz unless a new schema is passed in.
class FizzBuzz {
has $.schema is rw = < 3 Fizz 5 Buzz >.hash;
method filter (Int $this) {
my $fb;
for $.schema.sort: { +.key } -> $p { $fb ~= $this %% +$p.key ?? $p.value !! ''};
return $fb || $this;
}
}
# Sub implementing the specific requirements of the task.
sub GeneralFizzBuzz (Int $upto, @schema?) {
my $ping = FizzBuzz.new;
$ping.schema = @schema.hash if @schema;
map { $ping.filter: $_ }, 1 .. $upto;
}
# The task
say 'Using: 20 ' ~ <3 Fizz 5 Buzz 7 Baxx>;
.say for GeneralFizzBuzz(20, <3 Fizz 5 Buzz 7 Baxx>);
say '';
# And for fun
say 'Using: 21 ' ~ <2 Pip 4 Squack 5 Pocketa 7 Queep>;
say join ', ', GeneralFizzBuzz(21, <2 Pip 4 Squack 5 Pocketa 7 Queep>);

View file

@ -0,0 +1,9 @@
sub genfizzbuzz($n, +@fb) {
[Z~](
do for @fb || <3 fizz 5 buzz> -> $i, $s {
flat ('' xx $i-1, $s) xx *;
}
) Z|| 1..$n
}
.say for genfizzbuzz(20, <3 Fizz 5 Buzz 7 Baxx>);