Day24 part1
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
package be.vandewalleh.aoc.days
|
||||
|
||||
import be.vandewalleh.aoc.utils.input.Day
|
||||
import be.vandewalleh.aoc.utils.input.Input
|
||||
import be.vandewalleh.aoc.utils.input.Lines
|
||||
import be.vandewalleh.aoc.utils.input.createDay
|
||||
import org.eclipse.collections.api.factory.Bags
|
||||
|
||||
@Day(24)
|
||||
class Day24(@Lines val input: Input<List<String>>) {
|
||||
|
||||
private enum class Direction(vararg coordinates: Int) {
|
||||
E(1, -1, 0),
|
||||
SE(0, -1, 1),
|
||||
SW(-1, 0, 1),
|
||||
W(-1, 1, 0),
|
||||
NW(0, 1, -1),
|
||||
NE(1, 0, -1);
|
||||
|
||||
val coordinates = coordinates
|
||||
}
|
||||
|
||||
private data class Tile(val directions: List<Direction>)
|
||||
|
||||
private fun parseTile(line: String): Tile {
|
||||
val re = "e|se|sw|w|nw|ne".toRegex()
|
||||
val directions = re.findAll(line).flatMap { it.groupValues }.map { Direction.valueOf(it.toUpperCase()) }
|
||||
return Tile(directions.toList())
|
||||
}
|
||||
|
||||
fun part1() {
|
||||
val tiles = input.value.map { parseTile(it) }
|
||||
val bag = Bags.mutable.empty<List<Int>>()
|
||||
for (tile in tiles) {
|
||||
val encountered = tile.directions
|
||||
.map { it.coordinates }
|
||||
.reduce { acc, ints -> intArrayOf(acc[0] + ints[0], acc[1] + ints[1], acc[2] + ints[2]) }
|
||||
.toList()
|
||||
bag.add(encountered)
|
||||
}
|
||||
println(bag.selectByOccurrences { it % 2 == 1 }.size)
|
||||
}
|
||||
|
||||
fun part2() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
fun main() = with(createDay<Day24>()) {
|
||||
println(part1())
|
||||
println(part2())
|
||||
}
|
||||
Reference in New Issue
Block a user