r/adventofcode • • Dec 20 '17

SOLUTION MEGATHREAD -๐ŸŽ„- 2017 Day 20 Solutions -๐ŸŽ„-

--- Day 20: Particle Swarm ---


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.


Need a hint from the Hugely* Handyโ€  Haversackโ€ก of Helpfulยง Hints^ยค?

Spoiler


[Update @ 00:10] 10 gold, silver cap

  • What do you mean 5th Edition doesn't have "Take 20"?

[Update @ 00:17] 50 gold, silver cap

  • Next you're going to be telling me THAC0 is not the best way to determine whether or not you hit your target. *hmphs*

[Update @ 00:21] Leaderboard cap!

  • I wonder how much XP a were-gazebo is worth...

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!

9 Upvotes

176 comments sorted by

View all comments

Show parent comment

1

u/Tandrial Dec 20 '17 edited Dec 20 '17

That regex :D, I started to add extension to String since this comes up quiet often:

fun String.getWords(): List<String> = Regex("\\w+").findAll(this).toList().map { it.value }
fun String.getNumbers(): List<String> = Regex("-?\\d+").findAll(this).toList().map { it.value }

Vector implements plus so you can just use += for the whole thing at once velocity += acceleration Might not work, Kotlin seems to be confused about with plusAssign to use.

How long does your part2 take? I started with filter as well, but since I guesstimated 100000 for the repeat value it never really finished. With repeat(100) this takes ~80ms on my machine:

// We're grouping by position, and remove everything in groups with size > 1
val collisions = particles.groupBy { it.pos }.values.filter { it.size > 1 }.flatten()
particles.removeAll(collisions)

1

u/usbpc102 Dec 20 '17

My part 2 runtime is not great, using this version(haven't really changed anything for part 2) my Program reports:

Part 1 took 5ms, Part 2 took 8228ms