day14/haskell: replace map-filter-enumerate with findIndices
This commit is contained in:
parent
5cbd457ebc
commit
d99efc09fe
1 changed files with 2 additions and 1 deletions
|
@ -5,6 +5,7 @@ module Day14 where
|
||||||
import AoC
|
import AoC
|
||||||
|
|
||||||
import Data.Bits
|
import Data.Bits
|
||||||
|
import Data.List
|
||||||
import Data.Map (Map)
|
import Data.Map (Map)
|
||||||
import qualified Data.Map as M
|
import qualified Data.Map as M
|
||||||
import Data.Maybe
|
import Data.Maybe
|
||||||
|
@ -26,7 +27,7 @@ parseMaskDecl :: ReadP Mask
|
||||||
parseMaskDecl = do
|
parseMaskDecl = do
|
||||||
string "mask = "
|
string "mask = "
|
||||||
mask <- many1 (choice $ char <$> "01X")
|
mask <- many1 (choice $ char <$> "01X")
|
||||||
let extractMask c = foldl setBit zeroBits . map fst . filter ((==c) . snd) . enumerate 0 . reverse $ mask
|
let extractMask c = foldl setBit zeroBits . findIndices (==c) . reverse $ mask
|
||||||
return $ Mask { set = extractMask '1'
|
return $ Mask { set = extractMask '1'
|
||||||
, clear = extractMask '0'
|
, clear = extractMask '0'
|
||||||
, dontcare = extractMask 'X'
|
, dontcare = extractMask 'X'
|
||||||
|
|
Loading…
Reference in a new issue