From 799b000b39d0ddc9e0b449541d67e704ebe2fca4 Mon Sep 17 00:00:00 2001 From: shu Date: Fri, 6 Dec 2019 01:20:37 +0100 Subject: [PATCH] Day 5: Cleanup & golf for now, might document later --- 2019/day5/day5.hs | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/2019/day5/day5.hs b/2019/day5/day5.hs index 82fdfdf..9868f9d 100644 --- a/2019/day5/day5.hs +++ b/2019/day5/day5.hs @@ -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