Last year's Christmas Day was a couple of bonus stars with no actual puzzle to solve so I was expecting the same. But no there's real work to do today, although thankfully part 1 is pretty straightforward.
Parsing
data classPoint(valw:Int,valx:Int,valy:Int,valz:Int)funparse(input:String):List<Point>{valinteger=or(INTEGER.map(String::toInt),isChar('-').next(INTEGER).map{s->-s.toInt()})valpoint=sequence(integer.followedBy(isChar(',')),integer.followedBy(isChar(',')),integer.followedBy(isChar(',')),integer,::Point)returnpoint.sepBy(WHITESPACES).parse(input.trim())}
You could model the constellations as a set of set of points but type inference gets a bit hairy in Kotlin so we'll make a wrapper. The inline classes feature coming in the future will make this possible with no runtime overhead. I'll add a few syntactic conveniences such as adding points to constellations and merging them.
data classConstellation(valpoints:Set<Point>){constructor(p:Point):this(setOf(p))}funConstellation.shouldContain(point:Point):Boolean=points.any{p->p.distance(point)<=3}operatorfunConstellation.plus(p:Point):Constellation=Constellation(points+p)operatorfunConstellation.plus(c:Constellation):Constellation=Constellation(points+c.points)funCollection<Constellation>.merge(p:Point):Constellation=fold(Constellation(p),Constellation::plus)
With all that done, solving part 1 is a fold over the input points. For each point, partition the existing constellations into the ones it should join and the ones it should not. Merge the ones that the point should join and leave the others alone.
Last year's Christmas Day was a couple of bonus stars with no actual puzzle to solve so I was expecting the same. But no there's real work to do today, although thankfully part 1 is pretty straightforward.
Parsing
Part 1
Manhattan distance. We've done this before:
You could model the constellations as a set of set of points but type inference gets a bit hairy in Kotlin so we'll make a wrapper. The inline classes feature coming in the future will make this possible with no runtime overhead. I'll add a few syntactic conveniences such as adding points to constellations and merging them.
With all that done, solving part 1 is a fold over the input points. For each point, partition the existing constellations into the ones it should join and the ones it should not. Merge the ones that the point should join and leave the others alone.
Part 2
I don't have enough stars to unlock part 2. Will try to get there before the end of the year!