Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.33 KB | None | 0 0
  1. // find this from kotlin's doco. The seed is the previous result
  2. fun fibs(): Sequence<Int> {
  3. // fibonacci terms
  4. return generateSequence(Pair(1, 2), { Pair(it.second, it.first + it.second) }).map { it.first }
  5. }
  6.  
  7. // Example:
  8. // projecteuler.net problem 2:
  9. // fibs().takeWhile{ it < 4_000_000 }.filter { it % 2 == 0 }.sum()
  10. //
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement