{"id":"code-col-binary-search-hang-clues","audience":"college","category":"coding","track":"coding","technique":"constraints","title":"Find why your binary search hangs, without the fix","free":false,"task":"Your binary search for an algorithms side project sometimes never returns. You want to fix it yourself, so ask for exactly 3 numbered lines labeled 'Bug: line N - ...', 'Hangs on: find([...], x) - ...' with a concrete call that really loops forever, and 'Hint: ...', each under 20 words. No code blocks, no corrected line, under 75 words.","materialLabel":"Your function (attached to your prompt automatically)","material":"# search.py  - my \"algorithms in practice\" side project\n\n1  def find(a, t):\n2      lo, hi = 0, len(a) - 1\n3      while lo < hi:\n4          mid = (lo + hi) // 2\n5          if a[mid] < t:\n6              lo = mid\n7          else:\n8              hi = mid\n9      return lo if a and a[lo] == t else -1\n\nWhat I've tried:\n>>> find([2, 4, 6, 8, 10], 2)\n0\n>>> find([2, 4, 6, 8, 10], 6)\n2\n>>> find([], 5)\n-1\n>>> find([2, 4, 6, 8, 10], 10)\n(never returns, had to Ctrl+C)\n\nNotes to self:\n- list is always sorted ascending, no duplicates\n- I want the index of t, or -1 if it's not there\n- I think the bug is in line 9 because that's where it returns?\n- Kofi said \"binary search is always off by one somewhere\" lol","rules":[{"type":"numberedItems","count":3},{"type":"codeBlocks","count":0},{"type":"maxProseWords","max":75}],"mistakes":[{"title":"Getting the fix","why":"The AI hands you lo = mid + 1 and a rewritten function, so you never trace it yourself.","fix":"Say: \"Don't give the corrected line or code. Clues only.\"","checks":["r2","codeBlocks"]},{"title":"Blaming the wrong line","why":"Your note points at line 9, and the AI may follow your guess.","fix":"Ask: \"Which line causes the hang? Label it 'Bug: line N'.\"","checks":["r0"]},{"title":"No input to trace","why":"Without a small failing call, you can't see the loop get stuck.","fix":"Add: \"Give a concrete call that hangs, labeled 'Hangs on:'.\"","checks":["r1"]},{"title":"A long lesson","why":"The AI explains binary search from the start.","fix":"Add: \"Exactly 3 numbered lines, each under 20 words.\"","checks":["numberedItems","maxProseWords"]}],"promptHints":[{"label":"Asks for clues, not the fix","patterns":["don'?t (give|show|write).{0,20}(fix|code|answer)","no (fix|corrected)","myself","clue"]},{"label":"Gives the labels","patterns":["bug:","hangs on","hint:"]},{"label":"Asks for a failing input","patterns":["input","call","example that hangs"]},{"label":"Sets the number of lines","patterns":["\\b(3|three)\\b.{0,20}line","numbered"]},{"label":"Caps each line","patterns":["\\d+\\s*words"]}],"hint":"You'll learn more by tracing a small failing case than by reading a fix. Ask for the line, a tiny input that hangs, and a hint.","rubricLabels":["The Bug line points to line 6 (lo = mid), saying lo stops moving when hi is lo + 1 because mid equals lo","The Hangs on line gives a concrete call that really never returns with this code (e.g. find([2, 4], 4) or find([2, 4, 6, 8, 10], 10))","The lines start with the labels Bug:, Hangs on: and Hint:, and no corrected code or exact fixed line (like lo = mid + 1) is given"]}