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

Programmer Humor

26846 readers
432 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
[–] rooroo@feddit.org 22 points 3 days 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 7 points 3 days ago (2 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 6 points 3 days ago (1 children)

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

[–] pitiable_sandwich540@feddit.org 3 points 3 days ago (1 children)

If the substitution went right to left it might work.

[–] rooroo@feddit.org 2 points 2 days ago
[–] rooroo@feddit.org 2 points 3 days ago (1 children)

I’ve written it that way and it works, as in it will replace left to right and you replace iiii to iv after iiiii to v

[–] lugal@lemmy.dbzer0.com 0 points 3 days ago (1 children)

Makes sense but it will fail at 9 (VIV) it would only work for 9 if the replace went from right to left or the V and IV statements were exchanged but in both cases, 6 would fail

[–] rooroo@feddit.org 1 points 2 days ago (1 children)

9 is IX though, and that works.

6 works fine, as it replaces the first set of 5 I with V and then there’s nothing to replace.

I’d written it in typescript for all it’s worth; go ahead and try it yourself :)

[–] lugal@lemmy.dbzer0.com 1 points 2 days ago (2 children)

Does 9 really work? Wouldn't it be:

IIIIIIIII
-> VIIII
-> VIV
[–] rooroo@feddit.org 2 points 2 days ago

I like your questions about this and they all seem fair but I kinda wanna encourage you to go ahead and write it yourself; it’s a fun way to convert into Roman numerals that both is and isn’t intuitive at the same time.

[–] rooroo@feddit.org 2 points 2 days ago (2 children)

No, cause you do the replacement from large to small, I.e. you’d first check for 10 I to replace with X (none found); then replace 9 with IX (check), then check for 5, 4 and so on.

[–] lugal@lemmy.dbzer0.com 2 points 2 days ago (1 children)

The original doesn't have an extra check for 9 and it works for Roman->Indioarabic because it's:

IX
->IVV
->IIIIV
->IIIIIIIII

But the other way around, you need an extra step for 9. That's where our misunderstanding comes from.

[–] rooroo@feddit.org 2 points 2 days ago

Ohhh haha that makes sense. Fun!

[–] rooroo@feddit.org 1 points 2 days ago

I noticed my “and so on” is literally a noop here so yeah.