Part 1 of part1 is working
This commit is contained in:
parent
ad0be8ffaa
commit
415511204a
44
day5.hs
44
day5.hs
|
@ -1,9 +1,10 @@
|
||||||
import Data.List.Split
|
import Data.List.Split
|
||||||
|
|
||||||
main = do
|
main = do
|
||||||
content <- getList <$> getContents
|
let state = [3,0,4,0,99]
|
||||||
let input = changeInput content 12 2
|
let input = [83]
|
||||||
putStrLn (show (compute input input 0))
|
let output = operation state state 0 input []
|
||||||
|
mapM putStrLn (map show output)
|
||||||
|
|
||||||
getList :: String -> [Int]
|
getList :: String -> [Int]
|
||||||
getList = map read . splitOn ","
|
getList = map read . splitOn ","
|
||||||
|
@ -14,12 +15,12 @@ changeInput (begin:_:_:input) input1 input2= [begin] ++ [input1] ++ [input2] ++
|
||||||
func :: [Int] -> Int -> Int -> Int
|
func :: [Int] -> Int -> Int -> Int
|
||||||
func xs x y = do
|
func xs x y = do
|
||||||
let input = changeInput xs x y
|
let input = changeInput xs x y
|
||||||
head (compute input input 0)
|
head (compute input input 0 [] [] )
|
||||||
|
|
||||||
compute :: [Int] -> [Int] -> Int -> [Int]
|
compute :: [Int] -> [Int] -> Int -> [Int] -> [Int] -> [Int]
|
||||||
compute (99:_) state index = state
|
compute (99:_) state index input output = output
|
||||||
compute (op:x:y:z:_) state index =
|
compute (op:x:y:z:_) state index input output=
|
||||||
compute (drop newindex state) newstate newindex
|
compute (drop newindex state) newstate newindex input output
|
||||||
where
|
where
|
||||||
sum = if op == 1 then
|
sum = if op == 1 then
|
||||||
(state !! x) + (state !! y)
|
(state !! x) + (state !! y)
|
||||||
|
@ -29,28 +30,35 @@ compute (op:x:y:z:_) state index =
|
||||||
newstate = (fst split) ++ [sum] ++ (drop 1 (snd split))
|
newstate = (fst split) ++ [sum] ++ (drop 1 (snd split))
|
||||||
newindex = index + 4
|
newindex = index + 4
|
||||||
|
|
||||||
operation :: [Int] -> [Int] -> Int -> [Int]
|
operation :: [Int] -> [Int] -> Int -> [Int] -> [Int] -> [Int]
|
||||||
operation (1:x:y:z:_) state index = operation (drop newindex state) newstate newindex
|
operation (99:_) state index input output =
|
||||||
|
output
|
||||||
|
operation (1:x:y:z:_) state index input output =
|
||||||
|
operation (drop newindex state) newstate newindex input output
|
||||||
where
|
where
|
||||||
sum = (state !! x) + (state !! y)
|
sum = (state !! x) + (state !! y)
|
||||||
split = splitAt z state
|
split = splitAt z state
|
||||||
newstate = (fst split) ++ [sum] ++ (drop 1(snd split))
|
newstate = (fst split) ++ [sum] ++ (drop 1(snd split))
|
||||||
newindex = index + 4
|
newindex = index + 4
|
||||||
operation (2:x:y:z:_) state index = operation (drop newindex state) newstate newindex
|
operation (2:x:y:z:_) state index input output =
|
||||||
where
|
operation (drop newindex state) newstate newindex input output
|
||||||
|
where
|
||||||
sum = (state !! x) * (state !! y)
|
sum = (state !! x) * (state !! y)
|
||||||
split = splitAt z state
|
split = splitAt z state
|
||||||
newstate = (fst split) ++ [sum] ++ (drop 1 (snd split))
|
newstate = (fst split) ++ [sum] ++ (drop 1 (snd split))
|
||||||
newindex = index + 4
|
newindex = index + 4
|
||||||
operation (3:z:_) state index = operation (drop newindex state) newstate newindex
|
operation (3:z:_) state index input output=
|
||||||
|
operation (drop newindex state) newstate newindex newinput output
|
||||||
where
|
where
|
||||||
split = splitAt z state
|
split = splitAt z state
|
||||||
newstate = insert state (1) z
|
newstate = insert state (head input) z
|
||||||
|
newinput = drop 1 input
|
||||||
newindex = index + 2
|
newindex = index + 2
|
||||||
operation (4:z:_) state index = do
|
operation (4:z:_) state index input output=
|
||||||
putStrLn( show (state !! z ))
|
operation (drop newindex state) state newindex input newoutput
|
||||||
let newindex = index + 2
|
where
|
||||||
operation (drop newindex state) state newindex
|
newoutput = output ++ [(state !! z)]
|
||||||
|
newindex = index + 2
|
||||||
|
|
||||||
insert :: [Int] -> Int -> Int -> [Int]
|
insert :: [Int] -> Int -> Int -> [Int]
|
||||||
insert xs value index = do
|
insert xs value index = do
|
||||||
|
|
Loading…
Reference in New Issue
Block a user