Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/local/bin/perl6
- sub fizzAppender(Int:D $mod) {
- return sub (Str:D $currentOut, Int:D $currentNum) {
- if $currentNum % $mod == 0 {
- return $currentOut ~ "Fizz";
- }
- return $currentOut;
- }
- }
- sub buzzAppender(Int:D $mod) {
- sub (Str:D $currentOut, Int:D $currentNum) {
- if $currentNum % $mod == 0 {
- return $currentOut ~ "Buzz";
- }
- return $currentOut;
- }
- }
- sub reverser(Int:D $mod) {
- sub (Str:D $currentOut is copy, Int:D $currentNum) {
- if $currentNum % $mod == 0 {
- if $currentOut eq "" {
- $currentOut = "$currentNum";
- }
- return $currentOut.flip();
- }
- return $currentOut;
- }
- }
- sub dogPrepender(Int:D $mod) {
- sub (Str:D $currentOut, Int:D $currentNum) {
- if $currentNum % $mod == 0 {
- return "Dog" ~ $currentOut;
- }
- return $currentOut;
- }
- }
- my @mutators = (
- fizzAppender(3),
- buzzAppender(5),
- reverser(7),
- dogPrepender(11),
- reverser(13)
- );
- sub MAIN(Int:D $start, Int:D $end) {
- for $start..$end -> $i {
- my $output = "";
- my $changed = False;
- for @mutators -> &mutator {
- $output = &mutator($output, $i);
- }
- if $output ne "" {
- say $output;
- } else {
- say $i;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement