aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-120/james-smith/perl/ch-2.pl17
1 files changed, 13 insertions, 4 deletions
diff --git a/challenge-120/james-smith/perl/ch-2.pl b/challenge-120/james-smith/perl/ch-2.pl
index 2348c8b946..f34d666f9b 100644
--- a/challenge-120/james-smith/perl/ch-2.pl
+++ b/challenge-120/james-smith/perl/ch-2.pl
@@ -9,14 +9,23 @@ use Benchmark qw(cmpthese timethis);
use Data::Dumper qw(Dumper);
my @TESTS = (
- [ 0, 1 ],
+ [ '03:10', 35 ],
+ [ '04:00', 120 ],
);
-is( my_function($_->[0]), $_->[1] ) foreach @TESTS;
+is( clock_angle($_->[0]), $_->[1] ) foreach @TESTS;
done_testing();
-sub my_function {
- return 1;
+sub clock_angle {
+## The difference is: hr*30+min/2 - min*12
+## Modulo is int based so to avoid issue
+## when min is even we multiply by 2 take
+## modulus and then divide by 2.
+## If value is > 180 then we subtract from
+## 360....
+ my($h,$m) = split /:/,shift;
+ my $a = abs($h*60-$m*11)%720/2;
+ return $a > 180 ? 360-$a : $a;
}