From 78c841faea1060a3b7ea63a4316e461e490d275e Mon Sep 17 00:00:00 2001 From: Abigail Date: Mon, 5 Jul 2021 14:38:06 +0200 Subject: Solutions in 15 languages for week 120, part 1. This is basically the same as last weeks challenge... --- challenge-120/abigail/python/ch-1.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 challenge-120/abigail/python/ch-1.py (limited to 'challenge-120/abigail/python') diff --git a/challenge-120/abigail/python/ch-1.py b/challenge-120/abigail/python/ch-1.py new file mode 100644 index 0000000000..510ce33d10 --- /dev/null +++ b/challenge-120/abigail/python/ch-1.py @@ -0,0 +1,16 @@ +#!/opt/local/bin/python + +# +# See ../README.md +# + +# +# Run as: python ch-1.py < input-file +# + +import fileinput + +for line in fileinput . input (): + num = int (line) + print ( (num & 0x55) << 1 + | (num & 0xAA) >> 1) -- cgit From 0242bf8e30c825fb37e1a19fb70e8d8b6a47957f Mon Sep 17 00:00:00 2001 From: Abigail Date: Mon, 5 Jul 2021 18:40:41 +0200 Subject: Solutions in 14 languages for week 120, part 2 --- challenge-120/abigail/python/ch-2.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 challenge-120/abigail/python/ch-2.py (limited to 'challenge-120/abigail/python') diff --git a/challenge-120/abigail/python/ch-2.py b/challenge-120/abigail/python/ch-2.py new file mode 100644 index 0000000000..5c01644600 --- /dev/null +++ b/challenge-120/abigail/python/ch-2.py @@ -0,0 +1,27 @@ +#!/opt/local/bin/python + +# +# See ../README.md +# + +# +# Run as: python ch-2.py < input-file +# + +import fileinput + +DIFF_PER_MINUTE = 11 +MIN_PER_HOUR = 60 +FULL_CIRCLE = 720 + +for line in fileinput . input (): + hours, minutes = line . strip () . split (":") + angle = (DIFF_PER_MINUTE * (int (hours) * MIN_PER_HOUR + int (minutes))) \ + % FULL_CIRCLE + if 2 * angle >= FULL_CIRCLE: + angle = FULL_CIRCLE - angle + + print ("{}" . format (int (angle / 2)), end = '') + if angle % 2: + print (".5", end = '') + print ("") -- cgit