A-M baby
This commit is contained in:
parent
764da6cbbb
commit
db842d013d
19005 changed files with 197040 additions and 7 deletions
15
Task/Fibonacci-sequence/Haxe/fibonacci-sequence-1.haxe
Normal file
15
Task/Fibonacci-sequence/Haxe/fibonacci-sequence-1.haxe
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
static function fib(steps:Int, handler:Int->Void)
|
||||
{
|
||||
var current = 0;
|
||||
var next = 1;
|
||||
|
||||
for (i in 1...steps)
|
||||
{
|
||||
handler(current);
|
||||
|
||||
var temp = current + next;
|
||||
current = next;
|
||||
next = temp;
|
||||
}
|
||||
handler(current);
|
||||
}
|
||||
23
Task/Fibonacci-sequence/Haxe/fibonacci-sequence-2.haxe
Normal file
23
Task/Fibonacci-sequence/Haxe/fibonacci-sequence-2.haxe
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
class FibIter
|
||||
{
|
||||
public var current:Int;
|
||||
private var nextItem:Int;
|
||||
private var limit:Int;
|
||||
|
||||
public function new(limit) {
|
||||
current = 0;
|
||||
nextItem = 1;
|
||||
this.limit = limit;
|
||||
}
|
||||
|
||||
public function hasNext() return limit > 0
|
||||
|
||||
public function next() {
|
||||
limit--;
|
||||
var ret = current;
|
||||
var temp = current + nextItem;
|
||||
current = nextItem;
|
||||
nextItem = temp;
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
2
Task/Fibonacci-sequence/Haxe/fibonacci-sequence-3.haxe
Normal file
2
Task/Fibonacci-sequence/Haxe/fibonacci-sequence-3.haxe
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
for (i in new FibIter(10))
|
||||
Sys.println(i);
|
||||
Loading…
Add table
Add a link
Reference in a new issue