From cefa509d7618fbf86dc89ff1a4ef48cd23cfdace Mon Sep 17 00:00:00 2001 From: corvettes13 <86648326+corvettes13@users.noreply.github.com> Date: Sun, 11 Jul 2021 02:21:02 -0500 Subject: Create ch-2.pl --- challenge-120/paul-fajman/perl/ch-2.pl | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 challenge-120/paul-fajman/perl/ch-2.pl 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"; -- cgit