Basic caching
Input
add(1, 2, scale=3)
Output
9
add(1,2,scale=3) returns (1+2)*3 = 9 and the result will be cached for later calls with the same arguments.
Full lesson preview
Implement a memoization decorator that caches results of pure functions with hashable arguments and preserves function metadata.
Problem statement
Task
Examples
Input
add(1, 2, scale=3)
Output
9
add(1,2,scale=3) returns (1+2)*3 = 9 and the result will be cached for later calls with the same arguments.
Input format
Output format
Constraints
Samples
Input
fib(6)
Output
8
With memoization, recursive fib(6) should compute quickly and return 8.