X-Git-Url: https://git.njae.me.uk/?p=advent-of-code-20.git;a=blobdiff_plain;f=advent14%2Fsrc%2Fadvent14.hs;fp=advent14%2Fsrc%2Fadvent14.hs;h=b6343a4b54be52281c05e235a635b670a0e66a2c;hp=d03b33f6309c946c9b506f3f6705063d507eb952;hb=60f781a177b4c92193f0fca095816c8ca883c1c4;hpb=76f46123c958f2bb5ca05148c30b41fb9c5a613c

diff --git a/advent14/src/advent14.hs b/advent14/src/advent14.hs
index d03b33f..b6343a4 100644
--- a/advent14/src/advent14.hs
+++ b/advent14/src/advent14.hs
@@ -26,7 +26,7 @@ data Machine = Machine { mMemory :: Memory
                        , mMask1 :: Int64
                        } deriving (Show, Eq)
 
-emtpyMachine = Machine M.empty M.empty (complement 0) 0
+emptyMachine = Machine M.empty M.empty (complement 0) 0
 
 
 main :: IO ()
@@ -44,8 +44,9 @@ part2 program = sum $ M.elems $ mMemory finalMachine
   where finalMachine = executeInstructions2 program
 
 executeInstructions1 instructions = 
-  foldl' executeInstruction1 emtpyMachine instructions
+  foldl' executeInstruction1 emptyMachine instructions
 
+executeInstruction1 :: Machine -> Instruction -> Machine
 executeInstruction1 machine (Mask mask) = makeMask machine mask
 executeInstruction1 machine (Assignment loc value) = 
   assignValue machine loc value
@@ -66,13 +67,14 @@ maskOnes mask = foldl' setBit zeroBits ones
   where ones = M.keys $ M.filter (== One) mask
 
 maskZeroes :: MaskMap -> Int64
-maskZeroes mask = complement $ foldl' setBit zeroBits ones
-  where ones = M.keys $ M.filter (== Zero) mask
+maskZeroes mask = foldl' clearBit (complement zeroBits) zeroes
+  where zeroes = M.keys $ M.filter (== Zero) mask
 
 
 executeInstructions2 instructions = 
-  foldl' executeInstruction2 emtpyMachine instructions
+  foldl' executeInstruction2 emptyMachine instructions
 
+executeInstruction2 :: Machine -> Instruction -> Machine
 executeInstruction2 machine (Mask mask) = machine {mMask = mask}
 executeInstruction2 machine (Assignment loc value) = machine {mMemory = mem'}
   where locs = map encodeMask $ applyAddressMask (mMask machine) $ decodeMask loc