From cd5e13ba7979aa942326ddbc7199f91ca85425a9 Mon Sep 17 00:00:00 2001 From: Jed Barber Date: Thu, 6 Feb 2014 21:10:42 +1100 Subject: Placed Fractran interpreter into its own module --- Fractran/Interpreter.hs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Fractran/Interpreter.hs diff --git a/Fractran/Interpreter.hs b/Fractran/Interpreter.hs new file mode 100644 index 0000000..0427aed --- /dev/null +++ b/Fractran/Interpreter.hs @@ -0,0 +1,23 @@ +module Interpreter ( + fractran + ) where + + +import Parser + + + + +fractran :: FractranProgram -> [Int] +fractran program = + let prog = map (\(x,y) -> (fromIntegral x, fromIntegral y)) (fractions program) + f = (\p v -> if (p == []) + then [] + else let (curX, curY) = head p + newV = v * curX / curY + in if (isInt newV) + then newV : (f prog newV) + else f (tail p) v) + result = map round (f prog (fromIntegral (initialValue program))) + in value : result + -- cgit