object Day4 : AdventOfCode({ val parsed = input.toGrid() fun Grid.step(): Grid = mapValues { (point, char) -> when(char){ '@' if(point.winds().count{ get(it) == '@' } < 4) -> '.' else -> char } } fun Grid.countRolls() = count { it.value == '@' } part1{ parsed.countRolls() - parsed.step().countRolls() } part2{ generateSequence(parsed, Grid::step).zipWithNext() .takeWhile { it.first != it.second } .last() .second .let { parsed.countRolls() - it.countRolls() } } })