projects
/
advent-of-code-20.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
76f4612
)
Tweaking for clarity
author
Neil Smith
<neil.git@njae.me.uk>
Wed, 23 Dec 2020 11:25:10 +0000
(11:25 +0000)
committer
Neil Smith
<neil.git@njae.me.uk>
Wed, 23 Dec 2020 11:25:10 +0000
(11:25 +0000)
advent14/src/advent14.hs
patch
|
blob
|
history
diff --git
a/advent14/src/advent14.hs
b/advent14/src/advent14.hs
index d03b33f6309c946c9b506f3f6705063d507eb952..b6343a4b54be52281c05e235a635b670a0e66a2c 100644
(file)
--- a/
advent14/src/advent14.hs
+++ b/
advent14/src/advent14.hs
@@
-26,7
+26,7
@@
data Machine = Machine { mMemory :: Memory
, mMask1 :: Int64
} deriving (Show, Eq)
, mMask1 :: Int64
} deriving (Show, Eq)
-em
tp
yMachine = Machine M.empty M.empty (complement 0) 0
+em
pt
yMachine = Machine M.empty M.empty (complement 0) 0
main :: IO ()
main :: IO ()
@@
-44,8
+44,9
@@
part2 program = sum $ M.elems $ mMemory finalMachine
where finalMachine = executeInstructions2 program
executeInstructions1 instructions =
where finalMachine = executeInstructions2 program
executeInstructions1 instructions =
- foldl' executeInstruction1 em
tp
yMachine instructions
+ foldl' executeInstruction1 em
pt
yMachine instructions
+executeInstruction1 :: Machine -> Instruction -> Machine
executeInstruction1 machine (Mask mask) = makeMask machine mask
executeInstruction1 machine (Assignment loc value) =
assignValue machine loc value
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
where ones = M.keys $ M.filter (== One) mask
maskZeroes :: MaskMap -> Int64
-maskZeroes mask =
complement $ foldl' setBit zeroBits on
es
- where
on
es = M.keys $ M.filter (== Zero) mask
+maskZeroes mask =
foldl' clearBit (complement zeroBits) zero
es
+ where
zero
es = M.keys $ M.filter (== Zero) mask
executeInstructions2 instructions =
executeInstructions2 instructions =
- foldl' executeInstruction2 em
tp
yMachine instructions
+ foldl' executeInstruction2 em
pt
yMachine 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
executeInstruction2 machine (Mask mask) = machine {mMask = mask}
executeInstruction2 machine (Assignment loc value) = machine {mMemory = mem'}
where locs = map encodeMask $ applyAddressMask (mMask machine) $ decodeMask loc