2023 day 1: touchup

This commit is contained in:
eriedaberrie 2023-12-02 20:30:03 -08:00
parent d598c40185
commit ce72d1e8bc
2 changed files with 5 additions and 3 deletions

2
.gitignore vendored
View file

@ -1,2 +1,4 @@
*.fasl *.fasl
*.o
*.hi
data.txt data.txt

View file

@ -2,7 +2,7 @@ import Data.Char (isDigit, digitToInt)
import Data.Function (on) import Data.Function (on)
import Data.List (tails, findIndex, isPrefixOf, minimumBy) import Data.List (tails, findIndex, isPrefixOf, minimumBy)
import Data.Maybe (mapMaybe) import Data.Maybe (mapMaybe)
import Data.Bifunctor (first) import Data.Bifunctor (first, bimap)
type LineOp = String -> Int type LineOp = String -> Int
@ -31,8 +31,8 @@ firstNumInLine l = fst . minimumBy (compare `on` snd) . mapMaybe numIndex
opLineAdvanced :: LineOp opLineAdvanced :: LineOp
opLineAdvanced l = (combineDigits `on` uncurry firstNumInLine) opLineAdvanced l = (combineDigits `on` uncurry firstNumInLine)
(l, fullWordMap) <*> bimap reverse (map $ first reverse)
(reverse l, first reverse <$> fullWordMap) $ (l, fullWordMap)
combineDigits :: Int -> Int -> Int combineDigits :: Int -> Int -> Int
combineDigits = (+) . (10 *) combineDigits = (+) . (10 *)