And so closes out the first week. Can you believe we're already 20% of the way through the challenge? How's everybody doing staying on top of it? I was in awe of some of the solutions I saw yesterday. And I believe we had another couple firsts for new languages. Anyways, to the puzzle:
The Puzzle
In today’s puzzle, we've lost our boarding pass. But, like any tech-savvy holiday traveler, we're writing a program to use binary partitioning to unravel strings like BFBFFFBLRL into seat ID's. So. Yeah. Good luck!
The Leaderboards
As always, this is the spot where I’ll plug any leaderboard codes shared from the community.
Ryan's Leaderboard: 224198-25048a19
If you want to generate your own leaderboard and signal boost it a little bit, send it to me either in a DEV message or in a comment on one of these posts and I'll add it to the list above.
Yesterday’s Languages
Updated 03:07PM 12/12/2020 PST.
Language | Count |
---|---|
JavaScript | 4 |
Ruby | 2 |
C | 2 |
PHP | 2 |
Rust | 2 |
Python | 2 |
C# | 1 |
Go | 1 |
COBOL | 1 |
TypeScript | 1 |
Elixir | 1 |
Haskell | 1 |
Merry Coding!
Top comments (29)
COBOL (part 2 on my GitHub)
How do you run your COBOL solutions? I tried it in past AoCs but failed on that.
I'm using GnuCOBOL on Windows:
Python in 2 lines
And a much more legible Kotlin
I was curious to know if Python would let you execute a lambda immediately by wrapping it with parens and giving it the input, such as
(lambda)(input)
and ... sure enough you can. As such, I present this monstrosity in 1 line:I was hoping for a meaty one for a cold wet Saturday but this was straightforward. The insight was realising that "binary space partitioning" is just binary, swapping 1 and 0 for letters. I almost did it using string replace at first.
Yep, I noticed this too, I was like "hang on a sec" 🍒
Oh man! Swapping letters for numbers is an amazing insight. I'm half-tempted to go back and rewrite mine using even more sneaky binary tricks! I stopped at bit shifting.
This one was pretty simple.
Rust as always :D
Haskell:
Hey everyone 👋!
I've created a step-by-step tutorial for solving AoC 2020 day 5:
dev.to/kais_blog/step-by-step-tuto...
I'm using TypeScript and I explain how to use the binary representation of the boarding pass data.
Ruby, Late to the party - catching up!
I see lots of complex solutions when binary data packing/unpacking should be relatively compact and optimized. Hopefully this helps give people some ideas!
Part 2 of the puzzle was really puzzling, though I got the answer using set theory
My solution in python. Sometimes the challenge is just clicking what the description is actually saying, once it's obvious that these are just binary numbers then it was quite an easy one.
Today I have two implementations in Ruby for ya.
Wanting to continue with the Haskell approach of using just lists, which looks back at one of my favourite books from collage Brid and Wadler's Introduction to Functional Programming, I decided to allow my self one function, from the lens package, that is not in Haskell's standard of functions. At some point I guess it might get much of a performance issue to remain with just lists, but for now we continue.
That being said I could not face working with binary date in Haskell, directly at least, and so took a slightly lazy approach with calulating mid points, rather than going for swapping letters for 0 and 1.
Today I had a weird day. I did an advent task in my car waiting for gf Good for me that she was so late packing our cat for the trip. :topkek:
I saw many people did the task in a different way - I've used recurrence and pattern matching and it just works.
After discussing with my partner I thought I should do the binary version too, so here is a slightly modified version, but rather than using Haskell binary stuff, just used fold to convert the binary string to an int.
I went down an easy path today, implementing it in a most straightforward way:
Here's my C implementation. Kind of glad it was a straightforward problem this time. Will do tomorrow's in Python.