Skip to content

Commit

Permalink
make foldl strict
Browse files Browse the repository at this point in the history
  • Loading branch information
amogh09 committed Sep 26, 2020
1 parent 8ee91ef commit c1d19f4
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions epi_judge_haskell_solutions/absentValueArray.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Data.Bits
import Data.List (foldl')
import TestFramework.TestRunner

nbits :: Int
Expand All @@ -8,9 +9,9 @@ isBitClear :: Int -> Int -> Int
isBitClear n x = if x .&. (1 `shiftL` (nbits - n - 1)) == 0 then 1 else 0

findMissingElement :: [Int] -> Int
findMissingElement = snd . foldl f (0,0) . replicate nbits where
findMissingElement = snd . foldl' f (0,0) . replicate nbits where
f (n,x) xs =
if foldl g 0 xs == 1 `shiftL` (nbits-n-1)
if foldl' g 0 xs == 1 `shiftL` (nbits-n-1)
then (n+1, setBit x $ nbits - n - 1)
else (n+1, x)
where
Expand Down

0 comments on commit c1d19f4

Please sign in to comment.