Skip to content

Commit e8d3bcf

Browse files
committed
Add locate
1 parent d6e43d1 commit e8d3bcf

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

day21/src/day21.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ val PAD_LAYOUTS = Map(
2727
)),
2828
)
2929

30+
extension (ptype: PadType) {
31+
def locate(c: Char) = PAD_LAYOUTS(ptype).find(_._2 == c).get._1
32+
}
33+
3034
val DIRECTIONS = Map(
3135
('<', Vec2(-1, 0)),
3236
('>', Vec2( 1, 0)),
@@ -50,7 +54,7 @@ case class Pad(ptype: PadType, pos: Vec2) {
5054
}
5155

5256
object Pad {
53-
def apply(ptype: PadType): Pad = Pad(ptype, PAD_LAYOUTS(ptype).find(_._2 == 'A').get._1)
57+
def apply(ptype: PadType): Pad = Pad(ptype, ptype.locate('A'))
5458
}
5559

5660
case class State(pads: List[Pad] = List(), output: String = "") {

0 commit comments

Comments
 (0)