this post was submitted on 11 Oct 2025
233 points (99.6% liked)

Programmer Humor

26827 readers
1989 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 2 years ago
MODERATORS
top 28 comments
sorted by: hot top controversial new old
[–] CookieOfFortune@lemmy.world 19 points 5 hours ago

This isn’t sufficiently enterprisey for Java. There should be a Roman numeral factory followed by relevant fromString and toInteger methods.

[–] anugeshtu@lemmy.world 25 points 8 hours ago (1 children)

Why don't you just ask Chat-GPT o3 every time? Works like a charm!

[–] lugal@lemmy.dbzer0.com 23 points 7 hours ago

Because there are better random generators

[–] douglasg14b@lemmy.world 27 points 8 hours ago (2 children)

Still linear time at least, could always be much MUCH worse

[–] dfyx@lemmy.helios42.de 11 points 8 hours ago (1 children)

There could be a hidden quadratic cost because the string needs to be reallocated and copied multiple times.

[–] Jerkface@lemmy.world 15 points 5 hours ago (1 children)
[–] aaaaaaaaargh@feddit.org 2 points 56 minutes ago

This is the spirit

[–] lugal@lemmy.dbzer0.com 9 points 7 hours ago (1 children)

True. Lost opportunity to blow things up with useless recursivity

[–] bleistift2@sopuli.xyz 6 points 6 hours ago (1 children)

The word you’re looking for is recursion (see recursion).

[–] Gonzako@lemmy.world 2 points 4 hours ago

Nah, I'd like to un-see recursion. It was way overblown on uni, I barely ever use it.

[–] theunknownmuncher@lemmy.world 69 points 10 hours ago* (last edited 10 hours ago)

Whenever you sit back and smile proudly to yourself about how clever the block of code you just wrote is, your next move should be to delete and rewrite it.

This is a clever block of code! Great job, now rewrite it to be sane 😂

[–] rooroo@feddit.org 14 points 8 hours ago (1 children)

It also works the other way round: wanna convert Arabic n to Roman? Just write n times ‘I’ and revert these replacement in inverse order.

[–] lugal@lemmy.dbzer0.com 6 points 7 hours ago (1 children)

I don't know what happens when the substring overlaps. Like for the number 6, will it replace the first 5 I's with V and end up correctly with VI or the last ones and come to IV? I would guess the former and maybe you know but I never thought about it before

[–] Atlas_@lemmy.world 4 points 3 hours ago

Also does not handle 'IIIIIIIII' -> 'IX' properly

[–] TootSweet@lemmy.world 19 points 9 hours ago* (last edited 9 hours ago)

My first thought was something along the lines of a "zip bomb". For every "M" in the input string, it'd use more than a KiB of memory. But still, it'd take a string of millions of "M"s to exhaust memory on even a low-end modern server. Still probably not a good idea to expose to untrusted input on a public networked server, though. And it could easily peg a CPU core for a good while. Very good leveraged target for DDOSing.

[–] Zangoose@lemmy.world 10 points 10 hours ago (1 children)

They forgot "CM" so this doesn't work for any number that ends in 900s

[–] trxxruraxvr@lemmy.world 42 points 10 hours ago* (last edited 10 hours ago)

No, M will be replaced by DD and then CD will be picked up, so it will go

  1. CM
  2. CDD
  3. CCCCD
  4. CCCCCCCCC
  5. ......
[–] SpaceNoodle@lemmy.world 6 points 10 hours ago (1 children)
[–] trxxruraxvr@lemmy.world 24 points 10 hours ago* (last edited 10 hours ago) (2 children)

IIV would never be used. In Roman numerals at most one smaller unit can come in front of a larger one. The code doesn't do any validation though.

[–] Mirodir@discuss.tchncs.de 10 points 8 hours ago

While it doesn't say anything about IIV specifically, they sure got creative enough to sometimes subtract more than one of the smaller units from a larger one.

[–] SpaceNoodle@lemmy.world -3 points 10 hours ago

Yes, that does demonstrate my point.

[–] Olap@lemmy.world 5 points 10 hours ago

until(original=new) { run convertOriginal }

[–] eah@programming.dev 4 points 10 hours ago (3 children)

It's got some code duplication. Who can code gulf this?

[–] grue@lemmy.world 8 points 5 hours ago* (last edited 5 hours ago)

Code gulf, you say?

public static String
convertRomanNumeral(String numeral) {
    numeral = numeral.replace("America", "Mexico");
    return numeral;
} 
[–] ray@sh.itjust.works 2 points 3 hours ago
public static int convertRomanNumeral(String numeral)
{
  numeral = numeral.replace("M", "DD")
    .replace("CD", "CCCC")
    .replace("D", "CCCCC")
    .replace("C", "LL")
    .replace("XL", "XXXX")
    .replace("L", "XXXXX")
    .replace("X", "VV")
    .replace("IV", "IIII")
    .replace("V", "IIIII");
  return numeral.length();
}
[–] tourist@lemmy.world 34 points 9 hours ago
public static int convertRomanNumeral(String numeral) {
    return 4; // todo
}
[–] panda_abyss@lemmy.ca 3 points 10 hours ago (1 children)

Should do a regex find all then iterate over each chunk recursively until unchanged.

[–] ZTechnical@programming.dev 4 points 4 hours ago

there was no regex in ancient rome