Returning from calls 10.5.1
This commit is contained in:
parent
10cc5e6e89
commit
7f4946f1e9
10 changed files with 196 additions and 23 deletions
|
|
@ -4,17 +4,18 @@ import std.process;
|
|||
import std.conv;
|
||||
|
||||
void main(){
|
||||
string fib21(){
|
||||
string fib(uint n){
|
||||
string r = "";
|
||||
double a = 0;
|
||||
double temp;
|
||||
for(double b = 1; a < 10000; b = temp + b){
|
||||
for(double b = 1; a <= n; b = temp + b){
|
||||
r ~= a.to!string ~ "\n";
|
||||
temp = a;
|
||||
a = b;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
assert([ "./lox", "test/fib21.lox" ].execute.output == fib21());
|
||||
assert([ "./lox", "test/fib21.lox" ].execute.output == fib(6765));
|
||||
assert([ "./lox", "test/fib10.lox" ].execute.output == fib(34));
|
||||
}
|
||||
|
||||
|
|
|
|||
11
test/fib10.lox
Normal file
11
test/fib10.lox
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
|
||||
fun fib(n){
|
||||
if(n <= 1)
|
||||
return n;
|
||||
return fib(n - 2) + fib(n - 1);
|
||||
}
|
||||
|
||||
for(var i = 0; i < 10; i = i + 1){
|
||||
print fib(i);
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue