haskell: 2015 01

This commit is contained in:
Maciej Jur 2023-10-09 20:44:52 +02:00
parent 19806663a7
commit e79d03a7d9
Signed by: kamov
GPG key ID: 191CBFF5F72ECAFD
7 changed files with 121 additions and 0 deletions

1
2015/.inputs/01.txt Normal file

File diff suppressed because one or more lines are too long

23
2015/haskell/.gitignore vendored Normal file
View file

@ -0,0 +1,23 @@
dist
dist-*
cabal-dev
*.o
*.hi
*.hie
*.chi
*.chs.h
*.dyn_o
*.dyn_hi
.hpc
.hsenv
.cabal-sandbox/
cabal.sandbox.config
*.prof
*.aux
*.hp
*.eventlog
.stack-work/
cabal.project.local
cabal.project.local~
.HTF/
.ghc.environment.*

View file

@ -0,0 +1,5 @@
# Revision history for haskell
## 0.1.0.0 -- YYYY-mm-dd
* First version. Released on an unsuspecting world.

18
2015/haskell/app/Main.hs Normal file
View file

@ -0,0 +1,18 @@
module Main where
import Text.Printf (printf)
import qualified Day01
readDay :: Int -> IO String
readDay n = readFile $ getPath n
where
getPath n = "../.inputs/" <> printf "%02d" n <> ".txt"
main :: IO ()
main = do
content <- readDay 1
let parsed = Day01.parse content
print $ Day01.solve1 parsed
print $ Day01.solve2 parsed

View file

@ -0,0 +1,46 @@
cabal-version: 3.0
name: haskell
version: 0.1.0.0
synopsis: Advent of Code 2015 solutions
-- A longer description of the package.
-- description:
homepage:
-- A URL where users can report bugs.
-- bug-reports:
license: MIT
author: Maciej Jur
maintainer: maciej@kamoshi.org
-- A copyright notice.
-- copyright:
-- category:
extra-source-files: CHANGELOG.md
library
exposed-modules: Day01
-- Modules included in this library but not exported.
-- other-modules:
-- LANGUAGE extensions used by modules in this package.
-- other-extensions:
build-depends: base ^>=4.16.4.0
hs-source-dirs: src
default-language: Haskell2010
executable haskell
main-is: Main.hs
-- Modules included in this executable, other than Main.
-- other-modules:
-- LANGUAGE extensions used by modules in this package.
-- other-extensions:
build-depends:
base ^>=4.16.4.0,
haskell
hs-source-dirs: app
default-language: Haskell2010

24
2015/haskell/src/Day01.hs Normal file
View file

@ -0,0 +1,24 @@
module Day01 (parse, solve1, solve2) where
import Data.Char (isPrint)
import Data.List (scanl, findIndex)
import Data.Maybe (fromJust)
parse :: String -> String
parse = filter isPrint
mapper :: Char -> Int
mapper c = case c of
'(' -> 1
')' -> -1
_ -> undefined
solve1 :: String -> Int
solve1 = sum . map mapper
solve2 :: String -> Int
solve2 = fromJust . findIndex (<0) . scanl reducer 0
where
reducer acc next = acc + mapper next

View file

@ -0,0 +1,4 @@
module MyLib (someFunc) where
someFunc :: IO ()
someFunc = putStrLn "someFunc"