Commit 033ee470 authored by Alexander Gehrke's avatar Alexander Gehrke
Browse files

Allow reading samples from files and add a command line switch for it

parent b896b4f6
package aoc2020
@main def runDay(inputDir: String, day: Int): Unit =
given Location(inputDir, day)
//given Fixed(sample)
@main def runDay(inputDir: String, day: Int, sample: Int = -1): Unit =
given InputSource = inputSource(inputDir, day, sample)
val out = day match {
case 1 => input(_.toInt)(day1)
case 2 => input()(day2)
......@@ -17,6 +16,9 @@ package aoc2020
case 12 => input()(day12)
case _ => "No such day implemented"
}
if (sample > 0) println("SAMPLE VALUES!")
println(out)
//val sample: List[String] = List()
def inputSource(inputDir:String, day: Int, sample: Int) =
if (sample > 0) then SampleLocation(inputDir, day, sample)
else Location(inputDir, day)
......@@ -5,10 +5,12 @@ import scala.io.Source
sealed trait InputSource
case class Location(inputDir: String, day: Int) extends InputSource
case class Fixed(lines: List[String]) extends InputSource
case class SampleLocation(inputDir: String, day: Int, sample: Int) extends InputSource
def inputLines(using src: InputSource): Iterator[String] = src match {
case Location(inputDir, day) => scala.io.Source.fromFile(s"${inputDir}/day${day}.txt").getLines
case Fixed(input) => input.iterator
case SampleLocation(inputDir, day, sample) => scala.io.Source.fromFile(s"${inputDir}/day${day}-sample${sample}.txt").getLines
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment