From 50b492c1bc6255c333e1ce8537ca7bcda050e124 Mon Sep 17 00:00:00 2001 From: TiagoRG <35657250+TiagoRG@users.noreply.github.com> Date: Fri, 2 Dec 2022 18:35:14 +0000 Subject: [PATCH] Added day2 solution --- days1-5/day2/day2.py | 56 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 days1-5/day2/day2.py diff --git a/days1-5/day2/day2.py b/days1-5/day2/day2.py new file mode 100644 index 0000000..8044862 --- /dev/null +++ b/days1-5/day2/day2.py @@ -0,0 +1,56 @@ +with open('inputs/input2.txt', 'r') as f: + # Part 1 + matches = [rpsMatch.split(' ') for rpsMatch in f.read().split('\n')] + score = 0 + for rpsMatch in matches: + if rpsMatch[0] == 'A': + if rpsMatch[1] == 'X': + score += 1 + 3 + elif rpsMatch[1] == 'Y': + score += 2 + 6 + elif rpsMatch[1] == 'Z': + score += 3 + elif rpsMatch[0] == 'B': + if rpsMatch[1] == 'X': + score += 1 + elif rpsMatch[1] == 'Y': + score += 2 + 3 + elif rpsMatch[1] == 'Z': + score += 3 + 6 + elif rpsMatch[0] == 'C': + if rpsMatch[1] == 'X': + score += 1 + 6 + elif rpsMatch[1] == 'Y': + score += 2 + elif rpsMatch[1] == 'Z': + score += 3 + 3 + print(f"Total score: {score}") + + # Part 2 + roundN = 1 + score = 0 + for rpsMatch in matches: + if rpsMatch[0] == 'A': + if rpsMatch[1] == 'X': + score += 3 + elif rpsMatch[1] == 'Y': + score += 1 + 3 + elif rpsMatch[1] == 'Z': + score += 2 + 6 + elif rpsMatch[0] == 'B': + if rpsMatch[1] == 'X': + score += 1 + elif rpsMatch[1] == 'Y': + score += 2 + 3 + elif rpsMatch[1] == 'Z': + score += 3 + 6 + elif rpsMatch[0] == 'C': + if rpsMatch[1] == 'X': + score += 2 + elif rpsMatch[1] == 'Y': + score += 3 + 3 + elif rpsMatch[1] == 'Z': + score += 1 + 6 + print(f"Total score: {score}") + +