-- Writeup at https://work.njae.me.uk/2022/12/19/advent-of-code-2022-day-18/
-import Debug.Trace
+-- import Debug.Trace
import AoC
import Prelude hiding (Left, Right)
import Control.Lens
import Data.Ix
import Data.Maybe
-import Data.List
import Data.Char
import Control.Monad.Reader
print $ part2 field instrs
-- print $ probeAllCorners field
+part1, part2 :: FieldMap -> [PathElement] -> Int
part1 fieldMap instrs = passwordOf endPerson
where field = mkFlatField fieldMap
startPos = V2 0 $ fromJust $ minimumOf (folded . filteredBy (_r . only 0) . _c) $ M.keysSet fieldMap
(Down, F) -> person & position . _r .~ 0 & position . _c .~ (interpol c 100 149)
(Left, F) -> person & position . _r .~ 0 & position . _c .~ (interpol r 50 99) & facing .~ Down
- otherwise -> error ("Crossing illegal boundary " ++ show (person, face))
-
where r = person ^. position . _r
c = person ^. position . _c
d = person ^. facing
| cell == '#' = Wall
where cell = (rows !! r) !! c
+isCell :: Int -> Int -> [String] -> Bool
isCell r c rows = isRow && isCol && ((rows !! r) !! c) `elem` (".#" :: String)
where isRow = r < length rows
isCol = c < (length $ rows !! r)