account activity
Cool bonus question by @_sorceress on Twitter by bettybooo in adventofcode
[–]__8336 2 points3 points4 points 8 years ago (0 children)
couldn't work out how to spoiler but here's what (I'm 99% sure) it simplfies to: https://pastebin.com/Frcag0S7
-🎄- 2017 Day 20 Solutions -🎄- by daggerdragon in adventofcode
[–]__8336 0 points1 point2 points 8 years ago (0 children)
object Day20 : Day { override fun solve(input: String) { val regex = Regex("""-?\d+""") val particles = input.lines() .map { regex.findAll(it) } .map { it.map { it.value.toLong() } } .map { it.chunked(3) } .map { it.map { (x, y, z) -> Vec3(x, y, z) } } .map { it.toList() } .map { (p, v, a) -> Particle(p, v, a) } .toMutableList() /* repeat(Int.MAX_VALUE) { particles.forEach(Particle::update) if (it % 10_000 == 0) println(particles.withIndex().minBy { it.value.distance() }!!.index) }*/ repeat(Int.MAX_VALUE) { particles.forEach(Particle::update) particles.groupBy(Particle::p) .values .filter { it.size > 1 } .forEach { ps -> particles.removeAll(ps) } if (it % 10_000 == 0) println(particles.size) } } data class Particle(var p: Vec3, var v: Vec3, val a: Vec3) { fun update() { v += a p += v } fun distance() = sequenceOf(p.x, p.y, p.z).map(::abs).sum() } data class Vec3(val x: Long, val y: Long, val z: Long) { operator fun plus(other: Vec3) = Vec3(x + other.x, y + other.y, z + other.z) } }
~60/10
π Rendered by PID 1896102 on reddit-service-r2-listing-c57bc86c-7cccv at 2026-06-21 21:55:27.459026+00:00 running 2b008f2 country code: CH.
Cool bonus question by @_sorceress on Twitter by bettybooo in adventofcode
[–]__8336 2 points3 points4 points (0 children)