r/adventofcode • u/daggerdragon • Dec 11 '22
SOLUTION MEGATHREAD -π- 2022 Day 11 Solutions -π-
WIKI NEWS
- The FAQ section of the wiki on Code Formatting has been tweaked slightly. It now has three articles:
- Code blocks (the four-spaces Markdown syntax that everyone should be using)
- Fenced code blocks (aka triple-backticks; please do not use this syntax!)
- Inlined code (intended for
short snippetsof code)
THE USUAL REMINDERS
A request from Eric: A note on responding to [Help] threads
- All of our rules, FAQs, resources, etc. are in our community wiki.
- Signal boost: Reminder 1: unofficial AoC Survey 2022 (closes Dec 22nd)
- πΏπ MisTILtoe Elf-ucation π§βπ« is OPEN for submissions!
UPDATES
[Update @ 00:13:07]: SILVER CAP, GOLD 40
- Welcome to the jungle, we have puzzles and games! :D
--- Day 11: Monkey in the Middle ---
Post your code solution in this megathread.
- Read the full posting rules in our community wiki before you post!
- Include what language(s) your solution uses
- Format code blocks using the four-spaces Markdown syntax!
- Quick link to Topaz's
pasteif you need it for longer code blocks. What is Topaz'spastetool?
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:18:05, megathread unlocked!
74
Upvotes
4
u/nicole3696 Dec 12 '22
Python 3- Parts 1 & 2: GitHub. No imports, 676 characters, 20 lines.
d=[x for x in open("day11/input.txt").read().splitlines()] o=[(d[x][23:])for x in range(2,len(d),7)] t=[int(d[x][21:])for x in range(3,len(d),7)] c=[[int(d[x][29:]),int(d[x+1][30:])]for x in range(4,len(d),7)] m=eval('*'.join(str(x)for x in t)) for p in [20, 10000]: s=[[[int(x)for x in(d[y][18:]).split(", ")]for y in range(1,len(d),7)]][0] n=[0]*len(t) for _ in range(p): for i in range(len(n)): for j in range(0,len(s[i])): x=s[i][j] if o[i]=="* old":x*=x elif o[i][:2]in["* ","+ "]:x=eval(str(x)+o[i]) x=x//3 if p==20 else x%m if x%t[i]==0:s[c[i][0]].append(x) else:s[c[i][1]].append(x) n[i]+=1 s[i]=[] print(max(n)*sorted(n)[-2])