Day2 Addition
This commit is contained in:
parent
2adc9853d5
commit
b2190a7776
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,16 @@
|
||||||
|
with open("day2\input.txt") as f:
|
||||||
|
data = f.readlines()
|
||||||
|
# Pad Rock Paper Scissors
|
||||||
|
opponent_hand = ["A","B","C"]
|
||||||
|
my_hand = ["X","Y","Z"]
|
||||||
|
total_sum = 0
|
||||||
|
for line in data:
|
||||||
|
my_score = my_hand.index(line[2])+1
|
||||||
|
his_score = opponent_hand.index(line[0])+1
|
||||||
|
if (my_score == 1 and his_score == 3) or (his_score == my_score-1):
|
||||||
|
total_sum += 6 #Victory
|
||||||
|
if my_score == his_score:
|
||||||
|
print("Draw")
|
||||||
|
my_score += 3
|
||||||
|
total_sum += my_score
|
||||||
|
print(total_sum)
|
|
@ -0,0 +1,18 @@
|
||||||
|
with open("day2\input.txt") as f:
|
||||||
|
data = f.readlines()
|
||||||
|
# Rock Paper Scissors
|
||||||
|
opponent_hand = ["A","B","C"]
|
||||||
|
win_hand = ["B","C","A"]
|
||||||
|
loss_hand = ["C","A","B"]
|
||||||
|
outcome = ["X","Y","Z"]
|
||||||
|
# Loose Draw Win
|
||||||
|
total_sum = 0
|
||||||
|
for line in data:
|
||||||
|
his_hand = opponent_hand.index(line[0])
|
||||||
|
if outcome.index(line[2]) == 0: #Loss
|
||||||
|
total_sum += opponent_hand.index(loss_hand[his_hand])+1
|
||||||
|
if outcome.index(line[2]) == 1: #Draw
|
||||||
|
total_sum += 4 + his_hand
|
||||||
|
if outcome.index(line[2]) == 2: #Loss
|
||||||
|
total_sum += 6 + opponent_hand.index(win_hand[his_hand])+1
|
||||||
|
print(total_sum)
|
Loading…
Reference in New Issue