diff options
| -rw-r--r-- | challenge-120/abigail/README.md | 1 | ||||
| -rw-r--r-- | challenge-120/abigail/pascal/ch-2.p | 54 |
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. |
