Alright fags, time to see how many of you can actually program.
Your challenge:
Write a script that will convert natural numbers to Roman numerals.
Use any language you choose, no time limit.
>>54942769
>hey /g/ please solve my project euler for menumerals = {
'I': 1,
'V': 5,
'X': 10,
'L': 50,
'C': 100,
'D': 500,
'M': 1000
}
values = {
1: 'I',
4: 'IV',
5: 'V',
9: 'IX',
10: 'X',
40: 'XL',
50: 'L',
90: 'XC',
100: 'C',
400: 'CD',
500: 'D',
900: 'CM',
1000: 'M'
}
def expand(numeral):
i = value = 0
while i < len(numeral):
v = numerals[numeral[i]]
if i < len(numeral)-1 and v < numerals[numeral[i+1]]:
v = numerals[numeral[i+1]] - numerals[numeral[i]]
i += 1
i += 1
value += v
return value
def contract(value):
string = ""
remaining = value
for v in sorted(values.keys(), reverse=True):
while remaining >= v:
string += values[v]
remaining -= v
return string
>>54942769
i'll do your homework for you op here it is:
see if its divisible by the biggest unit
if it is then divide it by that and take its remainder and repeat the process
if not, see if its dvisible by the next biggest unit
... and so on
easy shit just use your brain and think about it
#include <iostream>
#include <string>
using namespace std;
string = "natural numbers";
cout << string << endl;
string = "Roman numerals";
cout << string;
>>54942769
Also adding lines over numbers for multiplying past 10000?
>>54942806
>>54942828
OP here
Not homework, I'm not a CS student. It's an interview practice question I was working on earlier, just interested to see how /g/ handles it.
>>54942841
Whatever you like m8
>>54942858
i forgot about the thing where it subtracts depending on what side it's on. thats harder than i thought m8
>>54942947
Yeah it's actually a surprising pain in the ass
I'm not a great programmer, but I'm definitely struggling with it. 0 to 9 is easy, after that it gets complex
>>54943244
i suppose just try to implement the same algorithm you inexplicitly use when you're reading a roman numeral in your head. idk what to tell u maiman
>>54943296
Huh, that's a good approach actually.
Maybe I should read more into algorithmic design, I know nothing about it