Implement memoize(fn) that caches results by argument. Input: a JSON array of integers representing successive calls to a memoized square function. Print two lines: the JSON array of results, and the number of ACTUAL (non-cached) computations.
Input: one JSON array of call arguments. Output: line 1 — JSON results; line 2 — computation count.
Your program reads from stdin and prints to stdout.
Example 1
Input: [2,3,2,2]
Output: [4,9,4,4] 2
Hints
Implement memoize(fn) that caches results by argument. Input: a JSON array of integers representing successive calls to a memoized square function. Print two lines: the JSON array of results, and the number of ACTUAL (non-cached) computations.
Input: one JSON array of call arguments. Output: line 1 — JSON results; line 2 — computation count.
Your program reads from stdin and prints to stdout.
Example 1
Input: [2,3,2,2]
Output: [4,9,4,4] 2
Hints