package aoc2025

import println
import readInput

/*
--- Day 1: Secret Entrance ---
https://adventofcode.com/2025/day/1
*/
fun main() {

    val inlineTestInput = """
L68
L30
R48
L5
R60
L55
L1
L99
R14
L82
"""

    fun part1(input: List<String>): Int {
        var dialPos = 50
        var pass = 0
        for (i in input) {
            dialPos = if (i.startsWith("L")) {
                dialPos + 100 - i.substring(1).toInt()
            } else {
                dialPos + i.substring(1).toInt()
            }
            dialPos = dialPos % 100
            if (dialPos == 0) pass++
        }
        return pass
    }

    fun part2(input: List<String>): Int {
        var dialPos = 50
        var pass = 0
        for (i in input) {
            val rot = i.substring(1).toInt()
            if (rot == 0) continue
            if (i.startsWith("L")) {
                if (dialPos == 0) pass--
                dialPos -= rot
                pass += (100 - dialPos) / 100
            } else {
                dialPos += rot
                pass += dialPos / 100
            }
            dialPos = if (dialPos < 0) (100 - (-dialPos % 100)) % 100 else dialPos % 100
        }
        return pass
    }

    // test if implementation meets criteria from the description, like:
    val testInput = inlineTestInput.trim().reader().readLines()
    //val testInput = readInput("aoc2025/Day01_test")
    val testInputPart1Result = part1(testInput)
    println("Part 1 Test: $testInputPart1Result")
    val testInputPart2Result = part2(testInput)
    println("Part 2 Test: $testInputPart2Result")
    check(testInputPart1Result == 3)
    check(testInputPart2Result == 6)

    val input = readInput("aoc2025/Day01")
    part1(input).println()
    part2(input).println()
}
