Complete the code to create an infinite sequence starting from 1.
val numbers = generateSequence([1]) { it + 1 }
The sequence starts from 1, so the initial value must be 1.
Complete the code to generate an infinite sequence of even numbers starting from 2.
val evens = generateSequence([1]) { it + 2 }
The sequence of even numbers starts at 2, so the initial value must be 2.
Fix the error in the code to generate an infinite sequence of odd numbers starting from 1.
val odds = generateSequence([1]) { it + 2 }
The sequence of odd numbers starts at 1, so the initial value must be 1.
Fill both blanks to generate the infinite sequence 1, 2, 5, 14, 41, … starting from 1.
val squares = generateSequence([1]) { it + [2] }
The sequence starts at 1, and the next value is obtained by adding it * 2 - 1.
Fill all three blanks to generate an infinite Fibonacci sequence starting from 0 and 1.
val fibs = generateSequence(Pair([1], [2])) { Pair(it.second, it.first [3] it.second) } .map { it.first }
The Fibonacci sequence starts with 0 and 1, and each next number is the sum of the previous two.