Basic integer sequence
Input
g = make_sequence(0, 1) (g(), g(), g())
Output
(0, 1, 2)
g starts at 0 and increments by 1 each call; the three calls return 0, 1, 2.
Full lesson preview
Build a function factory that returns a callable sequence generator using closures to retain state.
Problem statement
Task
Examples
Input
g = make_sequence(0, 1) (g(), g(), g())
Output
(0, 1, 2)
g starts at 0 and increments by 1 each call; the three calls return 0, 1, 2.
Input
a = make_sequence(1, 1) b = make_sequence(100, -10) (a(), b(), a(), b())
Output
(1, 100, 2, 90)
a and b each maintain their own state; calls interleave correctly.
Input format
Output format
Constraints
Samples
Input
g = make_sequence(5, 10) g()
Output
5
First call returns the start value 5.