]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/Collaz.scl
Automatic execution of SCL tests in Maven
[simantics/platform.git] / tests / org.simantics.scl.compiler.tests / src / org / simantics / scl / compiler / tests / scl / Collaz.scl
diff --git a/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/Collaz.scl b/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/Collaz.scl
new file mode 100644 (file)
index 0000000..2e4552d
--- /dev/null
@@ -0,0 +1,16 @@
+import "Prelude"\r
+\r
+f x = if x `mod` 2 == 0\r
+      then x `div` 2\r
+      else 3*x + 1\r
+fd x = unfoldr (\x -> do\r
+                   r = f x \r
+                   if x == 1\r
+                   then Nothing\r
+                   else Just (x,r)\r
+                ) x\r
+\r
+//main :: [Integer]                \r
+main = fd 7\r
+--\r
+[7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2]
\ No newline at end of file