From 9a0b4af4ac7a8f4aba89f575839e73553226349c Mon Sep 17 00:00:00 2001 From: chrisly42 Date: Mon, 1 Dec 2025 07:14:42 +0100 Subject: [PATCH] Day 1. --- src/aoc2025/Day01.kt | 72 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 src/aoc2025/Day01.kt diff --git a/src/aoc2025/Day01.kt b/src/aoc2025/Day01.kt new file mode 100644 index 0000000..d133771 --- /dev/null +++ b/src/aoc2025/Day01.kt @@ -0,0 +1,72 @@ +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): 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): 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() +}