-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathday14.nim
More file actions
36 lines (26 loc) · 701 Bytes
/
day14.nim
File metadata and controls
36 lines (26 loc) · 701 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import sets, day10
type Coordinate = tuple[x, y: int]
const
instructions = "hwlqcszp-"
deltas: array[4, Coordinate] = [(1, 0), (-1, 0), (0, 1), (0, -1)]
func createMaze(): HashSet[Coordinate] =
for row in 0 .. 127:
let
word = instructions & $row
binHash = knotHashing(word, binOut = true)
for i, n in binHash:
if n == '1':
result.incl((row, i))
var maze = createMaze()
echo maze.len
proc dfs(coord: Coordinate) =
for delta in deltas:
let candidate = (coord.x + delta.x, coord.y + delta.y)
if candidate in maze:
maze.excl(candidate)
dfs(candidate)
var regions: int
while maze.len > 0:
dfs(maze.pop())
inc regions
echo regions