r/adventofcode • u/daggerdragon • Dec 03 '18
SOLUTION MEGATHREAD -π- 2018 Day 3 Solutions -π-
--- Day 3: No Matter How You Slice It ---
Post your solution as a comment or, for longer solutions, consider linking to your repo (e.g. GitHub/gists/Pastebin/blag or whatever).
Note: The Solution Megathreads are for solutions only. If you have questions, please post your own thread and make sure to flair it with Help.
Advent of Code: The Party Game!
ATTENTION: minor change request from the mods!
Please prefix your card submission with something like [Card] to make scanning the megathread easier. THANK YOU!
Card prompt: Day 3 image coming soon - imgur is being a dick, so I've contacted their support.
Transcript:
I'm ready for today's puzzle because I have the Savvy Programmer's Guide to ___.
This thread will be unlocked when there are a significant number of people on the leaderboard with gold stars for today's puzzle.
edit: Leaderboard capped, thread unlocked!
41
Upvotes
View all comments
Show parent comment
3
u/pindab0ter Dec 06 '18 edited Dec 06 '18
Very nice solution and a nice write-up on the blog as well!
I didn't know where to start on this day's challenge, so I started off by copying yours and trying to learn ways of tackling this problem.
First of all, I haven't ever used
groupingBybefore, so thanks for showing me that. Without it it would've been a much taller order.Secondly, I'm very excited about how much of a perfect marriage Kotlin seems to be between FP and OO. This assignment is a prime example.
I'll showcase two things I'm proud of:
1: Creating a Claim from a String
Your way of doing this was brilliant. I love the
.destructured, but wanted to take it a little further by mappingString::toIntand dot-chaining everything, and the coolest thing; destructuring theList<Int>in the closure (I didn't know Kotlin allowed for destructuring lists):2: I found a nice single expression for part two
This is where I diverge from your solution. You maintain state for both yet uncovered claims and for the cloth as a whole.
My solution: find the first element that doesn't overlap with anything.
Sounds simple, right? It took between 15 and 20 minutes, thoughβ¦
Thanks again for showing me some new tricks. Please have a look through my solution as I think you might enjoy it :)
GitHub repo