Skip to content

Instantly share code, notes, and snippets.

@deadfoxygrandpa
Created January 8, 2016 03:47
Show Gist options
  • Save deadfoxygrandpa/ad43d8dade00095ae92d to your computer and use it in GitHub Desktop.
Save deadfoxygrandpa/ad43d8dade00095ae92d to your computer and use it in GitHub Desktop.
module Main (..) where
import Automaton
import Dict
import Graphics.Element exposing (show)
main =
Automaton.step 5 factorialAutomaton |> snd |> show
type alias State =
Dict.Dict Int Int
factorialAutomaton : Automaton.Automaton Int Int
factorialAutomaton =
let
factorial : Int -> State -> ( Int, State )
factorial i state =
case Dict.get i state of
Just n ->
( n, state )
Nothing ->
let
( n, state' ) = factorial (i - 1) state
in
( i * n, Dict.insert i n state' )
in
Automaton.hiddenState (Dict.fromList [ ( 0, 1 ) ]) factorial
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment