Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // find this from kotlin's doco. The seed is the previous result
- fun fibs(): Sequence<Int> {
- // fibonacci terms
- return generateSequence(Pair(1, 2), { Pair(it.second, it.first + it.second) }).map { it.first }
- }
- // Example:
- // projecteuler.net problem 2:
- // fibs().takeWhile{ it < 4_000_000 }.filter { it % 2 == 0 }.sum()
- //
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement