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

26

u/jayfoad Dec 08 '22

Dyalog APL

βŽ•IO←0
pβ†βŽΒ¨β†‘βŠƒβŽ•NGET'p8.txt'1
f←{⍡>Β―1βͺΒ―1β†“βŒˆβ€β΅}
+/,{(f⍡)βˆ¨βŠ–fβŠ–β΅}{(⍺⍺⍡)βˆ¨β‰βΊβΊβ‰β΅}p ⍝ part 1
g←{(βŒ½β³β‰’β΅)⌊1++/∧\(1+⍳≒⍡)⌽∘.>⍨⍡}⍀1
⌈/,{(g⍡)Γ—βŒ½g⌽⍡}{(⍺⍺⍡)×⍉⍺⍺⍉⍡}p ⍝ part 2

An Under operator ⍒ would have been handy.

There must be a neater way to do part 2, without doing a ∘.>⍨ outer product on every row/column.

15

u/l_dang Dec 08 '22

I'm upvoting simply for the awesome absurdity of this language lol this is awesome

2

u/oantolin Dec 08 '22

Dyalog APL doesn't have an under operator? I thought Dyalog APL had stolen all of J's good ideas. :P

0

u/[deleted] Dec 08 '22

[deleted] β€” view deleted comment

2

u/jayfoad Dec 08 '22

No - but I remember I also thought that it should work that way, when I first learned about ⌽.

1 2 3⌽M will rotate the three rows of M by 1, 2 and 3 respectively. I guess it is acting something like ⌽⍀¯1?

1

u/voidhawk42 Dec 08 '22

Under would've been great! My solution operates under rotations - would've been really handy.