2023 day 1: touchup
This commit is contained in:
parent
d598c40185
commit
ce72d1e8bc
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,2 +1,4 @@
|
||||||
*.fasl
|
*.fasl
|
||||||
|
*.o
|
||||||
|
*.hi
|
||||||
data.txt
|
data.txt
|
|
@ -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 *)
|
||||||
|
|
Loading…
Reference in a new issue