llmcoderlab

Word ladder (shortest path)

qwen3-30b-a3b Pythononeshotrun 2sample 0196.3s wall

← run 2 · raw JSON · challenge definitions

tests (60%)5/5 passed
deliverables (20%)100%
content checks (20%)100%

01 what the model was asked

Create ladder.py with exactly one function:

ladder_length(begin: str, end: str, word_list: list[str]) -> int
    A transformation sequence goes from begin to end, changing exactly one letter per step; every intermediate word (and end itself) must appear in word_list. Return the number of words in the SHORTEST such sequence counting both endpoints, or 0 if none exists. begin does not need to be in word_list. All words are lowercase and the same length.

Example: begin="hit", end="cog", word_list=["hot","dot","dog","lot","log","cog"] -> 5 (hit -> hot -> dot -> dog -> cog).

Use only the Python standard library. A breadth-first search is the intended approach; brute-force recursion will be too slow for the larger test.
required deliverables + checks
deliverable: ladder.py
ladder.py must contain “def ladder_length”
pytest suite it was graded against
test_ladder.py · 27 lines · 744 B
import time from ladder import ladder_length  def test_classic_example():    assert ladder_length("hit", "cog", ["hot", "dot", "dog", "lot", "log", "cog"]) == 5  def test_unreachable_end():    assert ladder_length("hit", "cog", ["hot", "dot", "dog", "lot", "log"]) == 0  def test_single_step():    assert ladder_length("a", "c", ["a", "b", "c"]) == 2  def test_shortest_is_found():    words = ["hot", "hit", "hat", "cat", "cot", "cog", "dog"]    assert ladder_length("hit", "cot", words) == 3  def test_larger_input_is_fast():    words = [a + b + c for a in "abcdefgh" for b in "abcdefgh" for c in "abcdefgh"]    start = time.monotonic()    assert ladder_length("aaa", "hhh", words) == 4    assert time.monotonic() - start < 2.0

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: ladder.py

SPEC:
Create ladder.py with exactly one function:

ladder_length(begin: str, end: str, word_list: list[str]) -> int
    A transformation sequence goes from begin to end, changing exactly one letter per step; every intermediate word (and end itself) must appear in word_list. Return the number of words in the SHORTEST such sequence counting both endpoints, or 0 if none exists. begin does not need to be in word_list. All words are lowercase and the same length.

Example: begin="hit", end="cog", word_list=["hot","dot","dog","lot","log","cog"] -> 5 (hit -> hot -> dot -> dog -> cog).

Use only the Python standard library. A breadth-first search is the intended approach; brute-force recursion will be too slow for the larger test.
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: ladder.py

SPEC:
Create ladder.py with exactly one function:

ladder_length(begin: str, end: str, word_list: list[str]) -> int
    A transformation sequence goes from begin to end, changing exactly one letter per step; every intermediate word (and end itself) must appear in word_list. Return the number of words in the SHORTEST such sequence counting both endpoints, or 0 if none exists. begin does not need to be in word_list. All words are lowercase and the same length.

Example: begin="hit", end="cog", word_list=["hot","dot","dog","lot","log","cog"] -> 5 (hit -> hot -> dot -> dog -> cog).

Use only the Python standard library. A breadth-first search is the intended approach; brute-force recursion will be too slow for the larger test.
reply4442 tokens
view raw reply
{"files": {"ladder.py": "from collections import deque\n\ndef ladder_length(begin: str, end: str, word_list: list[str]) -> int:\n    word_set = set(word_list)\n    if end not in word_set:\n        return 0\n    if begin == end:\n        return 1\n    queue = deque()\n    queue.append((begin, 1))\n    visited = set([begin])\n    while queue:\n        current, steps = queue.popleft()\n        if current == end:\n            return steps\n        for i in range(len(current)):\n            for c in 'abcdefghijklmnopqrstuvwxyz':\n                new_word = current[:i] + c + current[i+1:]\n                if new_word in word_set and new_word not in visited:\n                    visited.add(new_word)\n                    queue.append((new_word, steps + 1))\n    return 0"}}
write_fileladder.py · 727 B
graded 100.05 passed, 0 failed
pytest output
.....                                                                    [100%]
5 passed in 0.02s

03 what it wrote

1
files
22
lines
21
source lines
1
functions
0
classes
9
cyclomatic
5
max nesting
20.0
avg fn lines

stdlib imports: collections

FileLOCSLOC FnsComplexityDepthImports
ladder.py2221195collections
ladder.py · 22 lines · 727 B
from collections import deque def ladder_length(begin: str, end: str, word_list: list[str]) -> int:    word_set = set(word_list)    if end not in word_set:        return 0    if begin == end:        return 1    queue = deque()    queue.append((begin, 1))    visited = set([begin])    while queue:        current, steps = queue.popleft()        if current == end:            return steps        for i in range(len(current)):            for c in 'abcdefghijklmnopqrstuvwxyz':                new_word = current[:i] + c + current[i+1:]                if new_word in word_set and new_word not in visited:                    visited.add(new_word)                    queue.append((new_word, steps + 1))    return 0

04 how it was graded

✓ ok 5/5 passed
1
model calls
0
invalid actions
0
self test runs
4.4k
tokens out
252
tokens in
196.3s
wall time

agent actions:

final pytest output
.....                                                                    [100%]
5 passed in 0.02s