-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday21.hs
More file actions
24 lines (16 loc) · 694 Bytes
/
Copy pathday21.hs
File metadata and controls
24 lines (16 loc) · 694 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
module Main where
import Control.Arrow ((&&&))
import Data.Map (Map)
import Data.Map qualified as Map
import Data.Set (Set, intersection, (\\))
import Data.Set qualified as Set
import Debug.Trace (trace)
type Garden = Set Plot
type Plot = (Int, Int)
main = interact (unlines . sequence [part1] . graph . lines)
part1 = ("Part 1: " ++) . show . length . (!! 64) . uncurry (iterate . walk)
walk = flip $ intersection . Set.unions . Set.map dirs
graph input =
(Map.keysSet &&& Map.keysSet . Map.filter (== 'S')) $
Map.fromList [((x, y), v) | (y, row) <- zip [0 ..] input, (x, v) <- zip [0 ..] row, v /= '#']
dirs (x, y) = Set.fromList [(x + 1, y), (x - 1, y), (x, y + 1), (x, y - 1)]