Day 1!
This commit is contained in:
parent
6e39ba603f
commit
9ead1c5786
1
2023/.gitignore
vendored
Normal file
1
2023/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
dist-newstyle/
|
5
2023/CHANGELOG.md
Normal file
5
2023/CHANGELOG.md
Normal file
@ -0,0 +1,5 @@
|
||||
# Revision history for x2023
|
||||
|
||||
## 0.1.0.0 -- YYYY-mm-dd
|
||||
|
||||
* First version. Released on an unsuspecting world.
|
1000
2023/app/Day1-input.txt
Normal file
1000
2023/app/Day1-input.txt
Normal file
File diff suppressed because it is too large
Load Diff
34
2023/app/Day1.hs
Normal file
34
2023/app/Day1.hs
Normal file
@ -0,0 +1,34 @@
|
||||
module Day1 where
|
||||
import System.IO
|
||||
import Data.List
|
||||
import Data.Char
|
||||
import Data.Maybe
|
||||
import Data.List.Extra
|
||||
|
||||
getFirstInt :: String -> Int
|
||||
getFirstInt xs = read $ singleton $ fromMaybe '0' $ find isDigit xs
|
||||
|
||||
restoreLine :: String -> Int
|
||||
restoreLine l = 10 * getFirstInt l + getFirstInt (reverse l)
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
handle <- openFile "app/Day1-input.txt" ReadMode
|
||||
input <- hGetContents handle
|
||||
|
||||
putStr "Part 1: "
|
||||
print $ sum $ map restoreLine (words input)
|
||||
|
||||
putStr "Part 2: "
|
||||
print $ sum $ map restoreLine $ words
|
||||
$ replace "zero" "z0o"
|
||||
$ replace "one" "o1e"
|
||||
$ replace "two" "t2o"
|
||||
$ replace "three" "t3e"
|
||||
$ replace "four" "f4r"
|
||||
$ replace "five" "f5e"
|
||||
$ replace "six" "s6x"
|
||||
$ replace "seven" "s7n"
|
||||
$ replace "eight" "e8t"
|
||||
$ replace "nine" "n9e" input
|
||||
pure ()
|
6
2023/app/Main.hs
Normal file
6
2023/app/Main.hs
Normal file
@ -0,0 +1,6 @@
|
||||
module Main where
|
||||
|
||||
import Day1
|
||||
|
||||
main :: IO ()
|
||||
main = Day1.main
|
38
2023/x2023.cabal
Normal file
38
2023/x2023.cabal
Normal file
@ -0,0 +1,38 @@
|
||||
cabal-version: 2.4
|
||||
name: x2023
|
||||
version: 0.1.0.0
|
||||
|
||||
-- A short (one-line) description of the package.
|
||||
-- synopsis:
|
||||
|
||||
-- A longer description of the package.
|
||||
-- description:
|
||||
|
||||
-- A URL where users can report bugs.
|
||||
-- bug-reports:
|
||||
|
||||
-- The license under which the package is released.
|
||||
-- license:
|
||||
|
||||
-- The package author(s).
|
||||
-- author:
|
||||
|
||||
-- An email address to which users can send suggestions, bug reports, and patches.
|
||||
-- maintainer:
|
||||
|
||||
-- A copyright notice.
|
||||
-- copyright:
|
||||
-- category:
|
||||
extra-source-files: CHANGELOG.md
|
||||
|
||||
executable x2023
|
||||
main-is: Main.hs
|
||||
|
||||
-- Modules included in this executable, other than Main.
|
||||
other-modules: Day1
|
||||
|
||||
-- LANGUAGE extensions used by modules in this package.
|
||||
-- other-extensions:
|
||||
build-depends: base ^>=4.16.4.0, extra
|
||||
hs-source-dirs: app
|
||||
default-language: Haskell2010
|
Loading…
Reference in New Issue
Block a user