Undo/redo with typing coalescing for a text buffer (word boundaries, 2-second gap, backspace vs forward-delete groups, history cap)
Exact prompt
# Undo/redo with typing coalescing for a text buffer `editor.py` is the text buffer behind our notes app. Users expect one undo to remove a whole typed word, not one letter. Rewrite `Editor` (Python 3 stdlib only) with this exact behaviour. API: `Editor(text="")`, attribute `.text`, `insert(pos, s, t)`, `delete(pos, n, t)`, `undo() -> bool`, `redo() -> bool`. `t` is the edit time in seconds (float; compare with plain subtraction `t - last <= 2.0`; the hidden tests never use times where floating-point rounding could change that comparison). ## Edits 1. `insert`: `pos` must be an int with `0 <= pos <= len(text)`, else `ValueError`. Inserting `""` changes nothing and is not recorded (but positions and time are still validated). 2. `delete(pos, n, t)` removes `text[pos:pos+n]`; `pos` and `n` must be ints with `n >= 1`, `pos >= 0`, `pos + n <= len(text)`, else `ValueError`. 3. `t` must never be smaller than the `t` of the previous recorded edit, else `ValueError` (nothing changes). Validation errors leave everything unchanged. ## Undo groups 4. Every recorded edit either **joins** the most recent undo group or starts a new one. A new edit can only join if: the most recent group is still **open** (no `undo()`/`redo()` call happened since that group was last changed), the group was created by a **single-character** edit (a multi-character insert or delete is a group of its own that never accepts more edits), the new edit is a single character, `t - (time of the group's last edit) <= 2.0`, and the group currently holds **fewer than 20 characters**. 5. **Typing:** a 1-char insert joins an insert group if `pos` equals group start + group text length (typing right after it) and the group's last character is not a space or `\n` (a space/newline is still added to the group, but ends it for further typing). 6. **Deleting:** a 1-char delete joins a delete group either as **backspace** (`pos + 1 ==` group start; the group start moves to `pos`) or as **forward delete** (`pos ==` group start). A group's direction is fixed by its second delete; after that only the same direction joins. 7. Insert never joins a delete group and vice versa. 8. `undo()` reverts the most recent group as a whole and moves it to the redo stack; `redo()` re-applies the most recently undone group. Both return `False` (and change nothing else, except closing the open group) when their stack is empty, else `True`. Any recorded edit (including one that joins a group) clears the redo stack. 9. The undo stack keeps at most **50** groups; when a 51st is pushed (by a new group or by `redo`), the oldest is dropped. ## Scoring Hidden check groups (partial credit = fraction passed; all must pass): `validation` (1-3), `typing_groups` (4-5), `word_boundaries` (5), `time_gap` (4: exactly 2.0 s joins, 2.0001 s does not), `delete_directions` (6-7), `undo_redo_semantics` (8), `group_limits` (4: 20-char cap; 9: 50 groups), `randomized_agreement` (500 random sequences of 60 operations: `.text` and every return value must match the rules after each step).
Many small interacting rules (group closing on undo/redo, multi-character groups that never join, direction fixed by the second delete, 20-character cap, 50-group cap including redo) compared step by step on 500 random sequences. Original benchmark task written for usecaserank.com (not based on a specific public post). Headless, offline run on a reproducible fixture. Each run's notes say how its cost was measured (estimates are marked).
Success criteria: 1. validation 2. typing_groups 3. word_boundaries 4. time_gap 5. delete_directions 6. undo_redo_semantics 7. group_limits 8. randomized_agreement (500 sequences)
Best model for this task so far: Claude Haiku 5.5 (effort default (no --effort flag) · thinking on) (success, $0.01, 58s).
All runs (4)
100% pass rate across 4 eligible runs: 4 pass, 0 partial, 0 fail. Partial and failed runs are listed below with everything else.ⓘ
| Model | Cost | Time | Step-insⓘ | Autonomy | Outcome | Trustⓘ | Date | Compare |
|---|---|---|---|---|---|---|---|---|
| OGPT-6.1 Soldefault · thinking on | $0.07 | 2m | 0 | Fully autonomous | pass | Trust 80% | 2026-10-22 | |
| AClaude Haiku 5.5default · thinking on | $0.01 | 58s | 0 | Fully autonomous | pass | Trust 80% | 2026-10-20 | |
| AClaude Opus 5.5default · thinking on | $0.25 | 54s | 0 | Fully autonomous | pass | Trust 80% | 2026-10-20 | |
| AClaude Sonnet 5.5default · thinking on | $0.07 | 20s | 0 | Fully autonomous | pass | Trust 80% | 2026-10-20 |
Embed this result
A live badge for this use case. It links back here and updates as new runs are published.
Get new runs and ranking changes weekly
Which models got better or cheaper on real tasks like this one.