docs
evals
scenario-1
scenario-10
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
Counts the distinct ways to climb a staircase when up to a given number of steps can be taken at once. The recurrence must be expressed through the dependency's fixed-point recursion helper rather than direct self-reference, and cached with the dependency's memoization utility so repeated calls reuse prior results.
maxJump 2 yields ways {0:1, 1:1, 2:2, 3:3, 4:5} for countWays(0..4). @testmaxJump 3, countWays(7) returns 44 based on the staircase recurrence. @testCache statistics are exposed through getEvaluations(), which counts distinct step totals computed since the last clearCache while leaving cache hits unchanged.
countWays(7), a second call to countWays(7) leaves getEvaluations() unchanged, confirming cached reuse. @testclearCache() resets computed entries so a subsequent countWays(5) increments getEvaluations() again. @testmaxJump below 1 or calling countWays with a negative step count throws an error. @testUse the dependency's recursion combinator to build the anonymous recurrence and its memoization helper to cache per-step results.
export type StepCounter = {
countWays(n: number): number;
getEvaluations(): number;
clearCache(): void;
};
export function createStepCounter(maxJump: number): StepCounter;Functional toolkit providing the recursion combinator and memoization utility needed for the recurrence and cache.