or run

npx @tessl/cli init
Log in

Version

Files

docs

function-utilities.mdindex.mdlist-operations.mdmathematical-operations.mdobject-operations.mdstring-processing.md
tile.json

task.mdevals/scenario-10/

Memoized Step Counter

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.

Capabilities

Fixed-point recurrence

  • Creating a counter with maxJump 2 yields ways {0:1, 1:1, 2:2, 3:3, 4:5} for countWays(0..4). @test
  • With maxJump 3, countWays(7) returns 44 based on the staircase recurrence. @test

Memoized lookups

Cache statistics are exposed through getEvaluations(), which counts distinct step totals computed since the last clearCache while leaving cache hits unchanged.

  • After computing countWays(7), a second call to countWays(7) leaves getEvaluations() unchanged, confirming cached reuse. @test
  • Calling clearCache() resets computed entries so a subsequent countWays(5) increments getEvaluations() again. @test

Input validation

  • Creating a counter with a maxJump below 1 or calling countWays with a negative step count throws an error. @test

Implementation

@generates

Use the dependency's recursion combinator to build the anonymous recurrence and its memoization helper to cache per-step results.

API

export type StepCounter = {
  countWays(n: number): number;
  getEvaluations(): number;
  clearCache(): void;
};

export function createStepCounter(maxJump: number): StepCounter;

Dependencies { .dependencies }

prelude-ls { .dependency }

Functional toolkit providing the recursion combinator and memoization utility needed for the recurrence and cache.