Advertisement
SimonJkAdamek

AOC day 2

Dec 2nd, 2022 (edited)
925
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.99 KB | Source Code | 0 0
  1. #/usr/bin/env python3
  2.  
  3. score=0
  4.  
  5. win=['B Z','C X','A Y']
  6. draw=['A X','B Y','C Z']
  7.  
  8. with open("input.txt") as file:
  9.     for line in file:
  10.         line=line.strip()
  11.         if line in draw:
  12.             score += ((ord(line.split()[1])-87)+3)                  #ord('X')=88
  13.         elif line in win:
  14.             score += ((ord(line.split()[1])-87)+6)
  15.         else:
  16.             score += (ord(line.split()[1])-87)
  17. print("Part one: ", score)
  18.  
  19. ###############################################################################################
  20.  
  21. score=0
  22.  
  23. lost=['Z', 'X', 'Y']               
  24. win=['Y', 'Z', 'X']
  25. draw=['X','Y','Z']
  26.  
  27. with open("input.txt") as file:
  28.     for line in file:
  29.         text=line.split()
  30.         index=(ord(text[0])-65)             #A - index 0; B - 1; C - 2
  31.         if text[1]=='X':
  32.             score += (ord(lost[index])-87)
  33.         elif text[1]=='Y':
  34.             score += ((ord(draw[index])-87)+3)
  35.         elif text[1]=='Z':
  36.             score += ((ord(win[index])-87)+6)
  37. print("Part two:", score)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement