diff --git a/2022/Day-02/day02-1.py b/2022/Day-02/day02-1.py new file mode 100644 index 0000000..1a166b5 --- /dev/null +++ b/2022/Day-02/day02-1.py @@ -0,0 +1,44 @@ +#!/usr/bin/python3 + +points = { + 'rock': 1, + 'paper': 2, + 'scissors': 3, + 'lose': 0, + 'draw': 3, + 'win': 6 +} + +shapes = { + 'A': 'rock', + 'B': 'paper', + 'C': 'scissors', + 'X': 'rock', + 'Y': 'paper', + 'Z': 'scissors' +} + +def outcome(myMove, yourMove): + wins = { + 'rock': 'scissors', + 'paper': 'rock', + 'scissors': 'paper' + } + if myMove == yourMove: + return 'draw' + elif theirMove == wins[myMove]: + return 'win' + else: + return 'lose' + +totalScore = 0 + +with open('input.txt', 'r') as inputFile: + for line in inputFile: + moves = line.strip().split(' ') + ourMove = shapes[moves[1]] + theirMove = shapes[moves[0]] + totalScore += points[ourMove] + totalScore += points[outcome(ourMove, theirMove)] + +print(totalScore) diff --git a/2022/Day-02/day02-2.py b/2022/Day-02/day02-2.py new file mode 100644 index 0000000..efd96e6 --- /dev/null +++ b/2022/Day-02/day02-2.py @@ -0,0 +1,48 @@ +#!/usr/bin/python3 + +points = { + 'rock': 1, + 'paper': 2, + 'scissors': 3, + 'lose': 0, + 'draw': 3, + 'win': 6 +} + +shapes = { + 'A': 'rock', + 'B': 'paper', + 'C': 'scissors', +} + +wins = { + 'rock': ['paper', 'scissors'], + 'paper': ['scissors', 'rock'], + 'scissors': ['rock', 'paper'] +} + + +outcomes = { + 'X': 'lose', + 'Y': 'draw', + 'Z': 'win' +} + +totalScore = 0 + +with open('input.txt', 'r') as inputFile: + for line in inputFile: + moves = line.strip().split(' ') + theirMove = shapes[moves[0]] + requiredOutcome = outcomes[moves[1]] + if requiredOutcome == 'win': + requiredMove = wins[theirMove][0] + elif requiredOutcome == 'lose': + requiredMove = wins[theirMove][1] + else: + requiredMove = theirMove + + totalScore += (points[requiredOutcome] + points[requiredMove]) + + +print(totalScore)