summaryrefslogtreecommitdiff
path: root/12-1.hs
diff options
context:
space:
mode:
Diffstat (limited to '12-1.hs')
-rw-r--r--12-1.hs11
1 files changed, 6 insertions, 5 deletions
diff --git a/12-1.hs b/12-1.hs
index 78ea186..11b793f 100644
--- a/12-1.hs
+++ b/12-1.hs
@@ -1,4 +1,5 @@
import Data.Array
+import Data.HashSet as HS (HashSet, fromList, member, singleton, toList)
import Data.List (nub)
type Map = Array (Int,Int) (Maybe Char)
@@ -25,18 +26,18 @@ findNext = go
| otherwise = Nothing
getRegion :: Map -> (Int,Int) -> [(Int,Int)]
-getRegion m p = go [p] [p]
+getRegion m p = go (HS.singleton p) [p]
where
- go :: [(Int,Int)] -> [(Int,Int)] -> [(Int,Int)]
+ go :: HS.HashSet (Int,Int) -> [(Int,Int)] -> [(Int,Int)]
go visited points =
let v = filter f
- . filter (not . (`elem` visited))
+ . filter (not . (`HS.member` visited))
. nub
. concatMap neighbours
$ points
in case v of
- [] -> visited
- _ -> go (visited ++ v) v
+ [] -> HS.toList visited
+ _ -> go (visited <> HS.fromList v) v
f :: (Int,Int) -> Bool
f p' = inRange (bounds m) p' && m ! p == m ! p'