From 0f79cf34d676b93bd51014f1753877d2ef61de5b Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Sat, 30 Jun 2018 10:15:19 -0700 Subject: Add type sigs and try to fix bug --- simspace/Main.hs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'simspace/Main.hs') diff --git a/simspace/Main.hs b/simspace/Main.hs index 229bba4..18f744a 100644 --- a/simspace/Main.hs +++ b/simspace/Main.hs @@ -34,12 +34,15 @@ takeWhile' p (x:xs) = x : if p x then takeWhile' p xs else [] compute :: Int -> [Int] -> [Int] compute n state = state ++ compute n (next n state) +next :: Int -> [Int] -> [Int] next n state = [left, center, right] where - center = translate $ getLast n state - right = translate $ getLast (n+1) state - left = translate $ getLast (n-1) state + center = translate $ getLast n' state + right = translate $ getLast (n'+1) state + left = translate $ getLast (n'-1) state + n' = n+n +getLast :: Int -> [a] -> [a] getLast n ls = drop (length ls - n) ls translate [0,0,0] = 0 -- cgit v1.2.3