From 2829d545574b26553cc3d869d8709adf634cb762 Mon Sep 17 00:00:00 2001 From: Lachlan Meyer Date: Wed, 25 Dec 2024 23:44:34 +1100 Subject: [PATCH] 25-1 --- 2024/25/25-1.py | 57 +++++++++++++++++++++++++++++++++++++++++++ 2024/25/testinput.txt | 39 +++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 2024/25/25-1.py create mode 100644 2024/25/testinput.txt diff --git a/2024/25/25-1.py b/2024/25/25-1.py new file mode 100644 index 0000000..cee1f09 --- /dev/null +++ b/2024/25/25-1.py @@ -0,0 +1,57 @@ + +locks = [] +keys = [] + +total = 0 + +def convertKeyToLock(heights): + for i, result in enumerate(heights): + heights[i] = 6 - result + + return heights + +def testPins(key, lock): + for i, bump in enumerate(key): + if bump + lock[i] >= 6: + return False + return True + +def testKeysInLocks(): + global total + for key in keys: + for lock in locks: + if testPins(key, lock) is True: + total += 1 + +with open('2024/25/input.txt') as f: + current = [] + for i, line in enumerate(f): + line = line.strip() + + if len(line) == 0: + if isLock is True: + locks.append(current) + else: + keys.append(current) + + print(current) + continue + + if i % 8 == 0: + current = [-1] * 5 + isLock = False if '.' in line else True + + for j, char in enumerate(line): + if char == '#': + current[j] += 1 + + if isLock is True: + locks.append(current) + else: + keys.append(current) + + testKeysInLocks() + print(total) + + + \ No newline at end of file diff --git a/2024/25/testinput.txt b/2024/25/testinput.txt new file mode 100644 index 0000000..a53fe9b --- /dev/null +++ b/2024/25/testinput.txt @@ -0,0 +1,39 @@ +##### +.#### +.#### +.#### +.#.#. +.#... +..... + +##### +##.## +.#.## +...## +...#. +...#. +..... + +..... +#.... +#.... +#...# +#.#.# +#.### +##### + +..... +..... +#.#.. +###.. +###.# +###.# +##### + +..... +..... +..... +#.... +#.#.. +#.#.# +##### \ No newline at end of file