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 (28)
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: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:
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.
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.
Yep, I noticed this too, I was like "hang on a sec" 🍒
Today I have two implementations in Ruby for ya.
Haskell:
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 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.