Skill Issue logo

Skill Issue

Subscribe
Archives
December 9, 2024

Advent of Terrible Code

Christmas time is here, and three things are true:

  1. I'm streaming Advent of Code.
  2. I have not yet lost Whamageddon.
  3. This email was supposed to go out on Friday.

Heads up that there are mild Advent of Code spoilers in this email. I wouldn't consider any of this to be a real spoiler, but if you have a low tolerance for spoilers and are planning on doing these puzzles, consider holding off on reading this until you've completed day 8.

Day 1-4

As of writing this, I've completed days 1 through 8. Day 1's solution was just a chain of Ruby's Enumerable/Array methods. Ruby is a great language for coming up with solutions to these problems very quickly.

Day 2 was similar to day 1, in that if you know that Ruby gives you some helpful convenience methods, the solution is relatively simple. If you don't, and you try to implement each_cons yourself, then it's more work.

I liked day 3. My solution evaled parts of the puzzle input. Sorry, not sorry. We're here to have fun, not follow "best practices". (If I get hacked, kudos to whoever decided on Advent of Code puzzle inputs as the attack vector.)

image.png

I didn't find anything too weird to do day 4, so I took it as an opportunity to unify part 1 and part 2, providing different data to each to get their respective solutions.

Day 5: Operation Operator Override

On day 5, Marco Roth joined the stream and suggested we write some really bad code. I obliged. I won't get into details here, because I wrote a blog post all about it. Here's a teaser:

rule_data, update_data = *-input

rules = rule_data > ->(r) { eval r }
updates = update_data > ->(u) { eval "Update[#{u}]" }

valid_updates, invalid_updates = updates =~ ->(update) {
  rules <= ->(rule) { update === rule }
}

part_one = valid_updates.>=(&:~@)

part_two = (invalid_updates > ->(update) {
  update << rules
}).>=(&:~@)

`Part One: #{part_one}`
`Part Two: #{part_two}`

Yeah, that's valid Ruby.

Day 6: The Case of the Missing Method

Day 6 was a lot like day 5, in that Marco helped out and we wrote some truly terrible code. This time, we solved the entire puzzle by defining method_missing on Object.

Fun Fact: Ruby warns you if you define method_missing on Object as it can cause weird issues.

The code is terrible and you can look at it here.

Day 7/8

Sadly, I didn't do anything too crazy for day 7 and 8. My solution for day 7 is just an example of how you can create your own enumerable objects in Ruby. On day 8, I showed how to create custom value objects. Useful stuff to know, but not weird.

If you want to watch future streams, you'll find me over on Twitch. If you want to watch VODs, they are in this playlist on YouTube.

I'm still waiting for an opportunity to eval an entire input.

Occam's Razor

New music releases get pretty scarce towards the end of the year. I've been on a bit of a black metal kick, though, and Panzerfaust's release from last month has been seeing heavy rotation around my place. Check it out.

Don't miss what's next. Subscribe to Skill Issue:
GitHub Bluesky X LinkedIn
Powered by Buttondown, the easiest way to start and grow your newsletter.