diff --git a/day06a/.gitignore b/day06a/.gitignore new file mode 100644 index 0000000..c368d45 --- /dev/null +++ b/day06a/.gitignore @@ -0,0 +1,2 @@ +.stack-work/ +*~ \ No newline at end of file diff --git a/day06a/day06a.cabal b/day06a/day06a.cabal new file mode 100644 index 0000000..7777392 --- /dev/null +++ b/day06a/day06a.cabal @@ -0,0 +1,27 @@ +cabal-version: 1.12 + +-- This file has been generated from package.yaml by hpack version 0.36.0. +-- +-- see: https://github.com/sol/hpack + +name: day06a +version: 0.1.0.0 +description: Please see the README at +author: Natty +maintainer: natty.sh.git@gmail.com +copyright: 2023 Natty +build-type: Simple + +executable day06a + main-is: Main.hs + other-modules: + Paths_day06a + hs-source-dirs: + src + ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wmissing-export-lists -Wmissing-home-modules -Wpartial-fields -Wredundant-constraints -threaded -rtsopts -with-rtsopts=-N + build-depends: + base >=4.7 && <5 + , containers + , megaparsec + , text + default-language: Haskell2010 diff --git a/day06a/input.txt b/day06a/input.txt new file mode 100644 index 0000000..f0187ef --- /dev/null +++ b/day06a/input.txt @@ -0,0 +1,2 @@ +Time: 58 99 64 69 +Distance: 478 2232 1019 1071 diff --git a/day06a/package.yaml b/day06a/package.yaml new file mode 100644 index 0000000..59c9b84 --- /dev/null +++ b/day06a/package.yaml @@ -0,0 +1,33 @@ +name: day06a +version: 0.1.0.0 +author: "Natty" +maintainer: "natty.sh.git@gmail.com" +copyright: "2023 Natty" + +description: Please see the README at + +dependencies: +- base >= 4.7 && < 5 +- megaparsec +- containers +- text + +ghc-options: +- -Wall +- -Wcompat +- -Widentities +- -Wincomplete-record-updates +- -Wincomplete-uni-patterns +- -Wmissing-export-lists +- -Wmissing-home-modules +- -Wpartial-fields +- -Wredundant-constraints + +executables: + day06a: + main: Main.hs + source-dirs: src + ghc-options: + - -threaded + - -rtsopts + - -with-rtsopts=-N \ No newline at end of file diff --git a/day06a/src/Main.hs b/day06a/src/Main.hs new file mode 100644 index 0000000..1a7bff8 --- /dev/null +++ b/day06a/src/Main.hs @@ -0,0 +1,26 @@ +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE ViewPatterns #-} +{-# LANGUAGE TypeApplications #-} +{-# LANGUAGE ScopedTypeVariables #-} + +module Main (main) where + +import qualified Data.Text as T +import Data.List ( transpose ) +import Data.Bifunctor (Bifunctor(bimap)) + +parseRace :: [T.Text] -> (Integer, Integer) +parseRace [read @Integer . T.unpack -> time, read @Integer . T.unpack -> dist] = (time, dist) +parseRace _ = error "Parse" + +main :: IO () +main = do + lns <- lines <$> getContents + print + $ product + $ (\(time, dist) -> (\x -> floor (time / 2 + x) - ceiling (time / 2 - x) + 1) . subtract 0.000001 . sqrt . subtract dist . (**2) . (/2) $ time) + <$> ((bimap (fromIntegral @_ @Double) (fromIntegral @_ @Double) + . parseRace <$>) + . drop 1 + . transpose + $ T.words . T.pack <$> lns) \ No newline at end of file diff --git a/day06a/stack.yaml b/day06a/stack.yaml new file mode 100644 index 0000000..887f541 --- /dev/null +++ b/day06a/stack.yaml @@ -0,0 +1,6 @@ +resolver: lts-21.21 + +packages: +- . + +extra-deps: [] \ No newline at end of file diff --git a/day06a/stack.yaml.lock b/day06a/stack.yaml.lock new file mode 100644 index 0000000..433950c --- /dev/null +++ b/day06a/stack.yaml.lock @@ -0,0 +1,12 @@ +# This file was autogenerated by Stack. +# You should not edit this file by hand. +# For more information, please see the documentation at: +# https://docs.haskellstack.org/en/stable/lock_files + +packages: [] +snapshots: +- completed: + sha256: 7d4b649cf368f9076d8aa049aa44efe58950971d105892734e9957b2a26a2186 + size: 640060 + url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/21/21.yaml + original: lts-21.21 diff --git a/day06a/test.txt b/day06a/test.txt new file mode 100644 index 0000000..28f5ae9 --- /dev/null +++ b/day06a/test.txt @@ -0,0 +1,2 @@ +Time: 7 15 30 +Distance: 9 40 200 diff --git a/day06b/.gitignore b/day06b/.gitignore new file mode 100644 index 0000000..c368d45 --- /dev/null +++ b/day06b/.gitignore @@ -0,0 +1,2 @@ +.stack-work/ +*~ \ No newline at end of file diff --git a/day06b/day06b.cabal b/day06b/day06b.cabal new file mode 100644 index 0000000..8c6b32d --- /dev/null +++ b/day06b/day06b.cabal @@ -0,0 +1,28 @@ +cabal-version: 1.12 + +-- This file has been generated from package.yaml by hpack version 0.36.0. +-- +-- see: https://github.com/sol/hpack + +name: day06b +version: 0.1.0.0 +description: Please see the README at +author: Natty +maintainer: natty.sh.git@gmail.com +copyright: 2023 Natty +build-type: Simple + +executable day06b + main-is: Main.hs + other-modules: + Paths_day06b + hs-source-dirs: + src + ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wmissing-export-lists -Wmissing-home-modules -Wpartial-fields -Wredundant-constraints -threaded -rtsopts -with-rtsopts=-N + build-depends: + base >=4.7 && <5 + , bifunctors + , containers + , megaparsec + , text + default-language: Haskell2010 diff --git a/day06b/input.txt b/day06b/input.txt new file mode 100644 index 0000000..f0187ef --- /dev/null +++ b/day06b/input.txt @@ -0,0 +1,2 @@ +Time: 58 99 64 69 +Distance: 478 2232 1019 1071 diff --git a/day06b/package.yaml b/day06b/package.yaml new file mode 100644 index 0000000..7eaad5c --- /dev/null +++ b/day06b/package.yaml @@ -0,0 +1,34 @@ +name: day06b +version: 0.1.0.0 +author: "Natty" +maintainer: "natty.sh.git@gmail.com" +copyright: "2023 Natty" + +description: Please see the README at + +dependencies: +- base >= 4.7 && < 5 +- megaparsec +- containers +- text +- bifunctors + +ghc-options: +- -Wall +- -Wcompat +- -Widentities +- -Wincomplete-record-updates +- -Wincomplete-uni-patterns +- -Wmissing-export-lists +- -Wmissing-home-modules +- -Wpartial-fields +- -Wredundant-constraints + +executables: + day06b: + main: Main.hs + source-dirs: src + ghc-options: + - -threaded + - -rtsopts + - -with-rtsopts=-N \ No newline at end of file diff --git a/day06b/src/Main.hs b/day06b/src/Main.hs new file mode 100644 index 0000000..9a9beef --- /dev/null +++ b/day06b/src/Main.hs @@ -0,0 +1,28 @@ +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE ViewPatterns #-} +{-# LANGUAGE TypeApplications #-} +{-# LANGUAGE ScopedTypeVariables #-} + +module Main (main) where + +import qualified Data.Text as T +import Data.List ( transpose ) +import Data.Bifunctor (Bifunctor(bimap)) + +parseRace :: [T.Text] -> (Integer, Integer) +parseRace [read @Integer . T.unpack -> time, read @Integer . T.unpack -> dist] = (time, dist) +parseRace _ = error "Parse" + +main :: IO () +main = do + lns <- lines <$> getContents + print + $ (\(time, dist) -> (\x -> floor (time / 2 + x) - ceiling (time / 2 - x) + 1) + . subtract 0.000001 + . sqrt + . subtract dist + . (**2) + . (/2) $ time) + . bimap (fromIntegral @_ @Double) (fromIntegral @_ @Double) + $ parseRace + $ T.concat <$> (transpose . drop 1 . transpose $ T.words . T.pack <$> lns) \ No newline at end of file diff --git a/day06b/stack.yaml b/day06b/stack.yaml new file mode 100644 index 0000000..887f541 --- /dev/null +++ b/day06b/stack.yaml @@ -0,0 +1,6 @@ +resolver: lts-21.21 + +packages: +- . + +extra-deps: [] \ No newline at end of file diff --git a/day06b/stack.yaml.lock b/day06b/stack.yaml.lock new file mode 100644 index 0000000..433950c --- /dev/null +++ b/day06b/stack.yaml.lock @@ -0,0 +1,12 @@ +# This file was autogenerated by Stack. +# You should not edit this file by hand. +# For more information, please see the documentation at: +# https://docs.haskellstack.org/en/stable/lock_files + +packages: [] +snapshots: +- completed: + sha256: 7d4b649cf368f9076d8aa049aa44efe58950971d105892734e9957b2a26a2186 + size: 640060 + url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/21/21.yaml + original: lts-21.21 diff --git a/day06b/test.txt b/day06b/test.txt new file mode 100644 index 0000000..28f5ae9 --- /dev/null +++ b/day06b/test.txt @@ -0,0 +1,2 @@ +Time: 7 15 30 +Distance: 9 40 200 diff --git a/run.sh b/run.sh index f001a03..fff2122 100755 --- a/run.sh +++ b/run.sh @@ -24,7 +24,8 @@ case "$1" in "day01a" | "day01b" | \ "day02a" | "day02b" | \ "day03a" | "day03b" | \ - "day04a" | "day04b") stack run