day14/haskell: replace map-filter-enumerate with findIndices

This commit is contained in:
Xiretza 2020-12-16 17:55:22 +01:00
parent 5cbd457ebc
commit d99efc09fe
Signed by: xiretza
GPG key ID: 17B78226F7139993

View file

@ -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'