Why doesn't part 2 work?
This commit is contained in:
24
aoc.cabal
24
aoc.cabal
@ -20,7 +20,7 @@ executable 1
|
||||
main-is: 1.hs
|
||||
-- other-modules:
|
||||
-- other-extensions:
|
||||
build-depends: base ^>=4.18.2.1
|
||||
build-depends: base ^>=4.21.0.0
|
||||
hs-source-dirs: app
|
||||
default-language: GHC2021
|
||||
|
||||
@ -29,7 +29,7 @@ executable 2
|
||||
main-is: 2.hs
|
||||
-- other-modules:
|
||||
-- other-extensions:
|
||||
build-depends: base ^>=4.18.2.1
|
||||
build-depends: base ^>=4.21.0.0
|
||||
hs-source-dirs: app
|
||||
default-language: GHC2021
|
||||
executable 3
|
||||
@ -37,7 +37,7 @@ executable 3
|
||||
main-is: 3.hs
|
||||
-- other-modules:
|
||||
-- other-extensions:
|
||||
build-depends: base ^>=4.18.2.1
|
||||
build-depends: base ^>=4.21.0.0
|
||||
hs-source-dirs: app
|
||||
default-language: GHC2021
|
||||
executable 4
|
||||
@ -45,7 +45,7 @@ executable 4
|
||||
main-is: 4.hs
|
||||
-- other-modules:
|
||||
-- other-extensions:
|
||||
build-depends: base ^>=4.18.2.1
|
||||
build-depends: base ^>=4.21.0.0
|
||||
hs-source-dirs: app
|
||||
default-language: GHC2021
|
||||
executable 5
|
||||
@ -53,7 +53,7 @@ executable 5
|
||||
main-is: 5.hs
|
||||
-- other-modules:
|
||||
-- other-extensions:
|
||||
build-depends: base ^>=4.18.2.1
|
||||
build-depends: base ^>=4.21.0.0
|
||||
hs-source-dirs: app
|
||||
default-language: GHC2021
|
||||
executable 6
|
||||
@ -61,7 +61,7 @@ executable 6
|
||||
main-is: 6.hs
|
||||
-- other-modules:
|
||||
-- other-extensions:
|
||||
build-depends: base ^>=4.18.2.1
|
||||
build-depends: base ^>=4.21.0.0
|
||||
hs-source-dirs: app
|
||||
default-language: GHC2021
|
||||
executable 7
|
||||
@ -69,7 +69,7 @@ executable 7
|
||||
main-is: 7.hs
|
||||
-- other-modules:
|
||||
-- other-extensions:
|
||||
build-depends: base ^>=4.18.2.1
|
||||
build-depends: base ^>=4.21.0.0
|
||||
hs-source-dirs: app
|
||||
default-language: GHC2021
|
||||
executable 8
|
||||
@ -77,7 +77,7 @@ executable 8
|
||||
main-is: 8.hs
|
||||
-- other-modules:
|
||||
-- other-extensions:
|
||||
build-depends: base ^>=4.18.2.1
|
||||
build-depends: base ^>=4.21.0.0
|
||||
hs-source-dirs: app
|
||||
default-language: GHC2021
|
||||
executable 9
|
||||
@ -85,7 +85,7 @@ executable 9
|
||||
main-is: 9.hs
|
||||
-- other-modules:
|
||||
-- other-extensions:
|
||||
build-depends: base ^>=4.18.2.1
|
||||
build-depends: base ^>=4.21.0.0
|
||||
hs-source-dirs: app
|
||||
default-language: GHC2021
|
||||
executable 10
|
||||
@ -93,7 +93,7 @@ executable 10
|
||||
main-is: 10.hs
|
||||
-- other-modules:
|
||||
-- other-extensions:
|
||||
build-depends: base ^>=4.18.2.1
|
||||
build-depends: base ^>=4.21.0.0
|
||||
hs-source-dirs: app
|
||||
default-language: GHC2021
|
||||
executable 11
|
||||
@ -101,7 +101,7 @@ executable 11
|
||||
main-is: 11.hs
|
||||
-- other-modules:
|
||||
-- other-extensions:
|
||||
build-depends: base ^>=4.18.2.1
|
||||
build-depends: base ^>=4.21.0.0
|
||||
hs-source-dirs: app
|
||||
default-language: GHC2021
|
||||
executable 12
|
||||
@ -109,6 +109,6 @@ executable 12
|
||||
main-is: 12.hs
|
||||
-- other-modules:
|
||||
-- other-extensions:
|
||||
build-depends: base ^>=4.18.2.1
|
||||
build-depends: base ^>=4.21.0.0
|
||||
hs-source-dirs: app
|
||||
default-language: GHC2021
|
||||
|
||||
37
app/1.hs
37
app/1.hs
@ -1,6 +1,41 @@
|
||||
{-# LANGUAGE LambdaCase #-}
|
||||
{-# LANGUAGE MultiWayIf #-}
|
||||
module Main where
|
||||
|
||||
import Data.Functor
|
||||
|
||||
data Rotation where
|
||||
RRight :: Int -> Rotation
|
||||
RLeft :: Int -> Rotation
|
||||
|
||||
parse :: String -> [Rotation]
|
||||
parse = map (\case
|
||||
('R':xs) -> RRight (read xs :: Int)
|
||||
('L':xs) -> RLeft (read xs :: Int)
|
||||
_ -> error "") . lines
|
||||
|
||||
solver :: Bool -> [Rotation] -> Int
|
||||
solver b = go 50
|
||||
where go :: Int -> [Rotation] -> Int
|
||||
go _ [] = 0
|
||||
go curr (RRight n : xs) =
|
||||
let (rots,newCurr) = bound (curr + n) in
|
||||
(if | b -> (rots+)
|
||||
| newCurr == 0 -> (1+)
|
||||
| otherwise -> id) $ go newCurr xs
|
||||
go curr (RLeft n : xs) =
|
||||
let (rots,newCurr) = bound (curr - n) in
|
||||
(if | b -> (rots+)
|
||||
| newCurr == 0 -> (1+)
|
||||
| otherwise -> id) $ go newCurr xs
|
||||
|
||||
bound :: Int -> (Int,Int)
|
||||
bound x
|
||||
| x < 0 = (\(n,y) -> (n+1,y)) . bound $ x + 100
|
||||
| x > 99 = (\(n,y) -> (n+1,y)) . bound $ x - 100
|
||||
| otherwise = (0, x)
|
||||
|
||||
main :: IO ()
|
||||
main = pure ()
|
||||
main = readFile "inputs/1" <&> parse >>= \i ->
|
||||
print (solver False i) >>
|
||||
print (solver True i)
|
||||
|
||||
Reference in New Issue
Block a user