Browse Source

Day 2

master
Noëlle 1 year ago
parent
commit
3a95286329
No known key found for this signature in database
3 changed files with 2596 additions and 0 deletions
  1. 43
    0
      day2-1.py
  2. 53
    0
      day2-2.py
  3. 2500
    0
      input2.txt

+ 43
- 0
day2-1.py View File

@@ -0,0 +1,43 @@
# https://adventofcode.com/2022/day/2

MOVE_SCORES = {
"A": 1,
"B": 2,
"C": 3,
"X": 1,
"Y": 2,
"Z": 3
}

MOVE_BEATS = {
"X": "C",
"Y": "A",
"Z": "B"
}

MOVE_EQUALS = {
"X": "A",
"Y": "B",
"Z": "C"
}

def main():
with open("input2.txt", "r") as file:
moves = [line.strip() for line in file.readlines()]

# moves = [(x, y) for line in inlines for x, y in line.split(" ")]

scores = []
for move in moves:
(theirs, mine) = move.split(" ")
cur_score = MOVE_SCORES[mine]
if MOVE_BEATS[mine] == theirs:
cur_score += 6
elif MOVE_EQUALS[mine] == theirs:
cur_score += 3
scores.append(cur_score)

print(sum(scores))

if __name__ == "__main__":
main()

+ 53
- 0
day2-2.py View File

@@ -0,0 +1,53 @@
# https://adventofcode.com/2022/day/2

MOVE_SCORES = {
"A": 1,
"B": 2,
"C": 3,
"X": 0,
"Y": 3,
"Z": 6
}

MOVE_BEATS = {
"A": "C",
"B": "A",
"C": "B"
}

MOVE_LOSES = {
"A": "B",
"B": "C",
"C": "A"
}

def main():
with open("input2.txt", "r") as file:
moves = [line.strip() for line in file.readlines()]

# moves = [(x, y) for line in inlines for x, y in line.split(" ")]

scores = []
for move in moves:
(theirs, mine) = move.split(" ")
cur_score = MOVE_SCORES[mine]

if mine == "X":
# Have to lose.
# Add the score of the move that their move beats.
cur_score += MOVE_SCORES[MOVE_BEATS[theirs]]
elif mine == "Y":
# Have to tie.
# Add the score of the move that they made.
cur_score += MOVE_SCORES[theirs]
elif mine == "Z":
# Have to win.
# Add the score of the move that theirs loses to.
cur_score += MOVE_SCORES[MOVE_LOSES[theirs]]
scores.append(cur_score)

print(sum(scores))

if __name__ == "__main__":
main()

+ 2500
- 0
input2.txt
File diff suppressed because it is too large
View File


Loading…
Cancel
Save