Files
aji/docs/evaluation/dev-tasks/dev-lru/prompt.md
T
dev e3fc896a0a wip: shield index relations, dev evaluation tasks, Q-063 audit notes
Verifier borrow/provenance work, new phase3 shield_index conformance cases,
dev-intervals/dev-lru/dev-shards tasks with evaluate.py harness, and agent skill/hook config.
2026-10-17 12:30:37 +03:00

2.8 KiB
Raw Blame History

Task: least-recently-used cache

Development task (dev set). Its results are not evidence about any language.

Write a program that simulates a key–value cache of bounded size which evicts the least recently used key. The program reads commands from standard input, one per line, and writes its answers to standard output.

Input

The input is a sequence of lines separated by \n. If the input ends with \n, that final \n does not start another line. The input is at most 32 KiB and has at most 1500 lines.

The first line is always capacity C, where C is a decimal number with 1 ≤ C ≤ 1000 and no leading zeros. It produces no output. Every later line is a command.

A token is 1 to 16 characters, each an ASCII lowercase letter a–z or digit 0–9. Keys and values are tokens.

A line is a valid command when it is exactly one of the forms below: the command word, then its arguments, each separated by exactly one space. There are no other spaces or characters.

Command Effect Output
put K V If K is in the cache, its value becomes V. Otherwise, if the cache holds C keys, the least recently used key L is removed first, then K is added with value V. In both cases K becomes the most recently used key. evict L if a key was removed, otherwise ok
get K If K is in the cache, K becomes the most recently used key. the value of K, or miss
peek K Nothing changes. the value of K, or miss
del K Removes K if it is in the cache. ok if it was removed, otherwise miss
stats Nothing changes. size S hits H misses M evictions E
dump Nothing changes. the keys from the most to the least recently used, separated by single spaces; empty if the cache is empty

Recency changes only through put and a get that finds its key. S is the number of keys in the cache. H and M count the get commands that found and did not find their key; peek is not counted. E counts the keys removed by put; del is not counted.

Any other line, including an empty line, an unknown command, a wrong number of arguments, or an argument that is not a token, is invalid. For an invalid line the program writes error and changes nothing.

Output

One output line for each command and for each invalid line, in input order. Every output line ends with \n. Nothing else is written to standard output.

Example

Input:

capacity 2
put a 1
put b 2
get a
put c 3
peek b
dump
get b
stats
put a 9
get a
del zz

Output:

ok
ok
1
evict b
miss
c a
miss
size 2 hits 1 misses 1 evictions 1
ok
9
miss

The repository contains a README with the program's interface for this language and a public test script, sh test.sh, which must pass. Hidden tests check the requirements above, including invalid input.