aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordrbaggy <js5@sanger.ac.uk>2021-07-05 11:54:25 +0100
committerdrbaggy <js5@sanger.ac.uk>2021-07-05 11:54:25 +0100
commit7ecb9c24d7c69747e9dee7bd0e6d3a4d25fff466 (patch)
tree5735144d57bb3c022127d76c428d3e4dd7ccdbd1
parent7724f41709fab6db7dcd3ed4343dab68d72a734b (diff)
downloadperlweeklychallenge-club-7ecb9c24d7c69747e9dee7bd0e6d3a4d25fff466.tar.gz
perlweeklychallenge-club-7ecb9c24d7c69747e9dee7bd0e6d3a4d25fff466.tar.bz2
perlweeklychallenge-club-7ecb9c24d7c69747e9dee7bd0e6d3a4d25fff466.zip
clock angle added resolving issue of fractional angles
-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;
}