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?...
For further actions, you may consider blocking this person and/or reporting abuse
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.
With a bit of bitshifting:
And an alternative solution in PHP :-D
Pretty quick one today! I didn't have much problem, and once I realized that the seat ID was actually the index into a 1-D array of seats, I stopped writing my own custom seatID->index function 😂
Day5.h:
Day5.c:
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.
This one was pretty simple.
Rust as always :D
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
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.
I'm sad I couldn't think of a regex solution, just a quick sort and filter. (you get the gist)
Ruby, part 2:
My Haskell Solution (I just started learning Haskell so fair warning):
Hi, new to this site, and AOC. I did the last 4 in Python, but I thought I would try shell for this one (i'm not great at shell so this may be not the best):
I solved part 1 with this shell oneliner...
for part two, I created the list of passport ids with:
then threw this at the ids file:
My JavaScript walkthrough: