2
0
Fork 0
mirror of https://github.com/MartinThoma/LaTeX-examples.git synced 2025-04-25 14:28:05 +02:00
LaTeX-examples/documents/Programmierparadigmen/scripts/x10/Fibonacci.x10

23 lines
540 B
Text
Raw Normal View History

2014-03-28 11:06:02 +01:00
// file Fibonacci.x10
public class Fibonacci {
2014-03-29 14:20:26 +01:00
public static def fib(n:Long): Long {
2014-03-28 11:06:02 +01:00
if (n < 2) {
return n;
}
2014-03-29 14:20:26 +01:00
val f1:Long;
val f2:Long;
2014-03-28 11:51:59 +01:00
finish {
async f1 = fib(n-1);
async f2 = fib(n-2);
}
2014-03-28 11:06:02 +01:00
return f1 + f2;
}
public static def main(args:Rail[String]) {
x10.io.Console.OUT.println("This is fibonacci in X10.");
2014-03-29 14:20:26 +01:00
for (var i:Long=0; i < 10; ++i) {
2014-03-28 11:06:02 +01:00
x10.io.Console.OUT.println(i + ": " + fib(i));
}
}
}