Basic usage
Input
c = make_counter() (c(), c(), c())
Output
(0, 1, 2)
Default start=0, step=1. Calls return 0, then 1, then 2.
Full lesson preview
Create a closure-based counter factory that produces stateful counter functions which can be reset or reconfigured.
Problem statement
Task
Examples
Input
c = make_counter() (c(), c(), c())
Output
(0, 1, 2)
Default start=0, step=1. Calls return 0, then 1, then 2.
Input
c = make_counter(3, 2) (c(), c(), c.reset(), c(), c.set_step(5), c())
Output
(3, 5, None, 3, None, 8)
Starts at 3 with step 2: returns 3 then 5. reset() returns None and resets back to 3. Next call returns 3. set_step(5) returns None; next call returns 8 (3 + 5).
Input format
Output format
Constraints
Samples
Input
c = make_counter(5, 2) (c(), c())
Output
(5, 7)
A counter starting at 5 increments by 2 each call: 5 then 7.