Skip to content

Commit

Permalink
2023 - automated download of input.
Browse files Browse the repository at this point in the history
  • Loading branch information
fmmr committed Dec 11, 2023
1 parent e8300f0 commit 011545a
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 18 deletions.
18 changes: 13 additions & 5 deletions src/main/kotlin/no/rodland/advent/Misc.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,22 @@ import no.rodland.advent.Pos


fun String.readFile(): List<String> {
val resource = Pos::class.java.getResource("/$this")!!
return resource.readText().split("\n")
return readFileAsString().split("\n")
}

fun String.readFileAsString(): String {
val resource = Pos::class.java.getResource("/$this")!!
return resource.readText()
return try {
val resource = Pos::class.java.getResource("/$this")!!
val str = resource.readText()
if (str.last() == '\n') {
str.dropLast(1)
} else {
str
}
} catch (e: Exception) {
println("Unable to read file: $this, ${e.message}")
""
}
}

fun String.readFileAsInt(): List<Int> {
Expand Down Expand Up @@ -42,7 +51,6 @@ fun Int.isEven() = this % 2 == 0
fun Any.println() = println(this)



fun <T> Sequence<T>.takeWhileInclusive(pred: (T) -> Boolean): Sequence<T> {
var shouldContinue = true
return takeWhile {
Expand Down
14 changes: 14 additions & 0 deletions src/main/script/download_aoc_input.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash
YEAR=`date '+%Y'`
DAY=`date '+%d'`
DAY_NO_ZEROS="$(echo $DAY | sed 's/^0*//')"

AOC_SESSION_COOKIE="FIND_IN_BROWSER"

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"

curl -q -s "${PUZZLE_URL}" -H "cookie: session=${AOC_SESSION_COOKIE}" -o "${PUZZLE_FILE}" 2>/dev/null
touch "${PUZZLE_FILE_TEST}"
13 changes: 1 addition & 12 deletions src/test/kotlin/no/rodland/advent_2023/Day11Test.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,7 @@ import readFile
@DisableSlow
internal class Day11Test {
private val data11 = "2023/input_11.txt".readFile()
private val test11 = listOf(
"...#......",
".......#..",
"#.........",
"..........",
"......#...",
".#........",
".........#",
"..........",
".......#..",
"#...#.....",
)
private val test11 = "2023/input_11_test.txt".readFile()

private val resultTestOne = 374L
private val resultTestTwo = 82000210L
Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/2023/input_11.txt
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,4 @@
.................................................#..........................................................................................
.............#..........#...............................#...............#.............#..........#.........#........#.......................
............................................#................#.................#............................................................
....................................#....................................................................................#.............#....
....................................#....................................................................................#.............#....
10 changes: 10 additions & 0 deletions src/test/resources/2023/input_11_test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
...#......
.......#..
#.........
..........
......#...
.#........
.........#
..........
.......#..
#...#.....

0 comments on commit 011545a

Please sign in to comment.