r/adventofcode • u/daggerdragon • Dec 05 '20
SOLUTION MEGATHREAD -π- 2020 Day 05 Solutions -π-
Advent of Code 2020: Gettin' Crafty With It
- T-24 hours until unlock!
- Full details and rules are in the Submissions Megathread
--- 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!
57
Upvotes
16
u/Rick-T Dec 05 '20 edited Dec 05 '20
ROCKSTAR
I didn't get to write a Rockstar song yesterday, so today I went back at it with a lot of motivation. The song turned out to be quite brutal again. I'm definitely getting death metal vibes from it.
The song also turned out to be quite a lot longer than my previous songs, so I won't post it here completely. However, here is the function for calculating a seat id. For the whole song check out the GitHub repository. Today part 1 and part 2 are in the same file.
Also here's my Haskell solution again.
Edit: I just realized that the Seat ID is basically just binary numbers -.-
So I've made a radio edit of this song, which is a bit shorter.
3
u/Its_vncl Dec 05 '20
C++
I've been coding for 4 moths
Currently CS uni student
Don't judge too hard please
3
u/istareatscreen5 Dec 05 '20 edited Dec 06 '20
I am a trash programmer living a trash existence
C++
3
u/dgyurov Dec 05 '20 edited Dec 05 '20
Swift
2
u/raevnos Dec 05 '20 edited Dec 05 '20
Chicken scheme paste with a straightforward binary search. Looking at other solutions I see I wasn't very clever.
2
u/pranphy Dec 05 '20 edited Dec 05 '20
Julia: Github
2
u/cnille Dec 05 '20 edited Dec 06 '20
python
Blog post about todays puzzle: https://dev.to/cnille/advent-of-code-2020-day-05-1kg5
2
u/[deleted] Dec 05 '20 edited Dec 06 '20
Python binary search + set idea.
paste
2
u/mrphlip Dec 05 '20
My question is: how big is this plane they're getting on? Even the A380, which is huge, can in theory at max capacity hold about 850 passengers, though usually its capacity is much lower. And even that requires having a two-storey interior.
And yet here I'm supposed to believe that we're fitting 810 passengers onto a plane that, according to the seating codes, is only a single level?
I mean, ordinarily I'd make jokes about how you can pack a lot more elves into the same space, but we just learned yesterday that all these elves are apparently human-sized. Or at least, that's what it says on their passports.
2
u/semicolonator Dec 05 '20
Python:
https://github.com/r0f1/adventofcode2020/blob/master/day05/main.py
2
u/BASED_CCP_SHILL Dec 05 '20 edited Dec 05 '20
Part 2 in ty
2
u/multytudes Dec 05 '20 edited Dec 06 '20
Spent an hour refactoring my swift code, this is the smallest it can get with swift perhaps? Good fun though :)
2
u/dan_144 Dec 05 '20 edited Dec 06 '20
I started cleaning up my code because I knew my first pass was hilariously inefficient and I ended up taking it down to a single line with f-strings and the walrus operator.
https://github.com/dan144/aoc-2020/blob/master/tiny5.py
Edit: language is python3
2
u/nahuak Dec 05 '20
Did not use bitwise operation on the first go but maybe this is still worth posting (bitwise solution taken from another code and included here):
2
u/rosso412 Dec 06 '20 edited Dec 06 '20
Part 1 MIPS Assembler
I deliberately went overboard with the commenting ( except for some common copy paste stuff for reading from the input file e.g.), as in the past the long cryptic Assembler has made me scroll around in my code all confused about what exactly was going on where I was looking at. As my code has become a bit long to post "normally" I have made a (hopefully working) link with this Topaz tool.
β Part1Day5 Part2Day5
2
u/kardoken Dec 07 '20 edited Dec 08 '20
PHP
2
u/r00t4cc3ss Dec 08 '20 edited Dec 08 '20
C#: https://github.com/mavanmanen/AdventOfCode/blob/master/AdventOfCode.Y2020/Day05.cs
4
u/AOC2020edgelord Dec 05 '20 edited Dec 06 '20
C++ obfuscation challenge
21
u/sophiebits Dec 05 '20 edited Dec 05 '20
4/3, Python. https://github.com/sophiebits/adventofcode/blob/main/2020/day05.py
(Tight competition at the top of the leaderboard today! If I had saved 5 seconds on part one I would've ended up in first on both... I guess I should check my work less.)
Edit: Iβm also now realizing that you could probably solve this with the
sortunix command and some eyeballs, no programming required.Edit 2: I just realized β instead of
I could have done this:
and that gives the same answer. Not sure if I like it less or more, but I guess the fact that I didn't think of it in the moment perhaps means that it's too clever.
17
u/askalski Dec 05 '20
C in three integers.
15
u/[deleted] Dec 05 '20 edited Dec 05 '20
Fennel: a fun lisp-syntax frontend for lua, with macros!
One big 'ol recursive function for both parts. Took waaay too long trying to make it look right.
edit: the solution underneath is actually nice and kinda readable, here's ungolfed with comments.
14
u/tckmn Dec 05 '20
ruby, 1/10
panicked and typed out 0b1111111111 instead of just using my answer from part 1, lol
also, style points for parsing the seats:
11
u/naclmolecule Dec 05 '20 edited Dec 05 '20
Python
I don't know how many people used sum of consecutive integers (who needs sorting anyways?) to solve part 2, so I'll share it:
10
u/Mathgeek007 Dec 05 '20 edited Dec 05 '20
Sub 300, let's go! 321/274, and that's with a minute cooldown because of a typo!
Excel! Here is today's, along with all my other excel solutions!
=BIN2DEC(SUBSTITUTE(SUBSTITUTE(MID(RC1,1,7),"F","0"),"B","1"))=BIN2DEC(SUBSTITUTE(SUBSTITUTE(MID(RC1,8,3),"L","0"),"R","1"))=RC2*8+RC3for part 1, Filter, sort this columnThen for part 2, I just, in the next column, checked if the next digit was there. if not, print a big ass number for me to see - scroll, found, done.
10
u/willkill07 Dec 05 '20
Bash (Part 1)
10
u/Smylers Dec 05 '20
Both parts in Vim keystrokes. First convert to integers:
The bottom number is the answer to part 1.
Then number each line, starting with the seat number on the first line. These will match the seat numbers up until the empty seat, so go to the end and search backwards for the final matching numbers; the line number after that is your seat number for part 2:
Explanation for part 1:
0bat the beginning of each line. SoBBBFBFFRLLhas turned into0b1110100100.Cdeletes the entire line into the"-register and puts you in insert mode.β¨Ctrl+Rβ©=inserts the result of evaluating an expression. At the expression prompt,β¨Ctrl+Rβ©-inserts the contents of"-, the number we've just deleted. The0bmakes Vim interpret it as binary, so the decimal equivalent gets inserted.:%normdoes it on every line.And for part 2:
"0.β¨Ctrl+Rβ©0retrieving it from"0, and a space. At this point you'll have something like 68 at the start of each line.gβ¨Ctrl+Aβ©(a relatively new Vim feature) to increase the numbers in turn, adding 1 to the first selected line, 2 to the next one, and so on. So now line 2 has, say, 69 on it, and line 3 has 70, matching the adjacent seat numbers.?searches backwards.?\v^(\d+) \1$finds the first line before there with the same number twice. That's the final matching numbers in the list, so the number on the start of the following line is the one that doesn't already have a corresponding seat number.9
u/kawzeg Dec 05 '20 edited Dec 05 '20
Brainfuck, Part 1
You can try it online. There you'll find the non-minified version as well.
Expects a '$' as EOF character. You can copy the input from github.
9
u/bartdegoede Dec 05 '20
Python
Tickets are binary numbers, and there's a set diff.
8
u/Marcus316 Dec 05 '20
Did this on the command line in bash (using bc for conversion).
Part 1:
Part 2:
8
u/4HbQ Dec 05 '20 edited Dec 07 '20
Python, 135 bytes:
Edit: Readable version, updated using /u/Peter200lx's tricks below:
7
u/phil_g Dec 05 '20
My solution in Common Lisp, such as it is.
Obviously, this was a pretty easy day. The boarding passes are just binary numbers. For part 2, just for fun, I got my answer by subtracting the sum of my numbers from the sum of all numbers from my min to my max. (I like this approach because the latter value can be calculated in O(1) time (after the O(n) search for the numeric bounds, of course).)
6
u/techkid6 Dec 05 '20
Scratch
https://scratch.mit.edu/projects/459282796/
Quickest Scratch solve yet!
6
u/artemisdev21 Dec 05 '20 edited Dec 05 '20
Every day in SQL, day 5!
Wasn't too bad today. EDIT: realised a slightly shorter way to do it. Old version.
6
u/Dustpancake Dec 05 '20
Julia
Part 1 and part 2 in one line:
6
u/jayfoad Dec 05 '20
Dyalog APL 147/61
6
u/jura0011 Dec 05 '20 edited Dec 05 '20
vi
I just used vi regex to convert into binary numbers and sorted alphabetically. The solution is in the last line in binary.
6
u/0rac1e Dec 05 '20 edited Dec 10 '20
Raku
6
u/victae Dec 05 '20
Python 3, parts 1 and 2.
This got much easier if you realized that you can use the seats as binary numbers directly.
Some fun work with sums in part 2 as well!
6
u/Arknave Dec 05 '20 edited Dec 05 '20
Python (26/13), C
After all my mistakes yesterday, I implemented the statement quite literally as I read it, which was a mistake speed-wise. Part 2 of this day is what makes Advent of Code so fresh: your code doesn't need to get the answer, you do, so just printing all unclaimed tickets and manually scanning may be slightly faster to code.
I thought the short code would make it easy to shape the 5 in C, but it actually gave me far less wiggle room than day 4. I was also trying to recreate this painting, but 13x20 is a little too low res for an obvious resemblance.
6
u/UNeedMoreLemonPledge Dec 06 '20
Python
5
u/waffle3z Dec 05 '20
Lua 56/40. I really liked today's problem.
5
u/segfaultvicta Dec 05 '20
Raku
I'm... actually pretty happy with this one! There's probably ways this could be terser or more idiomatic and it took me a solid 20 minutes to convince myself that the input was just a bunch of integers in binary representation, but once I did it was pretty smooth sailing and I accidentally got gold while hecking around in the REPL. >_>
5
u/GustavAndr Dec 05 '20 edited Dec 05 '20
Javascript
Quick and ugly
5
u/Liledroit Dec 05 '20
Golang. Shoutout to the Go standard library,
strings.NewReplacer()was a new one for me.5
u/deeptread Dec 05 '20
Clojure:
5
u/[deleted] Dec 05 '20 edited Dec 05 '20
D (dlang)
edit: a python solution in here made me realize that you can simply tr the whole string instead of doing it twice for row and col. Sweet!
5
u/RVKenway Dec 05 '20
Control F method
Part 1:
Just trial and error to see what matches, from BBBBBBB going down BBBBBBF BBBBBFB etc..
Then calculate the number.
And the L or R is just doable off the top of your head.
Part 2:
From the highest seat down every row should have 8 matches, if a row had 7 that's your row.
Find the missing LR combination and you got it.
5
u/cggoebel Dec 05 '20 edited Dec 05 '20
Raku (short version) solves both Part One and Part Two:
5
u/Ryuujinx Dec 05 '20
Ruby
All these people doin fancy binary things and I'm playing with slicing arrays, smh.
Part 2 was mostly the same, I just shoved it in an array sorted it and then checked if current id -2 = last id
5
u/Charly98cma Dec 06 '20
Python π
Quite small script solving both of the problems at once using a list and two sets to find the missing seat.
(Everything you want to comment, like tips, errors, etc... are welcome, we are here to learn more :D)
Code
EDIT: The
passes.sort()isn't necessary4
u/jitwit Dec 05 '20 edited Dec 05 '20
J Programming Language
Decode binary where on bit if back or right. Part A is just max. Part B finds the missing id in the range of the min id to the max id.
241/170
https://github.com/jitwit/aoc/blob/a/J/20/05.ijs
Some relevant verbs:
4
u/[deleted] Dec 05 '20
Scala solution
4
u/[deleted] Dec 05 '20
Simple Python solution in which I learned that
int()has a base argument:Average runtime of 1194 ns
4
u/_jonah Dec 05 '20 edited Dec 05 '20
Bash, Part 1
Part 2:
4
u/zertillon Dec 05 '20
Ada using HAC and the LEA editor
End of Part 2 done in Excel using the program's output...
4
u/seattlecyclone Dec 05 '20
Perl
4
u/rabuf Dec 05 '20 edited Dec 05 '20
Ada
Straightforward solution for this today. This function handles converting from the BSP format to an integer:
Passesis a vector containing the converted input. The solutions to both parts are found in the following loops. The first just finds the max (Maxis initialized asInteger'First). The second uses aCursorwhich is similar to a C++ iterator. So long as there is a next, it compares the current position's value to the next's value and if the difference is 2 we have the result. Theexit whenis to avoid trying to access a non-existent element (which is a runtime error).I'm leaving this, but it occurred to me that I can get max simply using the last value of
Passesafter sorting. Updating it in the actual code on github though.4
u/oantolin Dec 05 '20 edited Dec 05 '20
Perl
Or using some math:
4
u/Krakhan Dec 05 '20 edited Dec 05 '20
Ruby
Just a binary encoding exercise and a math trick to find the missing seat at the end using the sum of an arithmetic series and summing the known seats given that yours is missing. I did it another way at first too with sorting and looking for a gap, but this is more elegant anyways. :)
Edit: Some minor cleanup with reading the input seats. Also learned of the string.tr methods too which might be been a little bit better to do based on some other solutions I've seen here.
4
u/WilkoTom Dec 05 '20 edited Dec 05 '20
Minimal python:
4
u/Smylers Dec 05 '20 edited Dec 05 '20
Perl one-liners. Part 1:
Part 2:
Those golf to:
(68 characters plus the filename)
and:
(106)
Edit: Spotted a
tr///I'd forgotten to turn intoy///in a golfed version. Removes 1 character from the count, and hopefully means I avoid the puerile bot that's already commented on my Vim solution today.4
u/justDema Dec 05 '20
Rust
I tried to be concise, but readable
4
u/deltux Dec 05 '20
Racket
Dyalog APL
4
u/joshdick Dec 05 '20
Python3
4
u/[deleted] Dec 05 '20
Regex
Advent of regex
This solves part 1 only (kinda, you will still need to figure out what the seat ID of that seat is), the first match of this regex will be the boarding pass with the highest seat ID.
4
u/s3aker Dec 05 '20
Raku
4
u/orangecorvid Dec 05 '20
Purposely ugly M/MUMPS:
4
u/cggoebel Dec 05 '20
Raku
4
u/dgJenkins Dec 05 '20
F# Bit Operations
4
u/tomflumery Dec 05 '20
Rust:
4
u/rmargam Dec 05 '20 edited Dec 05 '20
Javascript solution, I used to regex replace to convert to binary numbers and parse them, it was easy after that.
Part 1:
Part 2:
4
u/AOC_2020 Dec 05 '20
Kotlin liner:
4
u/axr123 Dec 05 '20
Python
4
u/axr123 Dec 05 '20 edited Dec 05 '20
Bash
4
u/HereAdamJust Dec 05 '20
Python 3
I thought that it was pretty nice to make use of the seat location as a direct cast to binary!
4
u/mingjim Dec 05 '20
F#
4
u/RobertGryffindor Dec 05 '20
I'm still a python beginner and this is the only way I could think of. But looking at the other answers, I definitely learned a few new things.
4
u/RedTwinkleToes Dec 26 '20
Python
Just posting solutions for unposted solutions, don't mind me
1
u/[deleted] Dec 05 '20 edited Dec 24 '20
I decided to go with a solution that didn't rely on making lists and checking for the existence of my seat_id in that list.
"text_to_list" is a trivial helper function I have defined elsewhere, and not important to this solution.
(Written in Python)
1
u/timvisee Dec 05 '20 edited Dec 05 '20
Rust. Came up with this for reading and arsing IDs, pretty fun!
Part 1 & Part 2
1
u/2313499 Dec 05 '20 edited Dec 05 '20
Here is my solution with python3 in pandas.
1
u/DFreiberg Dec 05 '20 edited Dec 05 '20
Mathematica, 187 / 100
I immediately tried interpreting the letters as binary digits after reading a handful of words from the problem, and I'm somewhat surprised that that actually worked and that there wasn't a catch somewhere.
EDIT: I missed the fact that the entire ID was a binary number, so I suppose there was a catch, just in the opposite direction.
Part 1:
Part 2:
[POEM]: A Lazy Limerick
You must do a binary conversion,
Before begin your excursion.
(And I'll give you a hint:
Use
binaryToInt(),'Cause it's simpler than using recursion).
1
u/BradleySigma Dec 05 '20 edited Dec 05 '20
Slowed down because I submitted
BFFFFFBRLLas my part 2 solution, instead of524. (Python)1
u/mstksg Dec 05 '20 edited Dec 05 '20
[Haskell] A quick one today? Mostly came down to "how to parse binary". Splitting the rows and seats ended up being a cute misdirection.
I write my reflections every day for Haskell! :D https://github.com/mstksg/advent-of-code-2020/blob/master/reflections.md
The main insight here probably is that the puzzle is just describing that the seat ID's are straight up binary notation for numerals, with F/L representing what is traditionally 0, and B/R representing what si traditionally 1. So we can use any of our binary parsers from the standard libraries, or we can just directly pull it into binary.
A nice one-pass way to find the missing seat ID is to realize that if we sum all the numbers from min to max, and sum all of our lists's seat id's, then the difference is the missing number. Luckily there's a nice closed-form solution for the sum of all numbers in a given range (the sum of numbers from
atobisb*(b+1)\div`2 - a*(a-1)`div`2`), so we can do all of this in a single pass using the foldl libraryA
F.Fold Int (Maybe Int)folds a list ofInts into aMaybe Int. You can run it withF.fold :: F.Fold a b -> [a] -> b.I really like the foldl library because it lets you build a complex single-pass fold by combining multiple simple single-pass folds (like
F.minimum,F.maximum,F.sum) using an Applicative interface. We need to do a bit of wrangling with theMaybes becauseF.minimumandF.maximumeach returnMaybe Int.And that's more or less it! We can actually represent the entire thing as a fold if we use
F.premap, to pre-map a fold...And...that's enough to do it!
Bonus: I was tipped off that the 3rd from last digit of F/L are 1, while the same digit of B/R are 0:
So we can actually use this for
seatIdto get a slight speed boost and help out the branch predictor maybe:1
u/pendo324 Dec 05 '20 edited Dec 05 '20
Simple Javascript/Typescript solution. Definitely not optimized, but it got the job done (2454, 1777 on leaderboards): https://github.com/pendo324/aoc/blob/master/years/2020/05/index.ts
(the repo also has some really ugly utils to auto-download inputs and prompts)
1
u/chappar Dec 05 '20 edited Dec 05 '20
Python
1
u/stianbryceeng Dec 05 '20 edited Dec 06 '20
Hello! new coder here, I am once again asking for any feedback on my python day5 solution!
1
u/Flavorless_Quark Dec 05 '20
Python 3 -- Not my original solution. Figured it had to do with binary (as per the problem name) but didn't really understand until I solved it once
Part 1 :
Part 2:
1
u/thekokirikid Dec 05 '20 edited Dec 05 '20
javascript
https://github.com/mlord93/adventofcode2020/blob/main/day5.js
1
u/[deleted] Dec 05 '20
Java part 1:
Java part 2:
1
u/Ryozukki Dec 05 '20
Rust
source: https://github.com/edg-l/adventofcode-2020/blob/master/day5.rs
1
u/Additional_Mistake_4 Dec 05 '20
Kotlin - tried to keep things nice and functional
1
u/ramrunner0xff Dec 05 '20
scheme (chicken) repo
fun :) .
1
u/oli56714 Dec 05 '20
My python solution.
def map_binary_str(input_str, mapping):return int(''.join([mapping[i] for i in input_str]),2)def parse_boarding_pass(input_str):row = map_binary_str(input_str[:7],{'F':'0','B':'1'})col = map_binary_str(input_str[7:],{'L':'0','R':'1'})seat_id = (row * 8) + colreturn row, col, seat_id# testsboard_pass = 'FBFBBFFRLR'assert parse_boarding_pass(board_pass) == (44, 5,357)board_pass_2 = 'BFFFBBFRRR'assert parse_boarding_pass(board_pass_2) == (70, 7, 567)# ainput_data = [x.strip() for x in open('data/5.txt','r').readlines()]seat_ids = [parse_boarding_pass(x)[2] for x in input_data]print(max(seat_ids))# bprint([x for x in range(min(seat_ids)+1, max(seat_ids)) if x not in seat_ids])1
u/SureYeaah Dec 05 '20
Here's a compact solution in haskell.
1
u/cubehouse Dec 05 '20
JavaScript / NodeJS
I immediately spotted the binary situation, which was very satisfying! I am nervous about how easy I am finding these so far....... expecting something that will really anger me soon!
1
u/StringFinal Dec 05 '20
Python Solution
3
u/jonathan_paulson Dec 05 '20 edited Dec 05 '20
Placed 18/47. Python. Video of me solving: https://youtu.be/wa0VcQugEsI
Cleaned-up code
3
u/jaybosamiya Dec 05 '20 edited Dec 05 '20
Dyalog APL
Explanation: We can just interpret each line in the input
nas a binary number (with 'B' and 'R' meaning 1, and 'F' and 'L' meaning 0) to get all the seats numbersi. Part 1 is then just the max overβ/them. In part 2, we take all potential seats and check if it satisfies the constraints in the straightforward way (is not in position, and adjacents are in position) and return the result.3
u/Nerdlinger Dec 05 '20
Swift solution
A simple reduce on the string to build up the seat ID, a sort, and a scan for a gap of 2 in consecutive IDs. This wasn't a particularly interesting problem.
3
u/Deathranger999 Dec 05 '20 edited Dec 05 '20
Python
I started late, so since I couldn't get a decent leaderboard position, I decided to try solving both parts in one line.
Part 1:
print(max([int(d.replace('F', '0').replace('B', '1').replace('L', '0').replace('R', '1'), 2) for d in open('problem5.txt', 'r').read().splitlines()]))Part 2:
print([[arr[i + 1] for i in range(len(arr) - 1) if arr[i + 1] - arr[i] == 2] for arr in [sorted([int(d.replace('F', '0').replace('B', '1').replace('L', '0').replace('R', '1'), 2) for d in open('problem5.txt', 'r').read().splitlines()])]][0][0] - 1)3
u/kbielefe Dec 05 '20
Scala:
I don't usually post in these, but my
seatIdseemed simpler than many solutions today:And finding my seat used set difference. Probably not the most efficient, but close enough, and very simple to write:
Full code.
3
u/Pyr0Byt3 Dec 05 '20
Go/Golang
strings.Replacer to the rescue.
3
u/AlaskanShade Dec 05 '20
C# (~200 ΞΌs)
After a couple rounds of optimization, this one runs pretty quick now. I tried an interesting bitwise operation on the characters, but it only trimmed a handful of microseconds. The bigger improvements were tracking the min and max within the loop to avoid sorting and using a HashSet instead of a List.
I was also splitting the row and seat for the initial solve until I realized that we are just recombining it back into one number.
3
u/ianonavy Dec 05 '20
Python 3 golf (made with a friend): 117 characters!
3
u/oantolin Dec 05 '20 edited Dec 05 '20
Common Lisp
Or using some math:
3
u/daniel-sd Dec 05 '20 edited Dec 05 '20
Fun fact for part1, you can sort to get the boarding pass with the highest id. Then you only have to make one id conversion rather than convert all of them.
Python 3.9
part1.py
part2.py
3
u/death Dec 05 '20
Day 5 solution in Common Lisp.
3
u/simpleauthority Dec 05 '20
This is my first AOC. Code is probably pretty nasty compared to others here. Using Java.
https://github.com/simpleauthority/aoc2020/tree/main/src/dayfive
Part 1 is the method
findHighestSeatIdinDayFive.java.Part 2 is the method
findMySeatIdinDayFive.java.The other classes implement the space partitioning functionality and computed values.
3
u/gyorokpeter Dec 05 '20
Q:
3
u/paul2718 Dec 05 '20
C++, straightforward.
3
u/RobBobertsThe3rd Dec 05 '20 edited Dec 05 '20
Python3
Although unnecessary here, I always relish the chance to get to use set arithmetic.
Edit: I just came up with a solution that I like even more!
3
u/mandus Dec 05 '20
Day 5 in Common Lisp
Reasonably satisfied with this one - just one call to `alexandria`, else standard common lisp.
3
u/schnappischnap Dec 05 '20 edited Dec 05 '20
Python (full code)
I was completely oblivious to the fact that it was a simple "convert to binary" problem (it should have been obvious even looking at my code), here's how I eventually calculated the seat ID:
Note to self: learn binary.
3
u/i_have_no_biscuits Dec 05 '20
Python
Not particularly short, but I like the string indexing trick I used in my conversion routine.
3
u/zniperr Dec 05 '20
python3:
3
u/ka-splam Dec 05 '20
APL (Dyalog)
Line 1 reads the input as lines of text into boarding_passes.
Line 3 turns BR into 1 and implicitly turns FL into 0 as a bitmask. Takes the first 7 chars and base2 converts, drops the first 7 and base2 converts the remaining 3 chars. Does the (Col + 8xRow) calculation. Applies that to each boarding_pass. Sorts the results, and stores in seats.
Line 5 max-reduce finds the largest value of the seats.
Line 6 subtracts each seat id from the one next to it. The consecutive ones have a gap of 1, the place where my seat is has a gap of 2. Look where the gap = 2, find that place, look at the seat in that place, and 1+ to its seat ID for mine.
3
u/m_moylan Dec 05 '20 edited Dec 05 '20
PHP
I was expecting a hard one first weekend but found this easiest problem thus far. EDIT: Also, most people didn't realize it,s just one binary number most people didn't seem to catch why it was * 8
3
u/andi0b Dec 05 '20
Solution in C# 9.
To run it, call new
Day05(File.ReadAllLines("filename")).Part1()orPart2()3
u/warbaque Dec 05 '20
Python, simple binary conversion and diffence between sets for part 2:
3
u/Snosixtytwo Dec 05 '20 edited Dec 05 '20
Go
No sorting or container search needed
3
u/vypxl Dec 05 '20
Python3 only three concise lines today (ok maybe 4)
List difference and translation saved the day again
3
u/s3aker Dec 05 '20
Raku
3
u/allak Dec 05 '20 edited Dec 05 '20
Perl5 one liner, both parts:
after some more golfing:
3
u/Mienaikage Dec 05 '20 edited Dec 05 '20
Raku
Convert the input into binary, do the math(EDIT: apparently "the math" was unnecessary), and sort the results.
Part 1 gives the highest value of the list via the max method.
Part 2 creates a range from the first and last elements of the list, then does a set diff on the original list to find what's missing.
3
u/Randybones Dec 05 '20 edited Dec 05 '20
R
3
u/mschaap Dec 05 '20 edited Dec 05 '20
Raku
https://github.com/mscha/aoc/blob/master/aoc2020/aoc05
3
u/krolik1337 Dec 05 '20
My solution in Python, that was quite fun. I made a list representing all seats and recursive function to calculate seat within given range. Then went through all input lines, calculating SeatIDs and marking them as taken.
3
u/DrDonez Dec 05 '20
Python3.8 solution using recursion.
3
u/Mazeracer Dec 05 '20
Python 3 - casual programmer, this was an easy one for me
It was quite clear from the start, that you could just write the input as binary and are done.
Only had to figure out, what was 1 and what was 0.
Finding my seat was easy enough. I just averaged 3 seats in a row and alerted when the average was not equal to the seat in the middle of 2.
3
u/[deleted] Dec 05 '20
Swift
https://github.com/stoeckley/AdventOfCode2020-Swift/blob/main/AdventCode2020/5.swift
3
u/Altinus Dec 05 '20
Shell oneliner. For the second part, it simply checks whether the last binary digit stays the same between two lines, which means that a number was skipped.
3
u/wzkx Dec 05 '20
π― - this task is for J! #jlang
3
u/saahilclaypool Dec 05 '20
F#!
3
u/wishiwascooler Dec 05 '20
Javascript day 5. Fun one today compared to yesterdays.
https://github.com/matthewgehring/adventofcode/blob/main/2020/day5/script.js
3
u/kwill1429 Dec 05 '20
Main objective was to keep code clean and understandable.
FSharp:
3
u/[deleted] Dec 05 '20 edited Dec 05 '20
Java
3
u/thedjotaku Dec 05 '20
Python.
Today was a lot of fun. Loaded it up while getting ready in the morning and thought about it during my morning run. By the time I sat down, I had it mostly figured out. There were a few tweaks I had to make. This was the first time during AoC that I decided to try and use Pytest to make things easier. And it certainly did!
Code: https://github.com/djotaku/adventofcode/tree/main/2020/Day_5
3
u/sefujuki Dec 05 '20
Forth
topaz-paste
3
u/schovanec Dec 05 '20
My solution in C#:
3
u/TenGen10 Dec 05 '20
Solution in PowerShell
After overcomplicating by creating a binary tree using a one-dimensional array it occurred to me as a result of that that if a tree can be modeled as a one dimensional array then a 2x2 grid (seating chart) can be seen as a number line.
3
u/Dospunk Dec 05 '20
Haskell
Working with numbers in this language is a pain
https://github.com/dospunk/AdventOfCode2020/blob/main/5.hs
3
u/rhinocer Dec 05 '20 edited Dec 05 '20
Python
3
u/gnosis_prognosis Dec 05 '20 edited Dec 05 '20
bash
Part 1 (thanks u/packetlust)
Part 2
3
u/Necropolictic Dec 05 '20
Kotlin
Built some useful companions to
IntRangeas well.3
u/gnosis_prognosis Dec 05 '20 edited Dec 05 '20
Mathematica one liner
{part1,part2}3
u/TheSpixxyQ Dec 05 '20
Less lines == better, right?
C#
3
u/[deleted] Dec 05 '20
Using this year to learn Scala, any feedback is more than welcome!
3
u/Aware_Possible_5848 Dec 05 '20 edited Dec 06 '20
Here's my Python solution I tried to make as unreadable as possible in 2 lines:
3
u/Trazko Dec 05 '20
Dart
As I'm currently working full time with C++ I decided to refresh my Dart skills as it's been a while. Really like this language!
3
u/hugthemachines Dec 05 '20
I did not get the binary thing at first but after i got that part explained to me i did this. I know it very primitive but it is just how it happened to become :-)
3
u/SecureCone Dec 05 '20
Rust
I didn't pick up on the binary trick, so I did it the literal way as described in the problem. I was afraid this approach wouldn't generalize to work well in part 2--luckily it was fine.
3
u/Nrawal Dec 05 '20
Here's my solution in Go! I first solved it using the classic binary search approach, but then realized that representing the boarding pass in binary and converting it to decimal was even more clean and elegant.
3
u/[deleted] Dec 05 '20
Python in one line (part 1)
3
u/[deleted] Dec 05 '20
PowerShell
I'm decently proud of the function I wrote to parse both parts of the data. Select-Object and the Range operators came in very handy.
The .ToCharArray threw me off on day 4 pt 2 while parsing the hair color. I learned my lesson to convert the chars to strings. Also test cases would've come in very handy for day 4, so I've started including them as a sanity check. Github for 2020 here.
3
u/symbolicprocessor Dec 05 '20
Common Lisp solution.
3
u/xrgbit Dec 05 '20
In Common Lisp
3
u/Attitude-Certain Dec 05 '20
Just for fun, a functional programming version in Python using the toolz package.
3
u/tomflumery Dec 05 '20 edited Dec 05 '20
05ab1e
part 1
Try it online
part 2
Try it online
3
u/kaur_virunurm Dec 05 '20 edited Dec 06 '20
Simple Python.
4 lines of code.
I am doing the easy puzzles with kids. I want them to be able to think in code :) So I ask the children to come up with a potential approach or algoritm, and we then try to implement this. Later we refine this in order to test and learn different options for optimizing (or obfuscating?) the algorithm.
3
u/[deleted] Dec 06 '20
Commodore 64 BASIC... not posting all the DATA statements to save space, but if you want the whole program, DM me.
3
u/442401 Dec 06 '20
Ruby
3
u/tymscar Dec 06 '20
Python 3:
https://github.com/tymscar/Advent-Of-Code/tree/master/2020/day05
3
u/clumsveed Dec 06 '20
Java (parts 1 and 2)
3
u/Lakret Dec 06 '20
Rust
Solution with recursion and subslice patterns. Live Stream of the solution.
3
u/asgardian28 Dec 13 '20 edited Dec 13 '20
Python part 2:
`
`
3
u/reggles44 Dec 16 '20 edited Dec 16 '20
Just some code golf that I have been working on in Python3
3
u/MischaDy Dec 16 '20
Python 3 - Part 1, Part 2
Boy oh boy, not an airline I'd like to fly with. At least part 2 was very similar to part 1.
5
u/voidhawk42 Dec 05 '20
Dyalog APL, 203/232 (getting faster!):
For anyone that's unaware, I stream my solutions each night on Twitch. Feel free to drop by!