Spaceship operator - Day 07 - Advent of Code 2023
Вставка
- Опубліковано 26 сер 2024
- This video tackles the "Camel Cards" poker puzzle. We’ll parse the input data into Hand objects, modeling ranks, and bids. We can sort hands by type and strength by including the Comparable module and implementing spaceship logic.
For part 1, we’ll build a card counter and hand typing system, assigning numeric ranks. This lets us multiply bids by position to get total winnings. For part 2's joker rules, we’ll tweak the ranks and add joker offset logic to promote hands.
The core solution focuses on custom classes and comparable spaceships for sorting. I polish with enumerable pipelines for a concise answer. While not golf code, we end up with readable Ruby leveraging objects, sorting, and clever tricks.
Advent of Code: adventofcode.com/
My Solutions: gist.github.co...
Playlist • Advent of Code
#adventofcode #ruby
How I handled my jokers was once I got the tally of cards, I removed the jokers from the tally hash and added the number of jokers to the highest card left in the hash and kept the rest of the logic similar to your part 1 implementation.
Oh nice! I actually like that approach better than mine!