diff options
author | tchojnacki <tomaszchojnacki2001@gmail.com> | 2022-08-11 19:24:23 +0200 |
---|---|---|
committer | tchojnacki <tomaszchojnacki2001@gmail.com> | 2022-08-11 19:24:23 +0200 |
commit | 0f1e145b80813ae2331b7dac5ace0c589654ad2a (patch) | |
tree | 25483b8239436dd5aed2fee8811caf0ba893c0bb /2021-kotlin/src/Day02.kt | |
parent | 85fb0396bed6a2129b12392941103924b1ab55be (diff) | |
download | gleam_aoc2020-0f1e145b80813ae2331b7dac5ace0c589654ad2a.tar.gz gleam_aoc2020-0f1e145b80813ae2331b7dac5ace0c589654ad2a.zip |
Move subproject to avoid IntelliJ module name issues
Diffstat (limited to '2021-kotlin/src/Day02.kt')
-rw-r--r-- | 2021-kotlin/src/Day02.kt | 56 |
1 files changed, 0 insertions, 56 deletions
diff --git a/2021-kotlin/src/Day02.kt b/2021-kotlin/src/Day02.kt deleted file mode 100644 index 2eb085a..0000000 --- a/2021-kotlin/src/Day02.kt +++ /dev/null @@ -1,56 +0,0 @@ -object Day02 { - private fun dispatchCommands(commands: List<String>, action: (command: String, argument: Int) -> Unit) { - for (line in commands) { - val parts = line.split(" ") - val command = parts[0] - val argument = parts[1].toInt() - - action(command, argument) - } - } - - fun part1(input: List<String>): Int { - var horizontal = 0 - var depth = 0 - - dispatchCommands(input) { command, argument -> - when (command) { - "forward" -> horizontal += argument - "down" -> depth += argument - "up" -> depth -= argument - } - } - - return horizontal * depth - } - - fun part2(input: List<String>): Int { - var horizontal = 0 - var depth = 0 - var aim = 0 - - dispatchCommands(input) { command, argument -> - when (command) { - "forward" -> { - horizontal += argument - depth += aim * argument - } - - "down" -> aim += argument - "up" -> aim -= argument - } - } - - return horizontal * depth - } -} - -fun main() { - val testInput = readInputAsLines("Day02_test") - check(Day02.part1(testInput) == 150) - check(Day02.part2(testInput) == 900) - - val input = readInputAsLines("Day02") - println(Day02.part1(input)) - println(Day02.part2(input)) -} |