2023 day 1: touchup
This commit is contained in:
parent
d598c40185
commit
ce72d1e8bc
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,2 +1,4 @@
|
|||
*.fasl
|
||||
*.o
|
||||
*.hi
|
||||
data.txt
|
|
@ -2,7 +2,7 @@ import Data.Char (isDigit, digitToInt)
|
|||
import Data.Function (on)
|
||||
import Data.List (tails, findIndex, isPrefixOf, minimumBy)
|
||||
import Data.Maybe (mapMaybe)
|
||||
import Data.Bifunctor (first)
|
||||
import Data.Bifunctor (first, bimap)
|
||||
|
||||
type LineOp = String -> Int
|
||||
|
||||
|
@ -31,8 +31,8 @@ firstNumInLine l = fst . minimumBy (compare `on` snd) . mapMaybe numIndex
|
|||
|
||||
opLineAdvanced :: LineOp
|
||||
opLineAdvanced l = (combineDigits `on` uncurry firstNumInLine)
|
||||
(l, fullWordMap)
|
||||
(reverse l, first reverse <$> fullWordMap)
|
||||
<*> bimap reverse (map $ first reverse)
|
||||
$ (l, fullWordMap)
|
||||
|
||||
combineDigits :: Int -> Int -> Int
|
||||
combineDigits = (+) . (10 *)
|
||||
|
|
Loading…
Reference in a new issue