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 data class Slope(val x: Int, val y: Int) @Day(3) class Day03(@Lines val input: Input>) { fun part1(slope: Slope = Slope(x = 3, y = 1)): Int { val grid = input.value var trees = 0 var x = 0 var y = 0 val width = grid.first().length while (y < grid.size - 1) { x += slope.x y += slope.y if (grid[y][x % width] == '#') trees++ } return trees } fun part2(): Long = listOf( Slope(x = 1, y = 1), Slope(x = 3, y = 1), Slope(x = 5, y = 1), Slope(x = 7, y = 1), Slope(x = 1, y = 2), ) .map { part1(it).toLong() } .reduce { acc, trees -> acc * trees } } fun main() = with(createDay()) { println(part1()) println(part2()) }