Dataset Viewer
Auto-converted to Parquet Duplicate
id
stringlengths
21
21
messages
listlengths
2
4
meta
dict
codeplan-train-000000
[ { "role": "user", "content": "I'm building the in-memory layer of an API backend in Python, as one module `memlayer.py`. It needs these parts:\n\n1. **Versioned key-value store.** Implement `TimeMap()` with `set(key, value, timestamp)` and `get(key, timestamp)`. get returns the value set for `key` at the la...
{ "kind": "code.plan.backend", "lang": "en", "generator": "kreatix-code-plan", "version": "0.1.0", "mode": "both", "parts": [ "time_map", "range_sum", "window_extreme" ], "entries": [ "TimeMap", "PointUpdateSums", "sliding_min" ], "problem_ids": [ "a6e61ba9ba95", "268...
codeplan-train-000001
[ { "role": "user", "content": "I need a route-planning module for a delivery map in Python: a single module, `routing.py`, with the following parts.\n\n1. **First edge that closes a cycle.** There are `n` nodes numbered 0..n-1 and a list of undirected edges `[u, v]`. Edges are added one by one in the given o...
{ "kind": "code.plan.routing", "lang": "en", "generator": "kreatix-code-plan", "version": "0.1.0", "mode": "multi", "parts": [ "union_find", "count_islands", "grid_paths" ], "entries": [ "first_cycle_edge", "num_islands", "best_path" ], "problem_ids": [ "68a840458140", ...
codeplan-train-000002
[ { "role": "user", "content": "I need the core of a calculator service in Python: a single module, `calc_core.py`, with the following parts.\n\n1. **Count subarrays.** Return how many non-empty contiguous subarrays of `nums` there are whose sum is exactly `k`. Values can be negative and the list can have hun...
{ "kind": "code.plan.calc", "lang": "en", "generator": "kreatix-code-plan", "version": "0.1.0", "mode": "multi", "parts": [ "subarray_count", "expr_eval" ], "entries": [ "subarrays_with_sum", "evaluate" ], "problem_ids": [ "30cbcb348f5f", "ba1b3f285f18" ], "difficulty": 3...
codeplan-train-000003
[ { "role": "user", "content": "I need a scheduling toolkit for a booking app in Python: a single module, `scheduling.py`, with the following parts.\n\n1. **Merge overlapping intervals.** You are given a list of intervals `[start, end]` with `start < end`, in no particular order. Merge every group of interval...
{ "kind": "code.plan.scheduling", "lang": "en", "generator": "kreatix-code-plan", "version": "0.1.0", "mode": "plan", "parts": [ "merge_intervals", "topo_order", "search_answer" ], "entries": [ "merge", "smallest_topo_order", "slowest_speed" ], "problem_ids": [ "7ce574f99...
codeplan-train-000004
[ { "role": "user", "content": "Project: a scheduling toolkit for a booking app. Everything goes in one Python module, `scheduling.py`. Parts:\n\n1. **Slowest speed that finishes in time.** There are piles of items `piles`. At speed `k` you take up to `k` items from one pile per hour (a pile with fewer items ...
{ "kind": "code.plan.scheduling", "lang": "en", "generator": "kreatix-code-plan", "version": "0.1.0", "mode": "plan", "parts": [ "search_answer", "interval_greedy", "meeting_rooms" ], "entries": [ "min_eating_speed", "min_points_to_cover", "rooms_needed" ], "problem_ids": [ ...
codeplan-train-000005
[ { "role": "user", "content": "I need a small text-processing library in Python: a single module, `textkit.py`, with the following parts.\n\n1. **Longest substring without repeats.** Return the length of the longest substring of `s` in which no character appears twice. `s` can be hundreds of thousands of cha...
{ "kind": "code.plan.text", "lang": "en", "generator": "kreatix-code-plan", "version": "0.1.0", "mode": "both", "parts": [ "longest_window", "palindromes", "common_sequence" ], "entries": [ "longest_unique_run", "count_palindromes", "common_substring_len" ], "problem_ids": [ ...
codeplan-train-000006
[ { "role": "user", "content": "I need a small text-processing library in Python: a single module, `textkit.py`, with the following parts.\n\n1. **Longest substring without repeats.** Return the length of the longest substring of `s` in which no character appears twice. `s` can be hundreds of thousands of cha...
{ "kind": "code.plan.text", "lang": "en", "generator": "kreatix-code-plan", "version": "0.1.0", "mode": "plan", "parts": [ "longest_window", "edit_distance", "word_break" ], "entries": [ "longest_unique_run", "weighted_edit_distance", "word_break" ], "problem_ids": [ "d08...
codeplan-train-000007
[ { "role": "user", "content": "Projekti: toimituskartan reitinsuunnittelumoduuli. Kaikki menee yhteen Python-moduuliin, `routing.py`. Osat:\n\n1. **Paras polku ruudukon läpi.** Ruudukossa on kokonaislukuja (myös negatiivisia). Palauta suurin mahdollinen polun arvojen summa, kun liikutaan vasemmasta yläkulmas...
{ "kind": "code.plan.routing", "lang": "fi", "generator": "kreatix-code-plan", "version": "0.1.0", "mode": "multi", "parts": [ "grid_paths", "union_find" ], "entries": [ "best_path", "largest_group" ], "problem_ids": [ "88866def76ad", "2b655db75f55" ], "difficulty": 2, ...
codeplan-train-000008
[ { "role": "user", "content": "Projekti: ajanvaraussovelluksen aikataulutyökalut. Kaikki menee yhteen Python-moduuliin, `scheduling.py`. Osat:\n\n1. **Tehtävien järjestys.** Tehtäviä on `n` (`0..n-1`) ja pareja `[a, b]`, jotka tarkoittavat, että tehtävä `a` on tehtävä ennen tehtävää `b`. Palauta leksikografi...
{ "kind": "code.plan.scheduling", "lang": "fi", "generator": "kreatix-code-plan", "version": "0.1.0", "mode": "both", "parts": [ "topo_order", "search_answer", "interval_greedy" ], "entries": [ "schedule", "min_ship_capacity", "min_removals" ], "problem_ids": [ "723aad79c...
codeplan-train-000009
[ { "role": "user", "content": "Project: the core of a calculator service. Everything goes in one Python module, `calc_core.py`. Parts:\n\n1. **Fix the parentheses.** `s` contains only `(` and `)`. Return the minimum number of parentheses you must insert (anywhere) to make it balanced.\n2. **Count subarrays.*...
{ "kind": "code.plan.calc", "lang": "en", "generator": "kreatix-code-plan", "version": "0.1.0", "mode": "both", "parts": [ "brackets", "subarray_count" ], "entries": [ "fix_parens", "subarrays_with_sum" ], "problem_ids": [ "f26917dfccd0", "30cbcb348f5f" ], "difficulty": 2...
codeplan-train-000010
[ { "role": "user", "content": "I'm building a scheduling toolkit for a booking app in Python, as one module `scheduling.py`. It needs these parts:\n\n1. **Fewest points that cover every interval.** You are given intervals `[start, end]` with `start < end`. Return the smallest number of points such that every...
{ "kind": "code.plan.scheduling", "lang": "en", "generator": "kreatix-code-plan", "version": "0.1.0", "mode": "both", "parts": [ "interval_greedy", "topo_order" ], "entries": [ "fewest_stabs", "smallest_topo_order" ], "problem_ids": [ "cdf4939fe2d3", "723aad79cf87" ], "di...
codeplan-train-000011
[ { "role": "user", "content": "Projekti: ruutupohjaisen pelin ruudukkotyökalut. Kaikki menee yhteen Python-moduuliin, `gridtools.py`. Osat:\n\n1. **Paras polku ruudukon läpi.** Ruudukossa on kokonaislukuja (myös negatiivisia). Palauta suurin mahdollinen polun arvojen summa, kun liikutaan vasemmasta yläkulmas...
{ "kind": "code.plan.grid", "lang": "fi", "generator": "kreatix-code-plan", "version": "0.1.0", "mode": "both", "parts": [ "grid_paths", "count_islands" ], "entries": [ "max_path_sum", "num_islands" ], "problem_ids": [ "88866def76ad", "75d0defff9c7" ], "difficulty": 2, ...
codeplan-train-000012
[ { "role": "user", "content": "Rakennan Pythonilla budjetointityökalun numeeriset apufunktiot, yhtenä moduulina `budget_math.py`. Siihen tarvitaan nämä osat:\n\n1. **Laske osataulukot.** Palauta, montako sellaista listan `nums` epätyhjää yhtenäistä osataulukkoa on, joiden summa on tasan `k`. Arvot voivat oll...
{ "kind": "code.plan.numbers", "lang": "fi", "generator": "kreatix-code-plan", "version": "0.1.0", "mode": "multi", "parts": [ "subarray_count", "lis", "coin_change" ], "entries": [ "count_sum_k", "longest_run_up", "min_coins" ], "problem_ids": [ "30cbcb348f5f", "53e0...
codeplan-train-000013
[ { "role": "user", "content": "Projekti: ruutupohjaisen pelin ruudukkotyökalut. Kaikki menee yhteen Python-moduuliin, `gridtools.py`. Osat:\n\n1. **Laske saaret.** Ruudukko on lista yhtä pitkiä merkkijonoja, joissa '1' on maata ja '0' vettä. Kaksi maaruutua kuuluu samaan saareen, kun ne ovat vierekkäin vaaka...
{ "kind": "code.plan.grid", "lang": "fi", "generator": "kreatix-code-plan", "version": "0.1.0", "mode": "multi", "parts": [ "count_islands", "spiral", "robot_walk" ], "entries": [ "islands", "spiral", "robot_max_distance" ], "problem_ids": [ "49595087decb", "38f2502ba...
codeplan-train-000014
[ { "role": "user", "content": "Projekti: laskinpalvelun ydin. Kaikki menee yhteen Python-moduuliin, `calc_core.py`. Osat:\n\n1. **Laske alkuluvut välillä.** Palauta, kuinka monta alkulukua `p` toteuttaa ehdon `lo <= p <= hi`. `lo` voi olla negatiivinen, ja `lo > hi` tarkoittaa tyhjää väliä. `hi` voi olla jop...
{ "kind": "code.plan.calc", "lang": "fi", "generator": "kreatix-code-plan", "version": "0.1.0", "mode": "plan", "parts": [ "primes_range", "expr_eval", "subarray_count" ], "entries": [ "count_primes", "eval_expression", "subarrays_div_by" ], "problem_ids": [ "fcfb2ec4ac3a...
codeplan-train-000015
[ { "role": "user", "content": "Tarvitsen Pythonilla pieni tekstinkäsittelykirjasto: yksi moduuli, `textkit.py`, jossa on seuraavat osat.\n\n1. **Pisin palindromiosajono.** Palauta merkkijonon `s` pisimmän sellaisen osajonon pituus, joka on sama takaperin luettuna. `s` voi olla tuhansia merkkejä pitkä, joten ...
{ "kind": "code.plan.text", "lang": "fi", "generator": "kreatix-code-plan", "version": "0.1.0", "mode": "plan", "parts": [ "palindromes", "edit_distance" ], "entries": [ "longest_palindrome_len", "edit_cost" ], "problem_ids": [ "9faa9dcf328a", "6ffdde278c0d" ], "difficult...
codeplan-train-000016
[ { "role": "user", "content": "I'm building grid utilities for a tile-based game in Python, as one module `gridtools.py`. It needs these parts:\n\n1. **Paths through a grid.** The grid is a list of strings of '.' (open) and '#' (blocked). Starting at the top-left cell and moving only right or down, how many ...
{ "kind": "code.plan.grid", "lang": "en", "generator": "kreatix-code-plan", "version": "0.1.0", "mode": "both", "parts": [ "grid_paths", "histogram", "robot_walk" ], "entries": [ "unique_paths", "max_histogram_area", "walk" ], "problem_ids": [ "9cbaa94810d4", "b594cfa...
codeplan-train-000017
[ { "role": "user", "content": "Rakennan Pythonilla pieni tekstinkäsittelykirjasto, yhtenä moduulina `textkit.py`. Siihen tarvitaan nämä osat:\n\n1. **Tasapainoiset sulkeet.** Palauta True, jos jokainen `(`, `[` ja `{` merkkijonossa `s` suljetaan oikealla sulkeella oikeassa järjestyksessä, muuten False. Muut ...
{ "kind": "code.plan.text", "lang": "fi", "generator": "kreatix-code-plan", "version": "0.1.0", "mode": "plan", "parts": [ "brackets", "palindromes", "word_break" ], "entries": [ "is_balanced", "palindromic_substrings", "can_segment" ], "problem_ids": [ "9719044729f6", ...
codeplan-train-000018
[ { "role": "user", "content": "Project: number utilities for a budgeting tool. Everything goes in one Python module, `budget_math.py`. Parts:\n\n1. **Knapsack (unbounded).** Item i weighs `weights[i]` and is worth `values[i]` (all positive integers). Return the largest total value whose total weight is at mo...
{ "kind": "code.plan.numbers", "lang": "en", "generator": "kreatix-code-plan", "version": "0.1.0", "mode": "both", "parts": [ "knapsack", "subarray_count", "lis" ], "entries": [ "best_load", "count_divisible", "longest_increasing" ], "problem_ids": [ "bbd681649271", "...
codeplan-train-000019
[ { "role": "user", "content": "I'm building the in-memory layer of an API backend in Python, as one module `memlayer.py`. It needs these parts:\n\n1. **LRU cache.** Implement `LRUCache(capacity)` with `get(key)` (the value, or -1 if absent) and `put(key, value)`. Both count as a use of the key. When a put wo...
{ "kind": "code.plan.backend", "lang": "en", "generator": "kreatix-code-plan", "version": "0.1.0", "mode": "both", "parts": [ "lru_cache", "time_map" ], "entries": [ "LRUCache", "TimeMap" ], "problem_ids": [ "e9eeef7af2fc", "a6e61ba9ba95" ], "difficulty": 2, "n_tests": ...
codeplan-train-000020
[ { "role": "user", "content": "I need a small text-processing library in Python: a single module, `textkit.py`, with the following parts.\n\n1. **Fewest words.** Return the smallest number of words from `words` that concatenate to exactly `s` (each word can be used any number of times), or -1 if it is imposs...
{ "kind": "code.plan.text", "lang": "en", "generator": "kreatix-code-plan", "version": "0.1.0", "mode": "both", "parts": [ "word_break", "brackets", "rle" ], "entries": [ "min_word_split", "fix_parens", "compress" ], "problem_ids": [ "80e4a77aa7a1", "f26917dfccd0", ...
codeplan-train-000021
[ { "role": "user", "content": "Projekti: API-taustapalvelun muistikerros. Kaikki menee yhteen Python-moduuliin, `memlayer.py`. Osat:\n\n1. **k yleisintä sanaa.** Palauta listan `words` `k` yleisintä sanaa yleisimmästä alkaen. Saman verran esiintyvät sanat järjestetään aakkosjärjestykseen. Jos erilaisia sanoj...
{ "kind": "code.plan.backend", "lang": "fi", "generator": "kreatix-code-plan", "version": "0.1.0", "mode": "plan", "parts": [ "top_k_words", "prefix_counter", "time_map" ], "entries": [ "top_words", "PrefixCounter", "VersionedStore" ], "problem_ids": [ "c1541db84646", ...
codeplan-train-000022
[ { "role": "user", "content": "I'm building grid utilities for a tile-based game in Python, as one module `gridtools.py`. It needs these parts:\n\n1. **Largest rectangle in a histogram.** `heights[i]` is the height of bar `i` in a histogram; every bar is 1 wide and bars stand side by side. Return the area of...
{ "kind": "code.plan.grid", "lang": "en", "generator": "kreatix-code-plan", "version": "0.1.0", "mode": "both", "parts": [ "histogram", "grid_paths" ], "entries": [ "largest_rectangle", "unique_paths" ], "problem_ids": [ "b594cfa644b5", "9cbaa94810d4" ], "difficulty": 3, ...
codeplan-train-000023
[ { "role": "user", "content": "I'm building number utilities for a budgeting tool in Python, as one module `budget_math.py`. It needs these parts:\n\n1. **Coin combinations.** Given distinct positive coin values (unlimited supply of each) and an amount, return the number of different combinations that add up...
{ "kind": "code.plan.numbers", "lang": "en", "generator": "kreatix-code-plan", "version": "0.1.0", "mode": "multi", "parts": [ "coin_change", "inversions", "subarray_count" ], "entries": [ "coin_combinations", "count_big_inversions", "subarrays_div_by" ], "problem_ids": [ ...
codeplan-train-000024
[ { "role": "user", "content": "Rakennan Pythonilla budjetointityökalun numeeriset apufunktiot, yhtenä moduulina `budget_math.py`. Siihen tarvitaan nämä osat:\n\n1. **Vähiten kolikoita.** Annettuna erisuuruiset positiiviset kolikkoarvot (jokaista rajattomasti) ja summa, palauta pienin määrä kolikoita, joiden ...
{ "kind": "code.plan.numbers", "lang": "fi", "generator": "kreatix-code-plan", "version": "0.1.0", "mode": "plan", "parts": [ "coin_change", "inversions", "lis" ], "entries": [ "fewest_coins", "count_big_inversions", "lis_length" ], "problem_ids": [ "9d7f7ca67fff", "e...
codeplan-train-000025
[ { "role": "user", "content": "Project: grid utilities for a tile-based game. Everything goes in one Python module, `gridtools.py`. Parts:\n\n1. **Spiral order.** Return all elements of the `rows × cols` matrix in spiral order, starting at the top-left corner and going counter-clockwise (down the left column...
{ "kind": "code.plan.grid", "lang": "en", "generator": "kreatix-code-plan", "version": "0.1.0", "mode": "plan", "parts": [ "spiral", "grid_paths" ], "entries": [ "spiral_order", "count_paths" ], "problem_ids": [ "af4362bd16a8", "9cbaa94810d4" ], "difficulty": 2, "n_test...
codeplan-train-000026
[ { "role": "user", "content": "Tarvitsen Pythonilla pieni tekstinkäsittelykirjasto: yksi moduuli, `textkit.py`, jossa on seuraavat osat.\n\n1. **Pisin osajono ilman toistoja.** Palauta merkkijonon `s` pisimmän sellaisen osajonon pituus, jossa mikään merkki ei esiinny kahdesti. `s` voi olla satojatuhansia mer...
{ "kind": "code.plan.text", "lang": "fi", "generator": "kreatix-code-plan", "version": "0.1.0", "mode": "plan", "parts": [ "longest_window", "rle" ], "entries": [ "longest_distinct_substring", "rle_encode" ], "problem_ids": [ "d083d59e642a", "082a4c4820df" ], "difficulty"...
codeplan-train-000027
[ { "role": "user", "content": "I'm building a scheduling toolkit for a booking app in Python, as one module `scheduling.py`. It needs these parts:\n\n1. **Task order.** There are `n` tasks `0..n-1` and pairs `[a, b]` meaning task `a` must be done before task `b`. Return the lexicographically smallest order t...
{ "kind": "code.plan.scheduling", "lang": "en", "generator": "kreatix-code-plan", "version": "0.1.0", "mode": "multi", "parts": [ "topo_order", "search_answer", "meeting_rooms" ], "entries": [ "schedule", "min_ship_capacity", "peak_time" ], "problem_ids": [ "723aad79cf87"...
codeplan-train-000028
[ { "role": "user", "content": "I'm building the core of a calculator service in Python, as one module `calc_core.py`. It needs these parts:\n\n1. **Count subarrays.** Return how many non-empty contiguous subarrays of `nums` there are whose sum is divisible by `k` (`k >= 1`). Values can be negative and the li...
{ "kind": "code.plan.calc", "lang": "en", "generator": "kreatix-code-plan", "version": "0.1.0", "mode": "both", "parts": [ "subarray_count", "primes_range" ], "entries": [ "count_divisible", "count_primes" ], "problem_ids": [ "d4e675b31167", "fcfb2ec4ac3a" ], "difficulty"...
codeplan-train-000029
[ { "role": "user", "content": "I'm building the core of a calculator service in Python, as one module `calc_core.py`. It needs these parts:\n\n1. **Count subarrays.** Return how many non-empty contiguous subarrays of `nums` there are whose sum is divisible by `k` (`k >= 1`). Values can be negative and the li...
{ "kind": "code.plan.calc", "lang": "en", "generator": "kreatix-code-plan", "version": "0.1.0", "mode": "both", "parts": [ "subarray_count", "brackets" ], "entries": [ "subarrays_div_by", "is_balanced" ], "problem_ids": [ "d4e675b31167", "9719044729f6" ], "difficulty": 2,...
codeplan-train-000030
[ { "role": "user", "content": "Tarvitsen Pythonilla budjetointityökalun numeeriset apufunktiot: yksi moduuli, `budget_math.py`, jossa on seuraavat osat.\n\n1. **Pisin ei-vähenevä alijono.** Palauta listan `nums` pisimmän alijonon (ei välttämättä yhtenäinen) pituus, kun alijonon on oltava ei-vähenevä (yhtä su...
{ "kind": "code.plan.numbers", "lang": "fi", "generator": "kreatix-code-plan", "version": "0.1.0", "mode": "plan", "parts": [ "lis", "subarray_count", "coin_change" ], "entries": [ "longest_increasing", "count_divisible", "fewest_coins" ], "problem_ids": [ "53e040dea565",...
codeplan-train-000031
[ { "role": "user", "content": "I need the core of a calculator service in Python: a single module, `calc_core.py`, with the following parts.\n\n1. **Count primes in a range.** Return how many prime numbers `p` satisfy `lo <= p <= hi`. `lo` can be negative and `lo > hi` means an empty range. `hi` can be up to...
{ "kind": "code.plan.calc", "lang": "en", "generator": "kreatix-code-plan", "version": "0.1.0", "mode": "both", "parts": [ "primes_range", "brackets", "subarray_count" ], "entries": [ "primes_between", "fix_parens", "subarrays_with_sum" ], "problem_ids": [ "fcfb2ec4ac3a",...
codeplan-train-000032
[ { "role": "user", "content": "Project: number utilities for a budgeting tool. Everything goes in one Python module, `budget_math.py`. Parts:\n\n1. **Count inversions.** Return the number of index pairs `i < j` with `a[i] > a[j]`. Values can be negative and the list can have 150,000 elements, so checking eve...
{ "kind": "code.plan.numbers", "lang": "en", "generator": "kreatix-code-plan", "version": "0.1.0", "mode": "plan", "parts": [ "inversions", "stock_profit", "primes_range" ], "entries": [ "count_inversions", "max_profit_with_fee", "count_primes" ], "problem_ids": [ "ee7e58...
End of preview. Expand in Data Studio

Kreatix Code Plan

2,165 conversations in English and Finnish where the assistant plans a Python module before writing it. Each project has 2 or 3 hard parts. The plan covers the layout and signatures, the algorithm, key points and complexity of each part, the edge cases, a test plan with exact expected values, and a build order. The implementation then follows the plan, and its self-test was run and passed.

Projects use the 40 problem families of Kreatix Code Hard, grouped by theme: a scheduling toolkit, a route planner, a text library, a calculator core, an in-memory API layer (cache, rate limiter, versioned store), budget math, and grid tools for a game.

Three conversation shapes:

Mode Conversation
plan the user asks for a plan only; the reply is the plan
plan + code one reply: the plan, then the full module and its test run
two turns the plan; the user approves ("Looks good. Implement it."); then the module and its test run

Made by KreatixLabs. Every row is built by a program: no language model wrote any text or code in this dataset.

Project themes in the train split

What it looks like

User

I need a small text-processing library in Python: a single module, `textkit.py`, with the following parts.

1. **Balanced brackets.** Return True if every `(`, `[` and `{` in `s` is closed by the matching bracket in the right order, and False otherwise. Other characters are ignored.
2. **Weighted edit distance.** Turn string `a` into string `b`. Inserting a character costs 2, deleting one costs 2, and replacing one character with a different one costs 3. Return the minimum total cost.

Assume large inputs: each part needs a properly efficient algorithm.
Don't code yet. Plan it first: structure, algorithms with their complexity, edge cases, a test plan with expected values, and the order you'd build it in.

Assistant

## Plan

**Module layout** (`textkit.py`)
```python
def valid_brackets(s: str) -> bool: ...

def edit_cost(a: str, b: str) -> int: ...
```
The parts are independent of each other, so each one gets its own function or class and its own tests; nothing is shared except the module's imports. Imports: none, only built-ins.

**1. `valid_brackets`** (Balanced brackets)
- Approach: A stack of open brackets: a closer must match the top; the stack must be empty at the end.
- Key points:
  - A stack (or a counter for one bracket type) tracks what is still open.
  - Process left to right; decide immediately when a closer arrives.
  - At the end, anything still open matters too.
- Complexity: O(n) time, O(n) space.
- Edge cases: empty string, only closers, interleaved types like '([)]'.

**2. `edit_cost`** (Weighted edit distance)
- Approach: Classic edit-distance DP with the three costs, keeping only the previous row. Because a replacement costs 3, it can beat a delete plus an insert.
- Key points:
  - dp[i][j] = cost to turn a[:i] into b[:j].
  - Transitions: delete a[i-1], insert b[j-1], or keep/replace the last characters.
  - Base row and column are pure inserts and deletes.
  - Only the previous row is needed: O(len(b)) memory.
- Complexity: O(len(a) · len(b)) time, O(len(b)) space.

**Test plan**
- `valid_brackets('}bb)b}')` → `False` (basic case)
- `valid_brackets(')(')` → `False` (edge case)
- `valid_brackets('(')` → `False` (edge case)
- `edit_cost('bbd', 'bd')` → `2` (basic case)
- `edit_cost('', '')` → `0` (edge case)
- `edit_cost('abc', '')` → `6` (edge case)

**Build order**
1. Write `valid_brackets` first: it is the simplest part.
2. Finish with `edit_cost`, the hardest part (it needs the most care).
3. Finally put all the tests under `if __name__ == "__main__":` so `python textkit.py` checks everything.

User

OK, implement it exactly like that.

Assistant

```python
"""A small text-processing library: valid_brackets, edit_cost."""


def valid_brackets(s: str) -> bool:
    pairs = {")": "(", "]": "[", "}": "{"}
    stack = []
    for ch in s:
        if ch in "([{":
            stack.append(ch)
        elif ch in pairs:
            if not stack or stack.pop() != pairs[ch]:
                return False
    return not stack


def edit_cost(a: str, b: str) -> int:
    INS, DEL, SUB = 2, 2, 3
    prev = [j * INS for j in range(len(b) + 1)]
    for i in range(1, len(a) + 1):
        cur = [i * DEL] + [0] * len(b)
        for j in range(1, len(b) + 1):
            keep = prev[j - 1] + (0 if a[i - 1] == b[j - 1] else SUB)
            cur[j] = min(keep, prev[j] + DEL, cur[j - 1] + INS)
        prev = cur
    return prev[len(b)]


if __name__ == "__main__":
    assert not valid_brackets('}bb)b}')
    assert not valid_brackets(')(')
    assert not valid_brackets('(')

    assert edit_cost('bbd', 'bd') == 2
    assert edit_cost('', '') == 0
    assert edit_cost('abc', '') == 6

    print("all 6 tests passed")
```

Running the file:
```
$ python textkit.py
all 6 tests passed
```

All 6 tests from the plan pass, covering the basic and edge cases of every part.

| Part | Complexity |
|---|---|
| `valid_brackets` | O(n) time, O(n) space |
| `edit_cost` | O(len(a) · len(b)) time, O(len(b)) space |

meta: {"kind": "code.plan.text", "lang": "en", "generator": "kreatix-code-plan", "version": "0.1.0", "mode": "multi", "parts": ["brackets", "edit_distance"], "entries": ["valid_brackets", "edit_cost"], "problem_ids": ["9719044729f6", "e47365121fe9"], "difficulty": 2, "n_tests": 6, "checked_by": "each part: reference == brute-force oracle + large-input time limit; combined module self-test run; parts re-checked from the module"}

How it was checked

  1. Every part is a problem from Kreatix Code Hard: its solution agrees with an independent brute-force solver on every test input and passes a large-input time limit.
  2. The test plan's expected values are those verified outputs.
  3. The module in the reply was run as written. It is kept only if:
    • it printed the success line shown in the reply;
    • every signature in the plan is defined in the module (checked through Python's AST);
    • each part, called from the combined module, still returns the verified results.

Size and repetition

Split Rows en fi
train 1,865 1,320 545
test 300 205 95

About 3.2M tokens in total.

Each combination of reference solutions appears in at most one project. Parts do repeat across projects, since there are 124 distinct solutions in all. meta.problem_ids lists them per row.

Test split: every test project includes a part from one of five families that never appear in train (two-colouring, decode ways, next greater element, trapped water / container, running median).

stats.json has the counts per theme and mode; samples.md shows examples in full.

Limitations

  • Independent parts. The parts of a project do not call each other, so the plans teach structure, choice of algorithm, edge cases, testing and build order, not interface design between modules.
  • Templates. Plans follow one structure with varied wording. The Finnish text is awaiting review by native speakers. Code identifiers and comments are in English in both languages.
  • Python only, standard library only.

License

Apache-2.0.

Downloads last month
-