Skip to content

Instantly share code, notes, and snippets.

@jimregan
Created May 1, 2016 13:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jimregan/0209f07405ca6e82a8e9ee90fd967f46 to your computer and use it in GitHub Desktop.
Save jimregan/0209f07405ca6e82a8e9ee90fd967f46 to your computer and use it in GitHub Desktop.
#!/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