this post was submitted on 11 Oct 2025
438 points (99.5% liked)

Programmer Humor

26846 readers
643 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
 
(page 2) 19 comments
sorted by: hot top controversial new old
[–] eah@programming.dev 8 points 3 days ago* (last edited 2 days ago) (5 children)

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

[–] TheLazyNerd@europe.pub 2 points 2 days ago* (last edited 2 days ago)

I'm not too good with java, but it should be something like this:

public static int convertRomanNumeral(string n){Map.of("M","DD","CD","CCCC","D","CCCCC","C","LL","XL","XXXX","L","XXXXX","X","VV","IV","IIII","V","IIIII");.forEach((k,v)->{n=n.replace(k,v);});return n.length();}

[–] ray@sh.itjust.works 3 points 2 days ago (1 children)
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();
}
load more comments (1 replies)
load more comments (3 replies)
[–] itsraining@lemmygrad.ml 6 points 3 days ago

According to this code, "CEREAL" is a valid Roman numeral which equals 154. Great job!

[–] BlackEco@lemmy.blackeco.com 3 points 2 days ago (1 children)

Depending on the language, you may be mutating the input value, which isn't great.

[–] qaz@lemmy.world 2 points 2 days ago (1 children)

I'm pretty sure it's Java (due to the syntax and Eclipse editor default color scheme), so that isn't an issue

load more comments (1 replies)
[–] SpaceNoodle@lemmy.world 7 points 3 days ago (3 children)
load more comments (3 replies)
[–] panda_abyss@lemmy.ca 6 points 3 days ago (2 children)

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

load more comments (2 replies)
[–] fckreddit@lemmy.ml 5 points 3 days ago (1 children)

I just wrote something similar for decoding binary asm instructions.

[–] Valmond@lemmy.world 3 points 3 days ago

If you have the time it's a good solution!

[–] Olap@lemmy.world 5 points 3 days ago

until(original=new) { run convertOriginal }

load more comments
view more: ‹ prev next ›