2023 day01
This commit is contained in:
parent
43c3c7311a
commit
a0601460be
20
2023/day01/day01.hs
Normal file
20
2023/day01/day01.hs
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
|
import Data.Char
|
||||||
|
import Control.Arrow
|
||||||
|
import qualified Data.Text as T
|
||||||
|
|
||||||
|
|
||||||
|
main :: IO ()
|
||||||
|
main = do
|
||||||
|
let nums = [("one", "o1ne"), ("two", "t2wo"), ("three", "th3ree"), ("four", "fo4ur"), ("five", "fi5ve"), ("six", "si6x"), ("seven", "se7ven"), ("eight", "eig8ht"), ("nine", "ni9ne")]
|
||||||
|
input <- init . T.splitOn "\n" . T.pack <$> readFile "input"
|
||||||
|
print $ day1a input
|
||||||
|
print $ day1a $ day1b input nums
|
||||||
|
|
||||||
|
day1a :: [T.Text] -> Int
|
||||||
|
day1a = sum . map ((T.head &&& T.last >>> (\(x, y) -> read [x,y])) . T.filter isDigit)
|
||||||
|
|
||||||
|
day1b :: [T.Text] -> [(T.Text,T.Text)] -> [T.Text]
|
||||||
|
day1b txt nums = map numfold txt
|
||||||
|
where rep z (x,y) = T.replace x y z
|
||||||
|
numfold x = foldl rep x nums
|
1000
2023/day01/input
Normal file
1000
2023/day01/input
Normal file
File diff suppressed because it is too large
Load Diff
4
2023/day01/testinput
Normal file
4
2023/day01/testinput
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
1abc2
|
||||||
|
pqr3stu8vwx
|
||||||
|
a1b2c3d4e5f
|
||||||
|
treb7uchet
|
7
2023/day01/testinput2
Normal file
7
2023/day01/testinput2
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
two1nine
|
||||||
|
eightwothree
|
||||||
|
abcone2threexyz
|
||||||
|
xtwone3four
|
||||||
|
4nineeightseven2
|
||||||
|
zoneight234
|
||||||
|
7pqrstsixteen
|
Loading…
Reference in New Issue
Block a user