Difference between revisions of "PromptCode/1"
Jump to navigation
Jump to search
| Line 1: | Line 1: | ||
| + | '''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 | ||
| + | ** Hard mode: reset to new conversation for every prompt | ||
| + | |||
<pre> | <pre> | ||
def cg(intervals: list[tuple[int, int]]) -> int: | def cg(intervals: list[tuple[int, int]]) -> int: | ||
Revision as of 16:20, 20 April 2026
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
- Hard mode: reset to new conversation for every prompt
def cg(intervals: list[tuple[int, int]]) -> int:
if len(intervals) <= 1:
return 0
sorted_intervals = sorted(intervals, key=lambda x: (x[0], x[1]))
merged = [sorted_intervals[0]]
for start, end in sorted_intervals[1:]:
prev_start, prev_end = merged[-1]
if start < prev_end:
merged[-1] = (prev_start, max(prev_end, end))
else:
merged.append((start, end))
return len(merged) - 1