Skip to content

Commit 77a9fb1

Browse files
committed
Solve day 21 part 1
1 parent eff7b66 commit 77a9fb1

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

day21/resources/input.txt

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
869A
2+
170A
3+
319A
4+
349A
5+
489A

day21/src/day21.scala

+10-4
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,13 @@ def shortestProgram(startState: State, goal: String): String =
105105
@main def main(path: String) =
106106
val input = Source.fromFile(path).getLines.toList
107107

108-
for line <- input do
109-
val pads = List(PadType.Dir, PadType.Dir, PadType.Dir, PadType.Num).map(Pad(_))
110-
val shortest = shortestProgram(State(pads), line)
111-
println(s"$shortest")
108+
val part1 = (
109+
for
110+
goal <- input
111+
yield
112+
val pads = List(PadType.Dir, PadType.Dir, PadType.Num).map(Pad(_))
113+
val shortest = shortestProgram(State(pads), goal)
114+
shortest.length * goal.dropRight(1).toInt
115+
).sum
116+
117+
println(s"Part 1: $part1")

0 commit comments

Comments
 (0)