Created
July 17, 2012 03:32
-
-
Save siosio/3126861 to your computer and use it in GitHub Desktop.
Kotlinでフィボナッチ数列的な
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Iterator | |
fun main(args: Array<String>) { | |
fibonacci(1000).forEach {println(it)} | |
} | |
fun fibonacci(max: Int): Iterator<Int> { | |
var current = #(1, 1) | |
return iterate<Int> { | |
val next = current._1 + current._2 | |
if (next < max) { | |
current = #(current._2, next) | |
next | |
} else { | |
null | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment