SHARE
TWEET

Untitled

a guest Aug 22nd, 2019 83 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. //
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top