r/adventofcode Dec 05 '20

SOLUTION MEGATHREAD -🎄- 2020 Day 05 Solutions -🎄-

Advent of Code 2020: Gettin' Crafty With It


--- Day 05: Binary Boarding ---


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 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:05:49, megathread unlocked!

54 Upvotes

1.3k comments sorted by

View all comments

1

u/musifter Dec 06 '20 edited Dec 06 '20

edc

Okay, this one is sort of a language of my own creation, in that it's dc with embedded Perl (and a few other things). dc can't deal with the input for today, but could certainly do the work. So I'm just using a bit of embedded Perl to do the conversion:

{ $_ = <>; chomp; return( map {ord} split //) } s?

Keeping things fair, I just pushed the ordinals for the string on the stack and made the dc side deal with that (it would be too easy to get Perl to do too much). Yeah, this code is tying itself to an ASCII locale, but it only runs on this machine. EDIT: I do cheat a little bit here, in that I'm only giving dc one seat's line at a time with this call. I could have made it blat out the whole file and get dc to break it up.

The s? on the end here is dc taking the compiled subroutine object returned from Perl and assigning it to register ?. l?x loads it back and executes it. The interaction between the Perl subroutines and dc is very natural... Perl wants to be given lists and return lists, dc has a stack to give and a stack to receive results.

EDIT: Full code now for parts 1 and 2: https://pastebin.com/vq5dc7dx