aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbigail <abigail@abigail.be>2021-07-06 15:59:27 +0200
committerAbigail <abigail@abigail.be>2021-07-06 15:59:27 +0200
commitfa23ba004412c1dbd773d897e2c9ba472e77c1dc (patch)
treee21148e440c5a9bef5db81c74e1f7010efb145c2
parent3f178b5765932821cc337637a44dd90e20cadd8e (diff)
downloadperlweeklychallenge-club-fa23ba004412c1dbd773d897e2c9ba472e77c1dc.tar.gz
perlweeklychallenge-club-fa23ba004412c1dbd773d897e2c9ba472e77c1dc.tar.bz2
perlweeklychallenge-club-fa23ba004412c1dbd773d897e2c9ba472e77c1dc.zip
Pascal solution for week 120, part 2
-rw-r--r--challenge-120/abigail/README.md1
-rw-r--r--challenge-120/abigail/pascal/ch-2.p54
2 files changed, 55 insertions, 0 deletions
diff --git a/challenge-120/abigail/README.md b/challenge-120/abigail/README.md
index 25875bb1a1..84e45df14e 100644
--- a/challenge-120/abigail/README.md
+++ b/challenge-120/abigail/README.md
@@ -82,6 +82,7 @@ Output: 120 degree
* [Java](java/ch-2.java)
* [Lua](lua/ch-2.lua)
* [Node.js](node/ch-2.js)
+* [Pascal](pascal/ch-2.p)
* [Perl](perl/ch-2.pl)
* [Python](python/ch-2.py)
* [R](r/ch-2.r)
diff --git a/challenge-120/abigail/pascal/ch-2.p b/challenge-120/abigail/pascal/ch-2.p
new file mode 100644
index 0000000000..0bfa4ab26f
--- /dev/null
+++ b/challenge-120/abigail/pascal/ch-2.p
@@ -0,0 +1,54 @@
+Program ClockAngle;
+
+(* *)
+(* See ../README.md *)
+(* *)
+
+(* *)
+(* Run as: fpc -och-2.out ch-2.p; ./ch-2.out < input-file *)
+(* *)
+
+uses sysutils;
+
+var
+ time: string;
+ hours, minutes, angle: integer;
+
+const
+ DIFF_PER_MINUTE = 11;
+ MIN_PER_HOUR = 60;
+ FULL_CIRCLE = 720;
+
+begin
+ while not eof () do begin
+ (* *)
+ (* Read and parse the input. *)
+ (* *)
+ readln (time);
+ hours := strtoint (leftstr (time, 2));
+ minutes := strtoint (rightstr (time, 2));
+
+ (* *)
+ (* Calculate the angle in half degrees. *)
+ (* *)
+ angle := (DIFF_PER_MINUTE * (hours * MIN_PER_HOUR + minutes)) mod
+ FULL_CIRCLE;
+
+ (* *)
+ (* We want the convex angle. *)
+ (* *)
+ if 2 * angle >= FULL_CIRCLE then begin
+ angle := FULL_CIRCLE - angle;
+ end;
+
+ (* *)
+ (* Output. First we output the integer part. If the *)
+ (* number of half degrees is odd, add a trailing '.5'. *)
+ (* *)
+ write (angle div 2);
+ if angle mod 2 = 1 then begin
+ write ('.5');
+ end;
+ writeln ('');
+ end
+end.