From fb62180005f55612297b8a97d061ace97e2d2dc7 Mon Sep 17 00:00:00 2001 From: Abigail Date: Thu, 18 Feb 2021 18:37:20 +0100 Subject: Python solution for week 100, part 1 --- challenge-100/abigail/python/ch-1.py | 50 ++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 challenge-100/abigail/python/ch-1.py (limited to 'challenge-100/abigail/python') diff --git a/challenge-100/abigail/python/ch-1.py b/challenge-100/abigail/python/ch-1.py new file mode 100644 index 0000000000..c236191663 --- /dev/null +++ b/challenge-100/abigail/python/ch-1.py @@ -0,0 +1,50 @@ +#!/opt/local/bin/python + +# +# See ../README.md +# + +# +# Run as python ch-1.py < input-file +# + +import fileinput +import re + + +for line in fileinput . input (): + # + # Parse input + # + hour, minute, ampm = re . compile (r'([0-9]+):([0-9]+)\s*([ap]?)') \ + . match (line) \ + . groups () + # + # Make sure we have integers + # + hour = int (hour) + minute = int (minute) + + # + # Calculate new AM/PM marker + # + new_ampm = "" + if ampm == "": + if hour >= 12: + new_ampm = "pm" + else: + new_ampm = "am" + + # + # Calculate new hour + # + hour = hour % 12 + if ampm == "" and hour == 0: + hour = 12 + if ampm == "p": + hour = hour + 12 + + # + # Print result + # + print ("{:02d}:{:02d}{:s}" . format (hour, minute, new_ampm)) -- cgit From 66a910dbb2a803dc8e785b6564d4f52eb4e4f560 Mon Sep 17 00:00:00 2001 From: Abigail Date: Fri, 19 Feb 2021 01:16:20 +0100 Subject: Python solution for week 100, part 2 --- challenge-100/abigail/python/ch-2.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 challenge-100/abigail/python/ch-2.py (limited to 'challenge-100/abigail/python') diff --git a/challenge-100/abigail/python/ch-2.py b/challenge-100/abigail/python/ch-2.py new file mode 100644 index 0000000000..b237f83d16 --- /dev/null +++ b/challenge-100/abigail/python/ch-2.py @@ -0,0 +1,36 @@ +#!/opt/local/bin/python + +# +# See ../README.md +# + +# +# Run as python ch-2.py < input-file +# + +import fileinput +import re + +numbers = [] + +# +# Read in the data +# +for line in fileinput . input (): + numbers . append (list (map (lambda x: int (x), + re . compile (r'\s+') + . split (line . strip ())))) + + +# +# Calculate the minimum path, bottom to top +# +for x in range (len (numbers) - 2, -1, -1): + for y in range (0, len (numbers [x])): + numbers [x] [y] = numbers [x] [y] + min (numbers [x + 1] [y], + numbers [x + 1] [y + 1]) + +# +# Print result +# +print (numbers [0] [0]) -- cgit