diff options
| author | corvettes13 <86648326+corvettes13@users.noreply.github.com> | 2021-07-11 02:21:02 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-07-11 02:21:02 -0500 |
| commit | cefa509d7618fbf86dc89ff1a4ef48cd23cfdace (patch) | |
| tree | ed4614996f4ad5992ad088b60bf414e497777651 /challenge-120 | |
| parent | 091011ae56b19db7de27d84018d2c1cb015e3b4e (diff) | |
| download | perlweeklychallenge-club-cefa509d7618fbf86dc89ff1a4ef48cd23cfdace.tar.gz perlweeklychallenge-club-cefa509d7618fbf86dc89ff1a4ef48cd23cfdace.tar.bz2 perlweeklychallenge-club-cefa509d7618fbf86dc89ff1a4ef48cd23cfdace.zip | |
Create ch-2.pl
Diffstat (limited to 'challenge-120')
| -rw-r--r-- | challenge-120/paul-fajman/perl/ch-2.pl | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/challenge-120/paul-fajman/perl/ch-2.pl b/challenge-120/paul-fajman/perl/ch-2.pl new file mode 100644 index 0000000000..1479bea605 --- /dev/null +++ b/challenge-120/paul-fajman/perl/ch-2.pl @@ -0,0 +1,30 @@ +#!/usr/bin/perl + +# Weekly Challenge 120 Task #2 +# You are given time $T in the format hh:mm. +# Write a script to find the smaller angle formed by the hands of an analog clock at a given time. + +use strict; +use warnings; + +my $input = $ARGV[0]; +my $output; +my $angle; +my @hand; + +my @time = split(':',$input); + +$hand[0]=30*$time[0]+($time[1]/60*30); # Calculate hour hand position. +$hand[1]=$time[1]/60*360; # Calculate minute hand move +$angle = abs($hand[0] - $hand[1]); # Difference between angles + +# We want the smallest of the angles. It must be less than or equal to 180. +if ($angle <= 180) { + $output = $angle; +} +else { + $output = abs(360-$angle); +} + +print "Input: \$T = $input\n"; +print "Output: $output\n"; |
