383
you are viewing a single comment's thread
view the rest of the comments
[-] eah@programming.dev 8 points 1 day ago* (last edited 4 hours ago)

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

[-] TheLazyNerd@europe.pub 1 points 8 hours ago* (last edited 8 hours 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();}

[-] grue@lemmy.world 25 points 19 hours ago* (last edited 19 hours ago)

Code gulf, you say?

public static String
convertRomanNumeral(String numeral) {
    numeral = numeral.replace("America", "Mexico");
    return numeral;
} 
[-] deadbeef79000@lemmy.nz 3 points 9 hours ago
[-] tourist@lemmy.world 45 points 23 hours ago
public static int convertRomanNumeral(String numeral) {
    return 4; // todo
}
[-] ray@sh.itjust.works 2 points 17 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();
}
[-] qaz@lemmy.world 6 points 13 hours 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();
}
this post was submitted on 11 Oct 2025
383 points (100.0% liked)

Programmer Humor

26827 readers
1889 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