Cellular automata in Elm
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

23 lines
638 B

module Automaton exposing (..)
import Random
-- MODEL
type alias Automaton s i = List ((s, i), s)
zip : List a -> List b -> List (a, b)
zip = List.map2 (,)
cart : List a -> List b -> List (a, b)
cart l1 l2 = List.concat <| List.map (\x -> List.map (\y -> (x, y)) l2) l1
genAut : Int -> Int -> Random.Generator (Automaton Int Int)
genAut n k = let
allSI = cart [1..n] [1..k]
in Random.map (zip allSI) (Random.list (n*k) <| Random.int 1 n)
step : Automaton s i -> Maybe s -> i -> Maybe s
step ls s0 i = case s0 of
Nothing -> Nothing
Just s -> List.filter (\((t, j), b) -> t == s && i == j) ls |> List.head |> Maybe.map snd