Skip to content

Commit

Permalink
2024-09 Scala 2 - Template
Browse files Browse the repository at this point in the history
  • Loading branch information
jurisk committed Dec 8, 2024
1 parent 396db3c commit 8edb9a3
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 0 deletions.
1 change: 1 addition & 0 deletions scala2/src/main/resources/2024/09-test-00.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
noop
1 change: 1 addition & 0 deletions scala2/src/main/resources/2024/09.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
noop
48 changes: 48 additions & 0 deletions scala2/src/main/scala/jurisk/adventofcode/y2024/Advent09.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package jurisk.adventofcode.y2024

import jurisk.utils.FileInput._
import jurisk.utils.Parsing.StringOps

object Advent09 {
type Input = List[Command]
type N = Long

sealed trait Command extends Product with Serializable
object Command {
case object Noop extends Command
final case class Something(
values: List[N]
) extends Command
final case class Other(value: String) extends Command

def parse(s: String): Command =
s match {
case "noop" => Noop
case s"something $rem" => Something(rem.extractLongList)
case s if s.nonEmpty => Other(s)
case _ => s.failedToParse
}
}

def parse(input: String): Input =
input.parseLines(Command.parse)

def part1(data: Input): N =
0

def part2(data: Input): N =
0

def parseFile(fileName: String): Input =
parse(readFileText(fileName))

def fileName(suffix: String): String =
s"2024/09$suffix.txt"

def main(args: Array[String]): Unit = {
val realData: Input = parseFile(fileName(""))

println(s"Part 1: ${part1(realData)}")
println(s"Part 2: ${part2(realData)}")
}
}
30 changes: 30 additions & 0 deletions scala2/src/test/scala/jurisk/adventofcode/y2024/Advent09Spec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package jurisk.adventofcode.y2024

import Advent09._
import org.scalatest.freespec.AnyFreeSpec
import org.scalatest.matchers.should.Matchers._

class Advent09Spec extends AnyFreeSpec {
private def testData = parseFile(fileName("-test-00"))
private def realData = parseFile(fileName(""))

"part 1" - {
"test" in {
part1(testData) shouldEqual 0
}

"real" in {
part1(realData) shouldEqual 0
}
}

"part 2" - {
"test" in {
part2(testData) shouldEqual 0
}

"real" in {
part2(realData) shouldEqual 0
}
}
}

0 comments on commit 8edb9a3

Please sign in to comment.