day2
This commit is contained in:
parent
bf2354d2ee
commit
ef0c56b784
13
2021/day02/day02.hs
Normal file
13
2021/day02/day02.hs
Normal file
@ -0,0 +1,13 @@
|
||||
import Control.Arrow
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
input <- map (head . words &&& read . flip (:) [] . last) <$> lines <$> readFile "input"
|
||||
print $ (\(x,y,z,d2) -> (x*y,x*d2)) $ day2 input (0,0,0,0)
|
||||
|
||||
day2 :: [(String,Int)] -> (Int,Int,Int,Int) -> (Int,Int,Int,Int)
|
||||
day2 ((d,l):xs) (x,y,z,d2)
|
||||
| d=="forward" = day2 xs (x+l,y,z,d2+l*z)
|
||||
| d=="up" = day2 xs (x,y-l,z-l,d2)
|
||||
| d=="down" = day2 xs (x,y+l,z+l,d2)
|
||||
day2 [] x = x
|
1000
2021/day02/input
Normal file
1000
2021/day02/input
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user