Day 6
This commit is contained in:
parent
799b000b39
commit
d09b565d9c
|
@ -0,0 +1,21 @@
|
|||
import Data.List.Split
|
||||
import Data.List
|
||||
import Data.Maybe
|
||||
|
||||
main = do
|
||||
content <- (map (splitOn ")") . lines) <$> readFile "input"
|
||||
print $ day6a content
|
||||
print $ day6b content
|
||||
|
||||
day6a l = sum $ map (day6a' (transpose l) l) l
|
||||
day6a' l l2 (s:t)
|
||||
| s `elem` (l!!1)=1+day6a' l l2 (l2 !! (fromJust (elemIndex s (l!!1))))
|
||||
| otherwise=1
|
||||
|
||||
day6b :: [[String]] -> Int
|
||||
day6b l = day6b' l "YOU" "SAN" [] - 2
|
||||
day6b' l s t visited
|
||||
| [s,t]`elem`l||[t,s]`elem`l=1
|
||||
| otherwise = 1 + minimum [if x `elem` visited then maxBound -1 else day6b' l x t (x:visited)| x<-neighbours s]
|
||||
where neighbours a = filter (/=a) $ concat
|
||||
[if x==a then xs else [] | xs<-l, x<-xs]
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user