fork download
  1. #!/usr/bin/perl
  2. use 5.016;
  3. use warnings;
  4. use Scalar::Util qw(dualvar looks_like_number);
  5.  
  6. sub _fizz_buzz {
  7. dualvar($_[0],
  8. ($_[0] % $_[1] ?
  9. "$_[0]" :
  10. (looks_like_number("$_[0]") ? $_[2] : $_[0] . $_[2])
  11. )
  12. )
  13. }
  14.  
  15. sub fizz { _fizz_buzz($_[0], 3, 'Fizz') }
  16. sub buzz { _fizz_buzz($_[0], 5, 'Buzz') }
  17. sub gizz { _fizz_buzz($_[0], 7, 'Gizz') }
  18.  
  19. say buzz fizz 1;
  20. say buzz fizz 3;
  21. say buzz fizz 5;
  22. say buzz fizz 15;
  23. say buzz fizz 998;
  24.  
  25. say gizz buzz fizz 7;
  26. say gizz buzz fizz 21;
  27. say gizz buzz fizz 35;
  28. say gizz buzz fizz 105;
  29. say buzz gizz fizz 105;
  30.  
  31. say buzz(fizz(1)) + 2;
  32. say fizz(buzz(fizz(1)) + buzz(2));
  33. say gizz(buzz(fizz(15))) . "XXX";
  34.  
Success #stdin #stdout 0s 3848KB
stdin
Standard input is empty
stdout
1
Fizz
Buzz
FizzBuzz
998
Gizz
FizzGizz
BuzzGizz
FizzBuzzGizz
FizzGizzBuzz
3
Fizz
FizzBuzzXXX