Basic increment and read
Input
(lambda f: (f[0](), f[1](3), f[0]()))(make_counter(2))
Output
(2, 5, 5)
make_counter(2) returns (get, inc, dec, set). We call get() -> 2, inc(3) -> 5, then get() again -> 5.
Full lesson preview
Create a factory that returns several functions which all capture and mutate the same enclosed state.
Problem statement
Task
Examples
Input
(lambda f: (f[0](), f[1](3), f[0]()))(make_counter(2))
Output
(2, 5, 5)
make_counter(2) returns (get, inc, dec, set). We call get() -> 2, inc(3) -> 5, then get() again -> 5.
Input format
Output format
Constraints
Samples
Input
(lambda f: (f[0](), f[1](), f[0]()))(make_counter(3))
Output
(3, 4, 4)
Start at 3. get()->3, inc() defaults to +1 -> 4, get()->4.