Skip to content

Commit

Permalink
Day 11 refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
benoitpas committed Dec 13, 2023
1 parent 22fe55a commit 6934c59
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
7 changes: 3 additions & 4 deletions src/main/scala/day11.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import zio._
import zio.Console._
import Day6.nbDistances

object Day11 extends ZIOAppDefault {

Expand All @@ -16,7 +15,7 @@ object Day11 extends ZIOAppDefault {
(g1._2 - g2._2).abs + expansion * emptyRows.count(y => math.min(g1._2, g2._2) < y && y < math.max(g1._2, g2._2))
cols + rows

def part1(space: List[String], expansion: Int) =
def sumDistances(space: List[String], expansion: Int) =
val galaxies = {
for
(y, l) <- (1L to space.length) zip space
Expand All @@ -36,7 +35,7 @@ object Day11 extends ZIOAppDefault {
def run =
for {
v <- Day1.readFile("day11_input.txt")
_ <- printLine(s"part1=${part1(v, 1)}")
_ <- printLine(s"part2=${part1(v, 999999)}")
_ <- printLine(s"part1=${sumDistances(v, 1)}")
_ <- printLine(s"part2=${sumDistances(v, 999999)}")
} yield ()
}
8 changes: 4 additions & 4 deletions src/test/scala/day11_test.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ class Day11Test {

@Test
def testPart1() =
assertEquals(374, Day11.part1(space, 1))
assertEquals(374, Day11.sumDistances(space, 1))

@Test
def testPart1b() =
assertEquals(50, Day11.part1(space2, 1))
assertEquals(50, Day11.sumDistances(space2, 1))

@Test
def testPart2a() =
assertEquals(1030, Day11.part1(space, 9))
assertEquals(1030, Day11.sumDistances(space, 9))

@Test
def testPart2b() =
assertEquals(8410, Day11.part1(space, 99))
assertEquals(8410, Day11.sumDistances(space, 99))

}

0 comments on commit 6934c59

Please sign in to comment.