diff --git a/src/Day15.kt b/src/Day15.kt new file mode 100644 index 0000000..bfc12de --- /dev/null +++ b/src/Day15.kt @@ -0,0 +1,26 @@ +fun main() { + fun part1(input: List): Int { + return input.first() + .split(',') + .fold(0) { acc, s -> + acc + s.hash() + } + } + + fun part2(input: List): Int { + return input.size + } + + // test if implementation meets criteria from the description, like: + val testInput = readInput("Day15_test") + check(part1(testInput) == 1320) + + val input = readInput("Day15") + part1(input).println() + check(part2(testInput) == 0) + part2(input).println() +} + +fun String.hash(): Int = toCharArray().fold(0) { sum, char -> + ((sum + char.code) * 17) % 256 +} \ No newline at end of file