Day2 Addition

This commit is contained in:
Thomas Hodnemyr 2022-12-03 19:56:13 +01:00
parent 2adc9853d5
commit b2190a7776
3 changed files with 2534 additions and 0 deletions

2500
day2/input.txt Normal file

File diff suppressed because it is too large Load Diff

16
day2/main1.py Normal file
View File

@ -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)

18
day2/main2.py Normal file
View File

@ -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)