Skip to content

Commit

Permalink
2023/day 15 - part 1
Browse files Browse the repository at this point in the history
  • Loading branch information
underlow committed Dec 15, 2023
1 parent 940298b commit 5cedb50
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
47 changes: 47 additions & 0 deletions src/main/kotlin/me/underlow/advent2023/Day15.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package me.underlow.advent2023

import me.underlow.advent2022.checkResult
import me.underlow.advent2022.readInput

object LensLibrary {

fun part1(list: List<String>): Int {
val steps = parseInput(list)

val s = steps.map { it.calc1() }

return s.sum()
}

fun part2(list: List<String>): Int {
val directions = parseInput(list)
return 0
}

private fun parseInput(list: List<String>): List<String> {
return list.map { it.split(',') }.flatten()
}
}

private fun String.calc1(): Int {
var res = 0
for (c in this.toCharArray()) {
res += c.code
res = res * 17
res = res % 256
}
return res
}


fun main() {
val input = readInput("$pathPrefix23/day15.txt")
val res1 = LensLibrary.part1(input)
val res2 = LensLibrary.part2(input)

println("part 1: $res1")
println("part 2: $res2")

checkResult(res1, 503487)
checkResult(res2, 0)
}
Loading

0 comments on commit 5cedb50

Please sign in to comment.