Skip to content

Commit

Permalink
2023 - Day 21 - parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
fmmr committed Dec 22, 2023
1 parent 97d2905 commit 3145906
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/main/kotlin/no/rodland/advent/SpacePos.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ sealed class SpacePos {

data class Pos3D(val x: Int, val y: Int, val z: Int) : SpacePos() {
constructor(triple: Triple<Int, Int, Int>) : this(triple.first, triple.second, triple.third)
constructor(str:String, separator:Char=',') : this(str.split(separator).map { it.trim().toInt() }.let { Triple(it[0], it[1], it[2]) })

override fun neighbours(): List<SpacePos> {
return listOf(0, 1, -1)
Expand Down
10 changes: 7 additions & 3 deletions src/main/kotlin/no/rodland/advent_2023/Day22.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package no.rodland.advent_2023

import no.rodland.advent.Day
import no.rodland.advent.Pos3D

// template generated: 22/12/2023
// Fredrik Rødland 2023

class Day22(val input: List<String>) : Day<Long, Long, List<String>> {
class Day22(val input: List<String>) : Day<Long, Long, List<Day22.Brick>> {

private val parsed = input.parse()

Expand All @@ -17,9 +18,12 @@ class Day22(val input: List<String>) : Day<Long, Long, List<String>> {
return 2
}

override fun List<String>.parse(): List<String> {
data class Brick(val from: Pos3D, val to: Pos3D)

override fun List<String>.parse(): List<Brick> {
return map { line ->
line
val (from, to) = line.split('~')
Brick(Pos3D(from), Pos3D(to))
}
}

Expand Down
18 changes: 13 additions & 5 deletions src/main/script/download_aoc_input.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
#!/bin/bash
YEAR=$(date '+%Y')
DAY=$(date '+%d')
DAY_NO_ZEROS="${DAY//0/}"
# shellcheck disable=SC2001
DAY_NO_ZEROS="$(echo "$DAY" | sed 's/^0*//')"

AOC_SESSION_COOKIE="FIND_IN_BROWSER"

AOC_DIR="/Users/fmr/projects/advent"
PUZZLE_URL="https://adventofcode.com/${YEAR}/day/${DAY_NO_ZEROS}/input"

PUZZLE_FILE="/Users/fmr/projects/advent/src/test/resources/${YEAR}/input_${DAY}.txt"
PUZZLE_FILE_TEST="/Users/fmr/projects/advent/src/test/resources/${YEAR}/input_${DAY}_test.txt"
PUZZLE_FILE="${AOC_DIR}/src/test/resources/${YEAR}/input_${DAY}.txt"
PUZZLE_FILE_TEST="${AOC_DIR}/src/test/resources/${YEAR}/input_${DAY}_test.txt"

curl -q -s "${PUZZLE_URL}" -H "cookie: session=${AOC_SESSION_COOKIE}" -o "${PUZZLE_FILE}" 2>/dev/null
touch "${PUZZLE_FILE_TEST}"
touch "${PUZZLE_FILE_TEST}"

cd "${AOC_DIR}" || exit
git add "src/test/resources/${YEAR}/input_${DAY}_test.txt"
git commit -a -m "${YEAR} - Day ${DAY} - input/init"
cd - || exit

tail -10 "$PUZZLE_FILE"
7 changes: 7 additions & 0 deletions src/test/resources/2023/input_22_test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
1,0,1~1,2,1
0,0,2~2,0,2
0,2,3~2,2,3
0,0,4~0,2,4
2,0,5~2,2,5
0,1,6~2,1,6
1,1,8~1,1,9

0 comments on commit 3145906

Please sign in to comment.