Advertisement
Guest User

Untitled

a guest
Dec 10th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 6 1.41 KB | None | 0 0
  1. #!/usr/local/bin/perl6
  2.  
  3. sub fizzAppender(Int:D $mod) {
  4.     return sub (Str:D $currentOut, Int:D $currentNum) {
  5.         if $currentNum % $mod == 0 {
  6.             return $currentOut ~ "Fizz";
  7.         }
  8.         return $currentOut;
  9.     }
  10. }
  11.  
  12. sub buzzAppender(Int:D $mod) {
  13.     sub (Str:D $currentOut, Int:D $currentNum) {
  14.         if $currentNum % $mod == 0 {
  15.             return $currentOut ~ "Buzz";
  16.         }
  17.         return $currentOut;
  18.     }
  19. }
  20.  
  21. sub reverser(Int:D $mod) {
  22.     sub (Str:D $currentOut is copy, Int:D $currentNum) {
  23.         if $currentNum % $mod == 0 {
  24.             if $currentOut eq "" {
  25.                 $currentOut = "$currentNum";
  26.             }
  27.             return $currentOut.flip();
  28.         }
  29.         return $currentOut;
  30.     }
  31. }
  32.  
  33. sub dogPrepender(Int:D $mod) {
  34.     sub (Str:D $currentOut, Int:D $currentNum) {
  35.         if $currentNum % $mod == 0 {
  36.             return "Dog" ~ $currentOut;
  37.         }
  38.         return $currentOut;
  39.     }
  40. }
  41.  
  42. my @mutators = (
  43.     fizzAppender(3),
  44.     buzzAppender(5),
  45.     reverser(7),
  46.     dogPrepender(11),
  47.     reverser(13)
  48. );
  49.  
  50. sub MAIN(Int:D $start, Int:D $end) {
  51.     for $start..$end -> $i {
  52.         my $output = "";
  53.         my $changed = False;
  54.         for @mutators -> &mutator {
  55.             $output = &mutator($output, $i);
  56.         }
  57.         if $output ne "" {
  58.             say $output;
  59.         } else {
  60.             say $i;
  61.         }
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement