rj1
about | log | files | refs
commit 5771e96e1b7d357820ce8a1bec42a5a6a2901db2
parent 9bca3e1ae75543529c96bfbad4cd29e0c7b86314
author: rj1 <[email protected]>
date:   Sat,  3 Dec 2022 00:00:30 -0600

day 3 solution

Diffstat:
A2022/03/solution.py | 26++++++++++++++++++++++++++
1 file changed, 26 insertions(+), 0 deletions(-)

diff --git a/2022/03/solution.py b/2022/03/solution.py @@ -0,0 +1,26 @@ +import os +import string + +base_dir = os.path.realpath(os.path.dirname(__file__)) +with open(base_dir + "/input.txt", "r") as file: + input = file.read().rstrip() + +lines = input.split("\n") +chars = string.ascii_letters + +total = 0 +for line in lines: + n = len(line) + for c in chars: + if (c in line[: n // 2]) and (c in line[n // 2 :]): + total += chars.index(c) + 1 + +print(total) + +total = 0 +for i in range(len(lines) // 3): + for c in chars: + if c in lines[3 * i] and c in lines[3 * i + 1] and c in lines[3 * i + 2]: + total += chars.index(c) + 1 + +print(total)