Archived
1
Fork 0
This repository has been archived on 2025-04-09. You can view files and clone it, but cannot push or open issues or pull requests.
cellomata/Automaton.elm
2016-11-14 20:33:15 +01:00

23 lines
638 B
Elm

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