2023 day01

This commit is contained in:
Gattix 2023-12-01 15:35:18 +01:00
parent 43c3c7311a
commit a0601460be
4 changed files with 1031 additions and 0 deletions

20
2023/day01/day01.hs Normal file
View 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

File diff suppressed because it is too large Load Diff

4
2023/day01/testinput Normal file
View File

@ -0,0 +1,4 @@
1abc2
pqr3stu8vwx
a1b2c3d4e5f
treb7uchet

7
2023/day01/testinput2 Normal file
View File

@ -0,0 +1,7 @@
two1nine
eightwothree
abcone2threexyz
xtwone3four
4nineeightseven2
zoneight234
7pqrstsixteen