summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Fractran/Interpreter.hs23
1 files changed, 23 insertions, 0 deletions
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
+