Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
11
Task/Roman-numerals-Decode/MATLAB/roman-numerals-decode-1.m
Normal file
11
Task/Roman-numerals-Decode/MATLAB/roman-numerals-decode-1.m
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
function x = rom2dec(s)
|
||||
% ROM2DEC converts Roman numbers to decimal
|
||||
|
||||
% store Roman digits values: I=1, V=5, X=10, L=50, C=100, D=500, M=1000
|
||||
digitsValues = [0 0 100 500 0 0 0 0 1 0 0 50 1000 0 0 0 0 0 0 0 0 5 0 10 0 0];
|
||||
% convert Roman number to array of values
|
||||
values = digitsValues(s-'A'+1);
|
||||
% change sign if next value is bigger
|
||||
x = sum(values .* [sign(diff(-values)+eps),1]);
|
||||
|
||||
end
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
romanNumbers = {'MMMCMXCIX', 'XLVIII', 'MMVIII'};
|
||||
for n = 1 : numel(romanNumbers)
|
||||
fprintf('%10s = %4d\n',romanNumbers{n}, rom2dec(romanNumbers{n}));
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue