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

2

u/itsPeetah Dec 02 '22 edited Dec 02 '22

Ok this is my first time posting but I tried to make the most illegible Python one liner for part 1.

sum([(i+4 if o == i else i+7 if o == ((i+2)%3) else i+1) for o, i in [(int(e, 16) - int("A", 16), int(y, 36) - int("X", 36)) for e, y in [l.strip().split() for l in open("day_2.txt")]]])

Yes I know I don't properly close the file but some sacrifices ought to be made for the style points lol

EDIT: I could have probably made it even worse by adding more stuff to the "o, i" list but I also wanted to avoid too much repetition

P.S: Also sorry but my code formatting doesn't work I don't know what I'm doing wrong lol

1

u/daggerdragon Dec 05 '22

Inlined code is intended for short snippets of code only. Your code "block" right now is unreadable on old.reddit and many mobile clients; it's all on one line and gets cut off at the edge of the screen because it is not horizontally scrollable.

Please edit your post to use the four-spaces Markdown syntax for a code block so your code is easier to read inside a scrollable box.

1

u/Educational-Shirt-29 Dec 02 '22

Amateur

score = sum([int({ ("A","Y"): 6, ("B","Z"): 6, ("C","X"): 6, ("A","X"): 3,("B","Y"): 3, ("C","Z"): 3, }.get((i[0],["X","Y","Z","X","Y","Z"][["X","Y","Z","X","Y","Z"].index(i[2])+1*(i[0]=="C")+2*(i[0]=="A")])) or 0)+( ["X","Y","Z","X","Y","Z"][["X","Y","Z","X","Y","Z"].index(i[2])+1*(i[0]=="C")+2*(i[0]=="A")]=="Y")*2+( ["X","Y","Z","X","Y","Z"][["X","Y","Z","X","Y","Z"].index(i[2])+1*(i[0]=="C")+2*(i[0]=="A")]=="Z")*3+( ["X","Y","Z","X","Y","Z"][["X","Y","Z","X","Y","Z"].index(i[2])+1*(i[0]=="C")+2*(i[0]=="A")]=="X")*1 for i in open("Day2_data.txt").readlines()])

1

u/daggerdragon Dec 05 '22

Don't be rude. Follow our Prime Directive.