PromptCode/6

From srakrn | Wiki
Revision as of 21:30, 21 April 2026 by Srakrn (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

PromptCode challenge:

  • Given the following code, use an LLM to generate a snippet of code that will function the same.
  • You can't cheat, which are basically:
    • Feed this code to an LLM and ask it to output the exact same thing.
    • Write this code in other languages and ask an LLM to rewrite in Python.
    • Prompt LLM the logic of this code line-by-line.
  • You can prompt as many time as you want.
    • Easy mode: conversation style, LLM keeps continuing with the context from its earlier message.
    • Hard mode: reset to new conversation or 'edit' the message sent to LLM for every prompt.
  • Highlight the black censored text for hint.



(Difficulty: medium)

def sc(lst, t, lo=0, hi=None):
    if hi is None:
        hi = len(lst) - 1
    if lo > hi:
        return -1
    mid = (lo + hi) // 2
    if lst[mid] == t:
        return mid
    if lst[mid] < t:
        return sc(lst, t, mid + 1, hi)
    return sc(lst, t, lo, mid - 1)

Hint 1: The function name is search_sorted