diff options
-rw-r--r-- | simspace/Main.hs | 9 |
1 files changed, 6 insertions, 3 deletions
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 |