Completed day 2
This commit is contained in:
44
2022/Day-02/day02-1.py
Normal file
44
2022/Day-02/day02-1.py
Normal file
@@ -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)
|
48
2022/Day-02/day02-2.py
Normal file
48
2022/Day-02/day02-2.py
Normal file
@@ -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)
|
Reference in New Issue
Block a user