day 2 python

master
Felix Pankratz 2 years ago
parent 89f9273f89
commit ece611baf6

@ -0,0 +1,30 @@
#!/usr/bin/env python3
INPUT_FILE = 'input'
# x = rock
# y = paper
# z = scissor
# lose = 0
# draw = 3
# win = 6
def main():
score = 0
content = map(str.strip, open(INPUT_FILE, 'r').readlines())
for line in content:
enemy_move, my_move = map(ord, line.split(' '))
enemy_move -= 64
my_move -= 24 + 63
print(enemy_move, my_move)
if my_move == enemy_move + 1 or (my_move == 1 and enemy_move == 3):
score += 6
elif my_move == enemy_move:
score += 3
score += my_move
print(score)
if __name__ == '__main__':
main()

@ -0,0 +1,37 @@
#!/usr/bin/env python3
INPUT_FILE = 'input'
# rock = 1
# paper = 2
# scissor = 3
# lose = X
# draw = Y
# win = Z
def main():
score = 0
content = map(str.strip, open(INPUT_FILE, 'r').readlines())
for line in content:
enemy_move, game_result = line.split(' ')
enemy_move = ord(enemy_move)-64
if game_result == 'X':
# lose
my_move = enemy_move - 1 or 3
elif game_result == 'Y':
# draw
my_move = enemy_move
elif game_result == 'Z':
# win
my_move = ( enemy_move % 3 ) + 1
if my_move == enemy_move + 1 or (my_move == 1 and enemy_move == 3):
score += 6
elif my_move == enemy_move:
score += 3
score += my_move
print(score)
if __name__ == '__main__':
main()

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save