summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJed Barber <jjbarber@y7mail.com>2014-02-06 21:10:42 +1100
committerJed Barber <jjbarber@y7mail.com>2014-02-06 21:10:42 +1100
commitcd5e13ba7979aa942326ddbc7199f91ca85425a9 (patch)
tree0519c5634f8940f0882e6867c45e93f56372d2f3
parent7bdff9045dba7506c7cd40646d0da95c0807b875 (diff)
Placed Fractran interpreter into its own module
-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
+