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!

103 Upvotes

1.5k comments sorted by

View all comments

1

u/teseting Dec 02 '22 edited Dec 02 '22

Python

tot = 0
for l in f:
    c1,c2 = l.strip().split(" ")
    tot += 3\*(ord(c2)-ord("X"))
    if c2 == "Y":
        tot += (ord(c1) - 68)%3+1
    elif c2 == "Z":
    tot += (ord(c1) - 67)%3+1
    else:
        tot += (ord(c1)-69)%3+1

code golf. didn't try too hard to golf. 116 bytes. EDIT 96 bytes

hard code constants and uses clever math

print(sum(map(lambda x:(ord(x[0])+ord(x[1])-1)%3+3*ord(x[1])-263,map(str.split,open("input")))))

1

u/daggerdragon Dec 02 '22

This one is a bit weird... the entire section of code between Python on the first line and code golf. is completely missing on old.reddit.

As in, it doesn't show up at all. It's 100% hidden. I use RES so I can click "source" and I do see your post content in Markdown, but there's spaces in between every line and I think that might be mucking up the Markdown parser on old.reddit.

Could you edit your post to fix the code block formatting so it displays properly (or at least shows up at all) on old.reddit, please?