File tree Expand file tree Collapse file tree 3 files changed +61
-2
lines changed
day14/src/main/kotlin/de/havox_design/aoc2023/day14 Expand file tree Collapse file tree 3 files changed +61
-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.13.1 '
7+ version ' 0.13.2 '
88
99// Switch to gradle "all" distribution.
1010wrapper {
Original file line number Diff line number Diff line change @@ -2,7 +2,10 @@ package de.havox_design.aoc2023.day14
22
33class Day14 (private var filename : String ) {
44 fun solvePart1 (): Long =
5- 136L
5+ Matrix (getResourceAsText(filename))
6+ .rollNorth()
7+ .northLoad()
8+ .toLong()
69
710 fun solvePart2 (): Long =
811 0L
Original file line number Diff line number Diff line change 1+ package de.havox_design.aoc2023.day14
2+
3+ data class Matrix (val matrix : MutableList <CharArray >) {
4+ private val ICON_ROUND_STONE = ' O'
5+ private val ICON_SQUARE_STONE = ' #'
6+
7+ fun rollNorth (): Matrix =
8+ apply {
9+ matrix
10+ .first()
11+ .indices
12+ .forEach { columnIndex ->
13+
14+ matrix
15+ .indices
16+ .joinToString(" " ) { rowIndex ->
17+ matrix[rowIndex][columnIndex].toString()
18+ }
19+ .split(ICON_SQUARE_STONE )
20+ .joinToString(ICON_SQUARE_STONE .toString()) {
21+ it
22+ .toCharArray()
23+ .sortedDescending()
24+ .joinToString(" " )
25+ }
26+
27+ .forEachIndexed { rowIndex, c ->
28+ matrix[rowIndex][columnIndex] = c
29+ }
30+ }
31+ }
32+
33+ fun northLoad (): Int =
34+ matrix
35+ .first()
36+ .indices
37+ .sumOf { columnIndex ->
38+ matrix.indices
39+ .sumOf { rowIndex ->
40+ when (ICON_ROUND_STONE ) {
41+ matrix[rowIndex][columnIndex] -> matrix.size - rowIndex
42+ else -> 0
43+ }
44+ }
45+ }
46+
47+ override fun toString (): String =
48+ matrix
49+ .joinToString(" \n " ) { line -> line.joinToString(" " ) }
50+ }
51+
52+ fun Matrix (input : List <String >): Matrix =
53+ input
54+ .map(String ::toCharArray)
55+ .toMutableList()
56+ .let (::Matrix )
You can’t perform that action at this time.
0 commit comments