Basic usage
Input
inc, dec, get = make_counter(10, 2) inc() get()
Output
12 12
Starting at 10 with step 2, inc() moves the counter to 12 and returns 12; get() returns the current value 12.
Full lesson preview
Create a closure-based counter factory that returns increment, decrement and getter functions sharing the same state.
Problem statement
Task
Examples
Input
inc, dec, get = make_counter(10, 2) inc() get()
Output
12 12
Starting at 10 with step 2, inc() moves the counter to 12 and returns 12; get() returns the current value 12.
Input format
Output format
Constraints
Samples
Input
make_counter(0, 1)[0]()
Output
1
Counter starts at 0; inc() with step 1 returns 1.