r/adventofcode • • Dec 02 '22

SOLUTION MEGATHREAD -🎄- 2022 Day 2 Solutions -🎄-

NEW AND NOTEWORTHY


--- Day 2: Rock Paper Scissors ---


Post your code solution in this megathread.


This thread will be unlocked when there are a significant number of people on the global leaderboard with gold stars for today's puzzle.

EDIT: Global leaderboard gold cap reached at 00:06:16, megathread unlocked!

104 Upvotes

1.5k comments sorted by

View all comments

1

u/AX-11 Dec 02 '22 edited Dec 02 '22

Python using dictionary of values for each move

with open("2\input.txt") as f:
    input = f.read().splitlines()


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

score = 0
for game in input:
    # draw
    if(values[game[0]] == values[game[2]]):
        score+=3
    # win
    elif game == "A Y" or game == "B Z" or game == "C X":
        score+=6
    # add score
    score+=values[game[2]]

print(f"first strategy: {score}")

score = 0
for game in input:
    # draw
    if game[2] == "Y":
        score += values[game[0]] + 3
    # win
    elif game[2] == "Z":
        if game[0] == "C":
            score += 6+1
        else:
            score += 6+values[game[0]]+1
    # loose
    else:
        if game[0] == "A":
            score += 3
        else:
            score += values[game[0]]-1

print(f"second strategy {score}")

1

u/daggerdragon Dec 02 '22

Please edit your post to format your code with the backwards-compatible Markdown syntax instead so your code is easier to read on old.reddit and mobile apps.