projects
/
advent-of-code-22.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
88d1ab0
)
Tidying
author
Neil Smith
<NeilNjae@users.noreply.github.com>
Thu, 22 Dec 2022 22:52:44 +0000
(22:52 +0000)
committer
Neil Smith
<NeilNjae@users.noreply.github.com>
Thu, 22 Dec 2022 22:52:44 +0000
(22:52 +0000)
advent22/Main.hs
patch
|
blob
|
history
diff --git
a/advent22/Main.hs
b/advent22/Main.hs
index 17f66898e93c286d9438e42dd3656f3f718c5a36..1a2e1c7eb67281b52f3c35f3a3564f77ca5d2bb3 100644
(file)
--- a/
advent22/Main.hs
+++ b/
advent22/Main.hs
@@
-1,6
+1,6
@@
-- Writeup at https://work.njae.me.uk/2022/12/19/advent-of-code-2022-day-18/
-- 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 AoC
import Prelude hiding (Left, Right)
@@
-10,7
+10,6
@@
import Linear hiding (E)
import Control.Lens
import Data.Ix
import Data.Maybe
import Control.Lens
import Data.Ix
import Data.Maybe
-import Data.List
import Data.Char
import Control.Monad.Reader
import Data.Char
import Control.Monad.Reader
@@
-62,6
+61,7
@@
main =
print $ part2 field instrs
-- print $ probeAllCorners field
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
part1 fieldMap instrs = passwordOf endPerson
where field = mkFlatField fieldMap
startPos = V2 0 $ fromJust $ minimumOf (folded . filteredBy (_r . only 0) . _c) $ M.keysSet fieldMap
@@
-199,8
+199,6
@@
crossEdge person face =
(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
(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
where r = person ^. position . _r
c = person ^. position . _c
d = person ^. facing
@@
-250,6
+248,7
@@
mkField rows = M.fromList
| cell == '#' = Wall
where cell = (rows !! r) !! c
| 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)
isCell r c rows = isRow && isCol && ((rows !! r) !! c) `elem` (".#" :: String)
where isRow = r < length rows
isCol = c < (length $ rows !! r)