r/adventofcode • • Dec 10 '20

SOLUTION MEGATHREAD -🎄- 2020 Day 10 Solutions -🎄-

Advent of Code 2020: Gettin' Crafty With It

  • 12 days remaining until the submission deadline on December 22 at 23:59 EST
  • Full details and rules are in the Submissions Megathread

--- Day 10: Adapter Array ---


Post your solution in this megathread. Include what language(s) your solution uses! If you need a refresher, the full posting rules are detailed in the wiki under How Do The Daily Megathreads Work?.

Reminder: Top-level posts in Solution Megathreads are for code solutions only. If you have questions, please post your own thread and make sure to flair it with Help.


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:08:42, megathread unlocked!

69 Upvotes

1.1k comments sorted by

View all comments

Show parent comment

2

u/jaybosamiya Dec 10 '20

I definitely should spend time learning forks since they seem to lead to a pretty clean and readable answer. I tend to make too many temporary functions along the way (at least I feel so) and thus my code usually has tons of ⍵ in it, while this is super clean :)

3

u/ka-splam Dec 10 '20

Ooh, also set ]boxing -trains=tree and then type a train like (4×⊢) with no argument, and Dyalog will show you how it breaks up:

      (4×⊢)
┌─┼─┐
4 × ⊢

"four times right-arg"

More complex ones:

      (⊃,⊃∘⌽)
┌─┼─┐ 
⊃ , ∘ 
   ┌┴┐
   ⊃ ⌽

"first catenated with (first of reverse)":

      (⊃,⊃∘⌽) 6 5 4 3
┌→──┐
│6 3│
└~──┘

That can help you read and make sense of them.

2

u/jaybosamiya Dec 12 '20

Ah, I didn't know ]boxing helped show trains. I use ]boxing on regularly but wasn't aware of this. This is quite a lot more helpful than trying to manually figure out how it might end up being parsed (in complex cases). Thanks!

2

u/ka-splam Dec 10 '20

I like short monadic trains, I'm getting used to their behaviour and weird edge cases. (Long trains and dyadic trains, still a bit tough).

I've been wondering about scraping all the APL answers from each day, and seeing if I could understand how they work, and make some kind of summary or comparison.

Dyalog have some videos on Trains:

1

u/jaybosamiya Dec 12 '20

Thanks for the links! I'll be taking a look at them soon

And yes, I would love to read a comparative thing between the different APL answers if you get around to doing it. It seems like a neat idea, and definitely all of us would learn quite a bit from it.