Fibonacci sequence whose values do not // exceed four million, find the sum of the even-valued terms. // let seq = LimitSequence(sequence: FibonacciSequence()) { $1 < 4_000_000 } let sum = seq.filter(isEven).reduce(0,combine: +)
// // If I use $0 here, compiler complains. So, explicitly using "(i,_) -> Bool" let primes = LimitSequence(sequence:PrimeSequence()) { (i, _) -> Bool in i < 10_001 } let lastPrime = Array(primes).last
the Fibonacci sequence whose values do not // exceed four million, find the sum of the even-valued terms. // let sum = FibonacciSequence().takeWhile({ $0 < 4_000_000 }).filter(isEven).reduce(0,combine: +)
1) × ... × 3 × 2 × 1 // // For example, 10! = 10 × 9 × ... × 3 × 2 × 1 = 3628800, // and the sum of the digits in the number 10! is 3 + 6 + 2 + 8 + 8 + 0 + 0 = 27. // // Find the sum of the digits in the number 100! //
AnyGenerator<JKBigInteger> { var last = JKBigInteger(string:"0"), current = JKBigInteger(string:"1") return anyGenerator { let next = last + current last = current current = next return next } } }
Oriented Programming: https://developer.apple.com/videos/wwdc/2015/?id=408 JKBigInteger: https://github.com/kirsteins/JKBigInteger Images Not a dinosaur: http://www.kappit.com/img/pics/201408_2234_aechh_sm.jpg Ruby on Rails: https://upload.wikimedia.org/wikipedia/commons/thumb/c/c3/Ruby_on_Rails_logo.svg/2000px-Ruby_on_Rails_logo.svg.png Ruby: https://upload.wikimedia.org/wikipedia/commons/thumb/7/73/Ruby_logo.svg/1024px-Ruby_logo.svg.png Milky Way Galaxy: http://www.nasa.gov/images/content/63376main_image_feature_202_jwfull.jpg Milky Way Chocolate: https://upload.wikimedia.org/wikipedia/en/5/5e/Small-milky-way-package.jpg Krusty the Clown: https://upload.wikimedia.org/wikipedia/en/5/5a/Krustytheclown.png Crusty: screenshot from WWDC Video (above)