LRU cache
← run 2 · raw JSON · challenge definitions
—
score
tests (60%)—
deliverables (20%)—
content checks (20%)—
one-shot reply is not valid JSON: Expecting ',' delimiter: line 3 column 17 (char 31)
01 what the model was asked
Create lru.py with a class:
class LRUCache:
def __init__(self, capacity: int)
def get(self, key) -> value # return the stored value, or -1 if absent
def put(self, key, value) -> None # insert or update
Semantics: the cache holds at most `capacity` entries. Both get() and put() count as a use of the key. When put() would exceed capacity, evict the least-recently-used key first. put() on an existing key updates its value and makes it most-recently-used.
Use only the Python standard library.
required deliverables + checks
✗deliverable: lru.py
✗lru.py must contain “class LRUCache”
✗lru.py must contain “def get”
✗lru.py must contain “def put”
pytest suite it was graded against
test_lru.py · 46 lines · 842 B
from lru import LRUCache def test_basic_put_get(): c = LRUCache(2) c.put("a", 1) assert c.get("a") == 1 assert c.get("missing") == -1 def test_eviction_order(): c = LRUCache(2) c.put("a", 1) c.put("b", 2) c.put("c", 3) assert c.get("a") == -1 assert c.get("b") == 2 assert c.get("c") == 3 def test_get_refreshes_recency(): c = LRUCache(2) c.put("a", 1) c.put("b", 2) c.get("a") c.put("c", 3) assert c.get("b") == -1 assert c.get("a") == 1 def test_put_overwrite_refreshes(): c = LRUCache(2) c.put("a", 1) c.put("b", 2) c.put("a", 10) c.put("c", 3) assert c.get("b") == -1 assert c.get("a") == 10 def test_capacity_one(): c = LRUCache(1) c.put("a", 1) c.put("b", 2) assert c.get("a") == -1 assert c.get("b") == 2
02 what it did — full transcript
promptthe exact instruction sent to the model
view full prompt
You are completing a coding task in one shot. Write complete files that satisfy the spec below. Tests (pytest) will be run against your files; you cannot run them yourself.
Reply with ONE JSON object and nothing else:
{"files": {"<relative path>": "<complete file content>", ...}}
Required deliverable files: lru.py
SPEC:
Create lru.py with a class:
class LRUCache:
def __init__(self, capacity: int)
def get(self, key) -> value # return the stored value, or -1 if absent
def put(self, key, value) -> None # insert or update
Semantics: the cache holds at most `capacity` entries. Both get() and put() count as a use of the key. When put() would exceed capacity, evict the least-recently-used key first. put() on an existing key updates its value and makes it most-recently-used.
Use only the Python standard library.
reply148 tokens
view raw reply
```json
{
"files": {
"lru.py": """
from collections import OrderedDict
class LRUCache:
def __init__(self, capacity: int):
self.capacity = capacity
self.cache = OrderedDict()
def get(self, key) -> int:
if key in self.cache:
self.cache.move_to_end(key)
return self.cache[key]
else:
return -1
def put(self, key, value) -> None:
if key in self.cache:
self.cache.move_to_end(key)
self.cache[key] = value
if len(self.cache) > self.capacity:
self.cache.popitem(last=False)
"""
}
}
```⚠ degenerate outputone-shot reply is not valid JSON: Expecting ',' delimiter: line 3 column 17 (char 31)
03 what it wrote
The model produced no files.
04 how it was graded
1
model calls
0
invalid actions
0
self test runs
148
tokens out
—
tokens in
6.2s
wall time
agent actions: —