Skip to content

Commit 926a5d5

Browse files
committed
2024-08 Scala template
1 parent f9ecfe5 commit 926a5d5

File tree

4 files changed

+80
-0
lines changed

4 files changed

+80
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
noop

scala2/src/main/resources/2024/08.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
noop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package jurisk.adventofcode.y2024
2+
3+
import jurisk.utils.FileInput._
4+
import jurisk.utils.Parsing.StringOps
5+
6+
object Advent08 {
7+
type Input = List[Command]
8+
type N = Long
9+
10+
sealed trait Command extends Product with Serializable
11+
object Command {
12+
case object Noop extends Command
13+
final case class Something(
14+
values: List[N]
15+
) extends Command
16+
final case class Other(value: String) extends Command
17+
18+
def parse(s: String): Command =
19+
s match {
20+
case "noop" => Noop
21+
case s"something $rem" => Something(rem.extractLongList)
22+
case s if s.nonEmpty => Other(s)
23+
case _ => s.failedToParse
24+
}
25+
}
26+
27+
def parse(input: String): Input =
28+
input.parseLines(Command.parse)
29+
30+
def part1(data: Input): N =
31+
0
32+
33+
def part2(data: Input): N =
34+
0
35+
36+
def parseFile(fileName: String): Input =
37+
parse(readFileText(fileName))
38+
39+
def fileName(suffix: String): String =
40+
s"2024/08$suffix.txt"
41+
42+
def main(args: Array[String]): Unit = {
43+
val realData: Input = parseFile(fileName(""))
44+
45+
println(s"Part 1: ${part1(realData)}")
46+
println(s"Part 2: ${part2(realData)}")
47+
}
48+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package jurisk.adventofcode.y2024
2+
3+
import Advent08._
4+
import org.scalatest.freespec.AnyFreeSpec
5+
import org.scalatest.matchers.should.Matchers._
6+
7+
class Advent08Spec extends AnyFreeSpec {
8+
private def testData = parseFile(fileName("-test-00"))
9+
private def realData = parseFile(fileName(""))
10+
11+
"part 1" - {
12+
"test" in {
13+
part1(testData) shouldEqual 0
14+
}
15+
16+
"real" in {
17+
part1(realData) shouldEqual 0
18+
}
19+
}
20+
21+
"part 2" - {
22+
"test" in {
23+
part2(testData) shouldEqual 0
24+
}
25+
26+
"real" in {
27+
part2(realData) shouldEqual 0
28+
}
29+
}
30+
}

0 commit comments

Comments
 (0)