r/ProgrammerHumor • • Feb 14 '25

[deleted by user]

[removed]

8.7k Upvotes

703 comments sorted by

View all comments

Show parent comment

2

u/[deleted] Feb 14 '25

That seems like a broad generalization. I’m curious to know why you think that about nearly all LLM code. Here’s a function it wrote to convert a Roman numeral to a number. This is one I’ve used and I thought worked pretty well. If all ai code is slop, what’s wrong with this?

Sincerely curious about your thoughts.

def roman_to_int(roman: str) -> int: # Map each Roman numeral to its integer value roman_map = { ‘I’: 1, ‘V’: 5, ‘X’: 10, ‘L’: 50, ‘C’: 100, ‘D’: 500, ‘M’: 1000 }

total = 0
for i in range(len(roman)):
    # If we’re not at the last character and the current value is
    # less than the next value, subtract; otherwise, add.
    if i + 1 < len(roman) and roman_map[roman[i]] < roman_map[roman[i + 1]]:
        total -= roman_map[roman[i]]
    else:
        total += roman_map[roman[i]]
return total

Examples

print(roman_to_int(“III”)) # Output: 3 print(roman_to_int(“IV”)) # Output: 4 print(roman_to_int(“IX”)) # Output: 9 print(roman_to_int(“LVIII”)) # Output: 58 print(roman_to_int(“MCMXCIV”))# Output: 1994