Skip to content

Commit adb6e4c

Browse files
committed
refactor(day11): loop the neighbors
1 parent 4be031b commit adb6e4c

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

day11.sc

+4-10
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,10 @@ import common.loadPackets
22
import scala.annotation.tailrec
33

44
case class Point(x: Int, y: Int) {
5-
def neighbors = Set(
6-
copy(x = x - 1),
7-
copy(x = x - 1, y = y - 1),
8-
copy(y = y - 1),
9-
copy(x = x + 1, y = y - 1),
10-
copy(x = x + 1),
11-
copy(x = x + 1, y = y + 1),
12-
copy(y = y + 1),
13-
copy(x = x - 1, y = y + 1)
14-
)
5+
def neighbors =
6+
(for (dx <- -1 to 1;
7+
dy <- -1 to 1)
8+
yield copy(x = x + dx, y = y + dy)).toSet - this
159
}
1610

1711
type State = Map[Point, Int]

0 commit comments

Comments
 (0)