0
0
Kotlinprogramming~10 mins

Sequence creation methods in Kotlin - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a sequence from a list.

Kotlin
val numbers = listOf(1, 2, 3, 4, 5)
val seq = numbers.[1]()
Drag options to blanks, or click blank then click option'
AasSequence
BtoSequence
CgenerateSequence
DsequenceOf
Attempts:
3 left
💡 Hint
Common Mistakes
Using sequenceOf() which creates a sequence from given elements, not from a list.
Trying to call toSequence() which does not exist.
2fill in blank
medium

Complete the code to create a sequence of numbers starting from 1.

Kotlin
val seq = [1](1) { it + 1 }
Drag options to blanks, or click blank then click option'
AsequenceOf
BlistOf
CasSequence
DgenerateSequence
Attempts:
3 left
💡 Hint
Common Mistakes
Using sequenceOf() which creates a sequence from fixed elements.
Using asSequence() which converts collections but does not generate sequences.
3fill in blank
hard

Fix the error in the code to create a sequence from given elements.

Kotlin
val seq = [1](1, 2, 3, 4, 5)
Drag options to blanks, or click blank then click option'
AsequenceOf
BgenerateSequence
CasSequence
DlistOf
Attempts:
3 left
💡 Hint
Common Mistakes
Using asSequence() which converts collections but does not accept varargs.
Using listOf() which creates a list, not a sequence.
4fill in blank
hard

Fill both blanks to create a sequence from a list and filter even numbers.

Kotlin
val numbers = listOf(1, 2, 3, 4, 5)
val evenSeq = numbers.[1]().filter { it [2] 2 == 0 }
Drag options to blanks, or click blank then click option'
AasSequence
BtoSequence
C%
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using toSequence() which does not exist.
Using '==' instead of '%' for checking even numbers.
5fill in blank
hard

Fill all three blanks to create a sequence of squares of numbers from 1 to 5, filtering those greater than 10.

Kotlin
val seq = (1..5).[1]().map { it [2] it }.filter { it [3] 10 }
Drag options to blanks, or click blank then click option'
AasSequence
B*
C>
DsequenceOf
Attempts:
3 left
💡 Hint
Common Mistakes
Using sequenceOf() instead of asSequence() on a range.
Using '+' instead of '*' for squaring.
Using '<' instead of '>' for filtering.