Created
May 1, 2016 13:23
-
-
Save jimregan/0209f07405ca6e82a8e9ee90fd967f46 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 POSIX; | |
sub round { | |
my $num = shift; | |
my $by = shift; | |
my $half = ceil($by / 2); | |
if (($num % $by) >= $half) { | |
return ceil ($num/$by) * $by; | |
} else { | |
return floor ($num/$by) * $by; | |
} | |
} | |
if (round (43, 5) == 45) {print "PASS\n"} else {print "FAIL\n"}; | |
if (round (46, 5) == 45) {print "PASS\n"} else {print "FAIL\n"}; | |
if (round (47, 5) == 45) {print "PASS\n"} else {print "FAIL\n"}; | |
if (round (45, 5) == 45) {print "PASS\n"} else {print "FAIL\n"}; | |
if (round (42, 5) == 40) {print "PASS\n"} else {print "FAIL\n"}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment