Skip to content

Commit

Permalink
test(2024/07): add test
Browse files Browse the repository at this point in the history
  • Loading branch information
scarf005 committed Dec 8, 2024
1 parent cc77c00 commit d056659
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
15 changes: 10 additions & 5 deletions 2024/day07.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,15 @@ def getCombo(xs: List[Long], next: Op) =
def solve(xss: Vector[(Long, List[Long])], op: Op) =
xss.filter((target, xs) => getCombo(xs, op).exists(_ == target)).map(_._1).sum

def parse(input: String) = input.linesIterator.collect { case s"$target: $xs" =>
(target.toLong, xs.split(" ").map(_.toLong).toList)
}.toVector

def part1(y: Long)(x: Long) = List(x + y, x * y)
def part2(y: Long)(x: Long) = List(x + y, x * y, x || y)

@main def main() =
val input = readInput(this).getLines.collect { case s"$target: $xs" =>
(target.toLong, xs.split(" ").map(_.toLong).toList)
}.toVector
val input = readInput(this).mkString |> parse

println(solve(input, (x) => (a) => List(a + x, a * x)))
println(solve(input, (x) => (a) => List(a + x, a * x, a || x)))
println(solve(input, part1))
println(solve(input, part2))
24 changes: 24 additions & 0 deletions 2024/day07.test.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package `2024`.day07

import prelude.*
import munit.FunSuite

val example =
"""|190: 10 19
|3267: 81 40 27
|83: 17 5
|156: 15 6
|7290: 6 8 6 15
|161011: 16 10 13
|192: 17 8 14
|21037: 9 7 18 13
|292: 11 6 16 20""".stripMargin

class Test extends FunSuite:
val input = example |> parse

test("part 1"):
assertEquals(solve(input, part1), 3749L)

test("part 2"):
assertEquals(solve(input, part2), 11387L)

0 comments on commit d056659

Please sign in to comment.