File tree Expand file tree Collapse file tree 2 files changed +11
-2
lines changed
day15/src/main/kotlin/de/havox_design/aoc2023/day15 Expand file tree Collapse file tree 2 files changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ plugins {
44
55// project meta data
66group ' de.havox_design.aoc2023'
7- version ' 0.14.2 '
7+ version ' 0.14.3 '
88
99// Switch to gradle "all" distribution.
1010wrapper {
Original file line number Diff line number Diff line change 11package de.havox_design.aoc2023.day15
22
33class Day15 (private var filename : String ) {
4+ private val ELEMENT_DELIMITER = " ,"
5+
46 fun solvePart1 (): Long =
5- 1320L
7+ getResourceAsText(filename)[0 ]
8+ .split(ELEMENT_DELIMITER )
9+ .sumOf { word -> calculateHash(word) }
10+ .toLong()
611
712 fun solvePart2 (): Long =
813 0L
914
15+ private fun calculateHash (word : String ): Int =
16+ word
17+ .fold(0 ) { acc, c -> ((acc + c.code) * 17 ) % 256 }
18+
1019 private fun getResourceAsText (path : String ): List <String > =
1120 this .javaClass.classLoader.getResourceAsStream(path)!! .bufferedReader().readLines()
1221}
You can’t perform that action at this time.
0 commit comments