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

Programmer Humor

26846 readers
448 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
 
you are viewing a single comment's thread
view the rest of the comments
[–] eah@programming.dev 8 points 3 days ago* (last edited 3 days ago) (4 children)

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

[–] tourist@lemmy.world 46 points 3 days ago
public static int convertRomanNumeral(String numeral) {
    return 4; // todo
}
[–] grue@lemmy.world 27 points 3 days ago* (last edited 3 days ago) (1 children)

Code gulf, you say?

public static String
convertRomanNumeral(String numeral) {
    numeral = numeral.replace("America", "Mexico");
    return numeral;
} 
[–] deadbeef79000@lemmy.nz 5 points 3 days ago
[–] TheLazyNerd@europe.pub 2 points 3 days ago* (last edited 3 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 3 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();
}
[–] qaz@lemmy.world 7 points 3 days ago
public static int convertRomanNumeral(String numeral)
{
  return 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")
    .length();
}