I'm trying to implement Wolfram’s elementary cellular automaton (rule 30) in haskell.
Result for ./wolfram 10 :
*
***
** *
** ****
** * *
** **** ***
** * * *
** **** ******
** * *** *
** **** ** * ***
To start, I generate this list : [0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0] where 0 is ' ' and 1 is '*'.
Passing this list to the function genNextLine :: [Int] -> [Int] will generate the next list.
For a given element, the next element is determined by its two neighbors (example : [0, 1, 1] will generate a 1).
I can iterate through the list element by element like this :
genNextLine :: [Int] -> [Int]
genNextLine (x : xs) = ...
But how can I iterate through the list by accessing elements x - 1, x, x + 1 ?