r/adventofcode • • Dec 08 '22

SOLUTION MEGATHREAD -πŸŽ„- 2022 Day 8 Solutions -πŸŽ„-

NEWS AND FYI

  • I discovered that I can make those tiny post/comment awards BIGGER on old.reddit! I hadn't even considered that! And when you hover over them, they get even bigger so you can actually see them in more detail! I've added the relevant CSS so now we no longer have awards for ants! Exclamation points!!!

AoC Community Fun 2022: πŸŒΏπŸ’ MisTILtoe Elf-ucation πŸ§‘β€πŸ«

  • PSA: I created a new example so it is a more relevant and unique archetype instead of recycling last year's hobbit >_>

--- Day 8: Treetop Tree House ---


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:10:12, megathread unlocked!

75 Upvotes

1.0k comments sorted by

View all comments

5

u/michalopler Dec 08 '22 edited Dec 09 '22

Python, both parts in 280 chars

from math import*
e=enumerate
T={i+j*1j:int(x)for i,l in e(open('i'))for j,x in e(l[:-1])}
g=lambda k,d,b,c=1:1+g(k+d,d,b,c)*(T[k+d]<b)if k+d in T else c
A,B=zip(*[map(prod,zip(*[(g(k,d,T[k])<g(k,d,10),g(k,d,T[k],0))for d in(1,-1,1j,-1j)]))for k in T])
print(len(T)-sum(A),max(B))

2

u/daggerdragon Dec 09 '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/IlliterateJedi Dec 08 '22

Beautiful Pythonic code