QUICK
WRITE A PROGRAM THAT CONVERTS ARABIC NUMBERS TO ROMAN NUMBERS
OR BIRDMIN GONNA STAB YA
>>56947685
>homework
fuck off.
if numbers = arabic
numbers = roman
>>56947701
YA FAGGOT
SURE IT IS HOMEWORK
WITHOUT SPECIFYING THE LANGUAGE
DO IT IN ASSEMBLER IF YOU WISH
OR YOU GONNA GET STABBED
def convert(arabic):
if arabic != 1:
return -1
else:
return "I"
>>56947685
string s;
cin >> s;
if(s == "I")
s == (int)1;
if(s == "II")
s == (int)2;
if(s == "III")
s == (int)3;
if(s == "IV")
s == (int)4;
hope this amount of numbers are enaught, BIRDMIN have mercy!
String roman;
if(arabic == 1) roman = I;
else if(arabic == 2) roman = II;
else if(arabic == 3) roman = III;
else if(arabic == 4) roman = IV;
...
And so on. Just do this for every roman numeral
>>56947814
>928304
>>56947814
Also before some retard goes "hurr you have to have IV in quotes", they're not actual strings, they're roman numerals so they act as numbers
fromRoman :: String -> Int
fromRoman = translateFromRoman >>> applyNegationRule >>> sum
translateFromRoman :: String -> [Int]
translateFromRoman = map (\r -> fromJust $ lookup r [('I',1),('V',5),('X',10),('L',50),('C',100),('D',500),('M',1000)])
applyNegationRule :: [Int] -> [Int]
applyNegationRule [x] = [x]
applyNegationRule (x:y:xs) = (if x < y then -x else x) : applyNegationRule (y:xs)
>>56947685
>Everybody else's solutions are wrong#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
static const struct {
int num;
char *str;
} lut[] = {
{1000, "M"},
{900, "CM"},
{500, "D"},
{400, "CD"},
{100, "C"},
{90, "XC"},
{50, "L"},
{40, "XL"},
{10, "X"},
{9, "IX"},
{5, "V"},
{4, "IV"},
{1, "I"},
};
if (argc != 2)
return 1;
int n = atoi(argv[1]);
size_t i = 0;
while (n > 0) {
if (n >= lut[i].num) {
printf("%s", lut[i].str);
n -= lut[i].num;
} else {
++i;
}
}
putchar('\n');
}
tfw no null in the roman numbers
>>56947685
Look at Dive Into Python 3. Tutorial on TDD & refactoring
>>56947906
>tfw yours too
>>56947966
What is wrong with my solution?
>>56947685const translate = require('translationlibrary');
console.log(translate("ayy lmao"));
import java.util.TreeMap;
public class RomanNumber {
private final static TreeMap<Integer, String> map = new TreeMap<Integer, String>();
static {
map.put(1000, "M");
map.put(900, "CM");
map.put(500, "D");
map.put(400, "CD");
map.put(100, "C");
map.put(90, "XC");
map.put(50, "L");
map.put(40, "XL");
map.put(10, "X");
map.put(9, "IX");
map.put(5, "V");
map.put(4, "IV");
map.put(1, "I");
}
public final static String toRoman(int number) {
int l = map.floorKey(number);
if ( number == l ) {
return map.get(number);
}
return map.get(l) + toRoman(number-l);
}
}
BIRDMIN PLS DON KIL MI
>>56948021
you're safe for now pajeet
>>56947685
@echo off del tree/
Cd
If yiddish==true;
numbers==arabic
If (number==١)
(number==1)
And thus
return x.toNumeral;
im not doing your homework faggot
>>56947685import com.frequal.romannumerals.Converter;
public class Main
{
public static void main(String[] args)
{
Converter converter = new Converter();
String roman = converter.toRomanNumerals(42);
}
}
:^)
My notes so far, I have to go dew something before I continue though.% Convert numbers to roman numerals
% Examples:
%% 1: I, 2: II, 3: III, 4: IV, 5: V, 7: VII, 8: VIII, 9: IX, 10: X
%% 13: XIII, 14: XIV, 15: XV, 19: XIX, 20: XX
% Notes:
%% There are a set of symbols representing magnitudes, S, [I, V, X, L]
%% This set, S, converts to digits, N, [1, 5, 10, 50].
%% S(0) = I, S(3) = L, N(3) = 50.
%% Any number less than N(n), can be represented using sumbols {S(i) | i in {0..n-1}}.
%% Any number between N(n)(inclusive) and N(n+1)(exclusive) starts with the sumbol S(n) and is followed by
%% symbols in the set {S(i) | i in {0..n} AND Odd(i)}.
>>56948238
Should b even
>>56947685(defun number->roman (n)
(format nil "~@r" n))
>>56947705
Alri straya
Google search "Arabic to Roman numeral"
These threads need to happen more frequently.
>>56947714
I had lots of homework that was language agnostic
I'm not afraid of some fuckin bird
do your own homework retard
>>56947685
I did this once but the code is not at this computer atm.
It's surprisingly difficult, since you have to seperate the input into the right subgroups.
I think I did it with a stack or finite state machine if I recall correctly..
>>56948061
this
def arabic_to_roman(n) :
m = n // 1000
cm = (n % 1000) // 900
d = ((n % 1000) % 900) // 500
cd = (((n % 1000) % 900) % 500) // 400
c = ((((n % 1000) % 900) % 500) % 400) // 100
xc = ((n % 1000) % 100) // 90
l = (((n % 1000) % 100) % 90) // 50
xl = ((((n % 1000) % 100) % 90) % 50) // 40
x = (((((n % 1000) % 100) % 90) % 50) % 40) // 10
ix = (((n % 1000) % 100) % 10) // 9
v = ((((n % 1000) % 100) % 10) % 9) // 5
i = ((((n % 1000) % 100) % 10) % 9) % 5
return m*"M"+cm*"CM"+d*"D"+cd*"CD"+c*"C"+xc*"XC"+l*"L"+xl*"XL"+x*"X"+ix*"IX"+v*"V"+i*"I"
>>56947685
FUCK OFF
from collections import OrderedDict
roman = OrderedDict()
roman[1000] = 'M'
roman[900] = 'CM'
roman[500] = 'D'
roman[400] = 'CD'
roman[100] = 'C'
roman[90] = 'XC'
roman[50] = 'L'
roman[40] = 'XL'
roman[10] = 'X'
roman[9] = 'IX'
roman[5] = 'V'
roman[4] = 'IV'
roman[1] = 'I'
def to_numerals(num):
def convert(num):
for key in roman.keys():
quantity, _ = divmod(num, key)
yield roman[key] * quantity
num -= (key * quantity)
if num > 0:
convert(num)
else:
break
return ''.join([numeral for numeral in convert(num)])
Took me a whole fucking hour, and it's still a little buggy
>>56948719
No, it's not taht simple..
I tried your programm:
999 --> "CMXCIX" (instead of "IC")
549 --> "DXLIX" (instead of "DIL")
>>56948759
>999 --> "CMXCIX" (instead of "IC")
sorry, instead of "IM", of course..
>>56947685
b-but I can't program for shit, please d-don't stab me b-bird
>>56948755
Yes, it is
>>56948759
I genuiely didnt know it could work like that?
Are you sure? Wolfram aplha uses CMXCIX instead of IC and DXLIX instead of DIL
>>56947814
>>56948754>>> to_numerals(543)
'DXLIII'>>> to_numerals(3243)
'MMMCCXLIII'
>>56948782
OK, I looked it up, seems like there is no clear definiton..
>http://www.infoplease.com/askeds/1999-roman-numerals.html
Basically Roman numbers are just a pain in the ass.
>>56948759
I'm pretty sure the "negative rule" or whatever is just used to stop 4 characters from appearing in a row.
>>56948799
> wasting this much space
>>56948781
You make it sound like there are a lot of bugs. The only bug I see in there is when I entered '0321'. I believe that any other problems are only based on roman numeral convention.
>>56947685
fuck arabic.
http://pastebin.com/4zN9NUuT
127 lines babyyyyyyyyyyy
>>56948917
What shitty language is that supposed to be?
>>56948828
It seems like the romans even used "VIIII" instead of "IX".
See the link here:
>>56948810
>>56948942
wtf now I'm not going to tell you, rude
>>56948942
Seconding this.
I want to know the language so I can avoid it in the future..
>>56948942
>>56949012
MATLAB
>>56948942
>>56949012
Looks like matlab to me
>>56949012
>>56948942
haha alright you guys
It's octave, which is a freeware clone of Matlab. High-level interpreted language meant for fairly light numerical computation
>>56949044
wtf, I hate octave now
HELP IVE LOST CONTROLlargestNA(I, [NH | [NNH | NT]], [SH | ST]) ->
if NNH > I ->
largestNA(I, [NNH | NT], ST);
true ->
{[NH | [NNH | NT]], [SH | ST]}
end.
largestN(I) ->
largestNA(I, [100, 50, 10, 5, 1], ['C', 'L', 'X', 'V', 'I']).
repeat(_, 0) ->
{};
repeat(S, R) ->
{S, repeat(S, R-1)}.
% Using the above cases.
r(I) ->
{[NH | NT], [SH | ST]} = largestN(I),
[NextSmallestN | _] = NT,
%[EvenSmallerN | _] = NTT,
[NextSmallestS | _] = ST,
if I == NextSmallestN ->
NextSmallestS;
I < (NH - NextSmallestN) -> % It will be composed of symbols not including SH
%SomeNumber of NextSmallestS followed by r(SomeNumber * NextSmallestN - NH)
SomeNumber = I div NextSmallestN,
{repeat(NextSmallestS, SomeNumber), r(I - (SomeNumber * NextSmallestN))};
true -> % else it will be r(NH - I)SH - NH-I = between 0 and NextSmallestN
{r(NH - I), SH}
end.
>okay Google
>how do you write واحد in Roman?
I hate that we call them "Arabic" instead of "Indian".
All that we think is Arabic, is really Indian. The Arabs served as intermediaries between the West and India. They didn't invent jack shit.
>>56947685
Couldn't you justif(number >= 10)
{
String roman = "X" + (number - 10);
}
And do something similar for the 100's, 1000's, etc? And apply similar logic for 30's and 40's?
>>5694925767> numerals:r(lists:seq(100, 1, -1)).
["XCX","XCIX","XCVIII","XCVII","XCVI","XCV","XCIV","XCIII",
"XCII","XCI","XC","LXXXIX","LXXXVIII","LXXXVII","LXXXVI",
"LXXXV","LXXXIV","LXXXIII","LXXXII","LXXXI","LXXX","LXXIX",
"LXXVIII","LXXVII","LXXVI","LXXV","LXXIV","LXXIII",
[...]|...]
I came back after going out and finished it off. Quite proud of this since I considered it quite a difficult problem. My code is full of confusing variables though.largestNA(I, [NH | [NNH | NT]], [SH | ST]) ->
if NNH > I ->
largestNA(I, [NNH | NT], ST);
true ->
{[NH | [NNH | NT]], [SH | ST]}
end.
largestN(I) ->
largestNA(I, [100, 50, 10, 5, 1], ["C", "L", "X", "V", "I"]).
largestTens(I) ->
largestNA(I, [100, 10, 1], ["C", "X", "I"]).
repeat(_, 0) ->
"";
repeat(S, R) ->
S ++ repeat(S, R-1).
% Using the above cases.
r(0) ->
"";
r([I]) ->
[r(I)];
r([I | Is]) ->
[r(I) | r(Is)];
r(I) ->
{[NH | NT], [SH | ST]} = largestN(I),
[NextSmallestN | _] = NT,
%[EvenSmallerN | _] = NTT,
[NextSmallestS | _] = ST,
{[_ | [NextSmallestTensN | _]], [_ | [NextSmallestTensS | _]]} = largestTens(I),
if I == NextSmallestN ->
NextSmallestS;
I < (NH - NextSmallestTensN) -> % It will be composed of symbols not including SH
%SomeNumber of NextSmallestS followed by r(SomeNumber * NextSmallestN - NH)
SomeNumber = I div NextSmallestN,
repeat(NextSmallestS, SomeNumber) ++ r(I - (SomeNumber * NextSmallestN));
true -> % else it will be NextSmallestS.r(I - (NH - NextSmallestN)) : NH-I = between 0 and NextSmallestN
NextSmallestTensS ++ SH ++ r(I - (NH - NextSmallestTensN))
end.
:- module roman.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is det.
:- implementation.
:- import_module char, int, list, string.
main(!IO) :-
command_line_arguments(Args, !IO),
filter(is_all_digits, Args, CleanArgs),
foldl((pred(Arg::in, !.IO::di, !:IO::uo) is det :-
( Roman = to_roman(Arg) ->
format("%s => %s", [s(Arg), s(Roman)], !IO), nl(!IO)
; format("%s cannot be converted.", [s(Arg)], !IO), nl(!IO) )
), CleanArgs, !IO).
:- func to_roman(string::in) = (string::out) is semidet.
to_roman(Number) = from_char_list(build_roman(reverse(to_char_list(Number)))).
:- func build_roman(list(char)) = list(char).
:- mode build_roman(in) = out is semidet.
build_roman([]) = [].
build_roman([D|R]) = Roman :-
map(promote, build_roman(R), Interim),
Roman = Interim ++ digit_to_roman(D).
:- func digit_to_roman(char) = list(char).
:- mode digit_to_roman(in) = out is semidet.
digit_to_roman('0') = [].
digit_to_roman('1') = ['I'].
digit_to_roman('2') = ['I','I'].
digit_to_roman('3') = ['I','I','I'].
digit_to_roman('4') = ['I','V'].
digit_to_roman('5') = ['V'].
digit_to_roman('6') = ['V','I'].
digit_to_roman('7') = ['V','I','I'].
digit_to_roman('8') = ['V','I','I','I'].
digit_to_roman('9') = ['I','X'].
:- pred promote(char::in, char::out) is semidet.
promote('I', 'X').
promote('V', 'L').
promote('X', 'C').
promote('L', 'D').
promote('C', 'M').
:- end_module roman.
>2016
>not wasting your life with meme languages
>>56950730
is that fucking prolog
>>56947742
Kek
>>56950653
Kek
>>56947814
This is bait, right? Just checking.
>>56950730
Cool, i didn't know this existed. Gonna be my next language.
>>56950743
Mercury
>>56947981
Nothing, it's the only correct solution itt. He's joking about nulls.
>>56950830
>The only correct solution ITT
It produces exactly the same output as mine(?)
>>56950822
This is a cool-ass language anon
reeee too many lines
http://pastebin.com/mMz44ie3
I don't even know how to start this.
Is there no tuples in C?
pub fn roman(mut arabic: u16) -> String {
let mut table = vec![
(1000, "M"),
( 900, "CM"),
( 500, "D"),
( 400, "CD"),
( 100, "C"),
( 90, "XC"),
( 50, "L"),
( 40, "XL"),
( 10, "X"),
( 9, "IX"),
( 5, "V"),
( 4, "IV"),
( 1, "I"),
].into_iter().peekable();
let mut output = String::new();
while arabic > 0 {
match table.peek().cloned() {
None => break,
Some((value, name)) => if value > arabic {
table.next();
} else {
output.push_str(name);
arabic -= value;
},
}
}
output
}
#[test]
fn it_works() {
assert_eq!(&roman(58), "LVIII");
assert_eq!(&roman(1998), "MCMXCVIII");
assert_eq!(&roman(10_000), "MMMMMMMMMM");
}
>>56952025
rust?
>>56947685function toRoman(intNumber)
{
var strRoman = '';
while (intNumber > 0)
{
intNumber--;
strRoman = strRoman + 'I';
}
return strRoman;
}
for (int i = 0; i < n; i++) {
System.out.println("I");
}
>>56952831
This isn't funny, anon. Please try again.
>>56952910
Then why am I laughing?
>>56952446
yes
>giving a shit about roman numbers in the year 2016
lol pleb
>>56952970
> claims to not give shits about roman language, but uses words from it anyway
you mother fucker
>>56952025
I slightly modified your code to avoid unnecessary allocations ('vec!' and '.cloned()'):pub fn roman(mut arabic: u16) -> String {
let table = [
(1000, "M"),
( 900, "CM"),
( 500, "D"),
( 400, "CD"),
( 100, "C"),
( 90, "XC"),
( 50, "L"),
( 40, "XL"),
( 10, "X"),
( 9, "IX"),
( 5, "V"),
( 4, "IV"),
( 1, "I"),
];
let mut it = table.into_iter().peekable();
let mut output = String::new();
while arabic > 0 {
match it.peek() {
None => break,
Some(&&(value, name)) => if value > arabic {
it.next();
} else {
output.push_str(name);
arabic -= value;
},
}
}
output
}
#[test]
fn it_works() {
assert_eq!(&roman(58), "LVIII");
assert_eq!(&roman(1998), "MCMXCVIII");
assert_eq!(&roman(10_000), "MMMMMMMMMM");
}
var arab = "ARABIC NUMBERS"
var roman "ROMAN NUMBERS"
arab = roman
console.log(arab);
>npm install roman-numerals
var toRoman = require('roman-numerals').toRoman
toRoman(someNumber)
itt we waste time writing code that has already been written
>>56953222
Nice trips$ npm unpublish roman-numerals
Get fuck'd m8