Created
November 3, 2011 08:22
-
-
Save mrmt/1336034 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use feature 'say'; | |
use warnings; | |
use strict; | |
usage() unless scalar(@ARGV) == 1; | |
our $max_value = $ARGV[0]; | |
usage() unless $max_value > 0; | |
for my $i (1 .. $max_value){ | |
if(fizzbuzz($i)){ | |
say 'FizzBuzz'; | |
}elsif(fizz($i)){ | |
say 'Fizz'; | |
}elsif(buzz($i)){ | |
say 'Buzz'; | |
}else{ | |
say $i; | |
} | |
} | |
exit; | |
sub fizz{ | |
my $n = shift; | |
return ($n % 3 == 0); | |
} | |
sub buzz{ | |
my $n = shift; | |
return ($n % 5 == 0); | |
} | |
sub fizzbuzz{ | |
my $n = shift; | |
return fizz($n) && buzz($n); | |
} | |
sub usage{ | |
die "Usage: $0 max_value\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment