Day 5: Cleanup & golf for now, might document later

This commit is contained in:
shu 2019-12-06 01:20:37 +01:00
parent dd2bf86d1c
commit 799b000b39

View File

@ -9,15 +9,6 @@ main = do
let input = fromList $ L.concatMap (L.map read . splitOn ",") (lines content)
exec_step (input,0)
day5 :: Vector Int -> Vector Int
day5 x = V.take 20 x
type Tape = Vector Int
type TapeSection = Vector Int
type Pointer = Int
type TuringMachine = (Tape, Pointer)
opl x
| n`L.elem`"1278"=4
| n`L.elem`"56"=3
@ -29,17 +20,14 @@ parsemodes :: String -> [Bool]
parsemodes m = L.replicate (3 - L.length l) False L.++ l
where l = L.map (toEnum . digitToInt) m
paramch :: [Bool] -> TapeSection -> Tape -> TapeSection
paramch m opvec t = imap f (V.tail opvec)
where f i a = if (L.reverse m) !! i then a else t ! a
getopmodes opvec = (op_dedup,parsed_modes)
where (op,modes) = L.splitAt 2 $ L.reverse $ show $ opvec ! 0
parsed_modes = parsemodes $ L.reverse modes
op_dedup = if L.last op == '0' then [L.head op] else op
step opvec (t,p) = do
let (op,m) = getopmodes opvec
input <- if op=="3"
@ -65,7 +53,6 @@ step opvec (t,p) = do
return newtm
exec_step (t,p) = do
let command_length = opl $ t ! p
let opvec = slice p command_length t