Fix absolute paths
This commit is contained in:
@@ -26,10 +26,10 @@ def runSolver(solver: Solver, input: os.Path): Unit =
|
||||
day match
|
||||
case "all" =>
|
||||
solvers.foreach { case (day, solver) =>
|
||||
runSolver(solver, os.pwd / os.RelPath(input) / f"$day%02d.in")
|
||||
runSolver(solver, os.Path(input, os.pwd) / f"$day%02d.in")
|
||||
}
|
||||
case num(_) =>
|
||||
solvers.get(day.toInt) match
|
||||
case Some(solver) => runSolver(solver, os.pwd / os.RelPath(input))
|
||||
case Some(solver) => runSolver(solver, os.Path(input, os.pwd))
|
||||
case None => println(s"Day $day not solved")
|
||||
case _ => println(day)
|
||||
|
||||
@@ -5,7 +5,7 @@ case class Timings(prep: Long, p1: Long, p2: Long)
|
||||
case class Solution(p1: Object, p2: Object)
|
||||
|
||||
abstract class Solver(day: Int):
|
||||
def run(input: os.Path): (Timings, Solution)
|
||||
def run(input: os.ReadablePath): (Timings, Solution)
|
||||
|
||||
def timed[A](solution: => A): (Long, A) =
|
||||
val start = System.nanoTime()
|
||||
|
||||
12
aoc/src/dev/ctsk/aoc/Util.scala
Normal file
12
aoc/src/dev/ctsk/aoc/Util.scala
Normal file
@@ -0,0 +1,12 @@
|
||||
package dev.ctsk.aoc
|
||||
|
||||
import scala.collection
|
||||
|
||||
val NAT_REGEX = """(\d+)""".r
|
||||
val INT_REGEX = """-?(\d+)""".r
|
||||
|
||||
def naturals(string: CharSequence): Vector[Long] =
|
||||
NAT_REGEX.findAllIn(string).map(_.toLong).toVector
|
||||
|
||||
def integers(string: CharSequence): Vector[Long] =
|
||||
INT_REGEX.findAllIn(string).map(_.toLong).toVector
|
||||
@@ -5,7 +5,7 @@ import dev.ctsk.aoc._
|
||||
object Day01 extends Solver(1):
|
||||
type Input = (Array[Int], Array[Int])
|
||||
|
||||
def pre(input: os.Path): Input =
|
||||
def pre(input: os.ReadablePath): Input =
|
||||
os.read
|
||||
.lines(input)
|
||||
.map { case s"$i $j" => (i.toInt, j.toInt) }
|
||||
@@ -21,7 +21,7 @@ object Day01 extends Solver(1):
|
||||
val counts = right.groupMapReduce(identity)(identity)(_ + _)
|
||||
left.map(n => counts.getOrElse(n, 0)).sum
|
||||
|
||||
def run(input: os.Path): (Timings, Solution) =
|
||||
def run(input: os.ReadablePath): (Timings, Solution) =
|
||||
val (pre_time, pre_input) = timed { pre(input) }
|
||||
val (p1_time, p1_solution) = timed { part1(pre_input) }
|
||||
val (p2_time, p2_solution) = timed { part2(pre_input) }
|
||||
|
||||
@@ -3,7 +3,7 @@ package dev.ctsk.aoc.days
|
||||
import dev.ctsk.aoc._
|
||||
|
||||
object Day02 extends Solver(2):
|
||||
def pre(input: os.Path): List[List[Int]] =
|
||||
def pre(input: os.ReadablePath): List[List[Int]] =
|
||||
os.read
|
||||
.lines(input)
|
||||
.map(line => line.split(" ").map(_.toInt).toList)
|
||||
@@ -24,7 +24,7 @@ object Day02 extends Solver(2):
|
||||
def part2(lists: List[List[Int]]): Int =
|
||||
lists.count(list => safeWithGap(list) || safeWithGap(list.reverse))
|
||||
|
||||
def run(input: os.Path): (Timings, Solution) =
|
||||
def run(input: os.ReadablePath): (Timings, Solution) =
|
||||
val (pre_time, pre_input) = timed { pre(input) }
|
||||
val (p1_time, p1_solution) = timed { part1(pre_input) }
|
||||
val (p2_time, p2_solution) = timed { part2(pre_input) }
|
||||
|
||||
@@ -24,7 +24,7 @@ object Day03 extends Solver(3):
|
||||
}
|
||||
._2
|
||||
|
||||
def run(input: os.Path): (Timings, Solution) =
|
||||
def run(input: os.ReadablePath): (Timings, Solution) =
|
||||
val in = os.read(input)
|
||||
val (p1_time, p1_solution) = timed { part1(in) }
|
||||
val (p2_time, p2_solution) = timed { part2(in) }
|
||||
|
||||
@@ -38,7 +38,7 @@ object Day04 extends Solver(4):
|
||||
&& grid(i - 1)(j + 1) + grid(i + 1)(j - 1) == 'S' + 'M'
|
||||
yield ()).length
|
||||
|
||||
def run(input: os.Path): (Timings, Solution) =
|
||||
def run(input: os.ReadablePath): (Timings, Solution) =
|
||||
var in = os.read.lines(input).map { line => line.toVector }.toVector
|
||||
|
||||
val (p1_time, p1_solution) = timed { part1(in) }
|
||||
|
||||
@@ -4,7 +4,7 @@ import dev.ctsk.aoc._
|
||||
import scala.annotation.nowarn
|
||||
|
||||
object Day05 extends Solver(5):
|
||||
def pre(input: os.Path) =
|
||||
def pre(input: os.ReadablePath) =
|
||||
val Array(rulesStr, updatesStr) = os.read(input).split("\n\n")
|
||||
|
||||
val rules = rulesStr.linesIterator
|
||||
@@ -19,7 +19,7 @@ object Day05 extends Solver(5):
|
||||
|
||||
(rules, updates)
|
||||
|
||||
def run(input: os.Path): (Timings, Solution) =
|
||||
def run(input: os.ReadablePath): (Timings, Solution) =
|
||||
val (pre_time, (rules, updates)) = timed { pre(input) }
|
||||
|
||||
@nowarn("msg=match may not be exhaustive")
|
||||
|
||||
Reference in New Issue
Block a user