Cody

# Problem 63. Encode Roman Numerals

Solution 1782379

Submitted on 11 Apr 2019 by Yingao Zhang
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Pass
x = 1990; y_correct = 'MCMXC'; assert(isequal(dec2rom(x),y_correct))

dis = 1989 1986 1985 1981 1980 1950 1940 1900 1890 1590 1490 1090 990 dis = 1989 1986 1985 1981 1980 1950 1940 1900 1890 1590 1490 1090 990 idx = 13 romStr = "M" n = 990 dis = 989 986 985 981 980 950 940 900 890 590 490 90 -10 dis = 989 986 985 981 980 950 940 900 890 590 490 90 Inf idx = 12 romStr = "MCM" n = 90 dis = 89 86 85 81 80 50 40 0 -10 -310 -410 -810 -910 dis = 89 86 85 81 80 50 40 0 Inf Inf Inf Inf Inf idx = 8 romStr = "MCMXC" n = 0

2   Pass
x = 2008; y_correct = 'MMVIII'; assert(isequal(dec2rom(x),y_correct))

dis = 2007 2004 2003 1999 1998 1968 1958 1918 1908 1608 1508 1108 1008 dis = 2007 2004 2003 1999 1998 1968 1958 1918 1908 1608 1508 1108 1008 idx = 13 romStr = "M" n = 1008 dis = 1007 1004 1003 999 998 968 958 918 908 608 508 108 8 dis = 1007 1004 1003 999 998 968 958 918 908 608 508 108 8 idx = 13 romStr = "MM" n = 8 dis = 7 4 3 -1 -2 -32 -42 -82 -92 -392 -492 -892 -992 dis = 7 4 3 Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf idx = 3 romStr = "MMV" n = 3 dis = 2 -1 -2 -6 -7 -37 -47 -87 -97 -397 -497 -897 -997 dis = 2 Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf idx = 1 romStr = "MMVI" n = 2 dis = 1 -2 -3 -7 -8 -38 -48 -88 -98 -398 -498 -898 -998 dis = 1 Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf idx = 1 romStr = "MMVII" n = 1 dis = 0 -3 -4 -8 -9 -39 -49 -89 -99 -399 -499 -899 -999 dis = 0 Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf idx = 1 romStr = "MMVIII" n = 0

3   Pass
x = 1666; y_correct = 'MDCLXVI'; assert(isequal(dec2rom(x),y_correct))

dis = 1665 1662 1661 1657 1656 1626 1616 1576 1566 1266 1166 766 666 dis = 1665 1662 1661 1657 1656 1626 1616 1576 1566 1266 1166 766 666 idx = 13 romStr = "M" n = 666 dis = 665 662 661 657 656 626 616 576 566 266 166 -234 -334 dis = 665 662 661 657 656 626 616 576 566 266 166 Inf Inf idx = 11 romStr = "MD" n = 166 dis = 165 162 161 157 156 126 116 76 66 -234 -334 -734 -834 dis = 165 162 161 157 156 126 116 76 66 Inf Inf Inf Inf idx = 9 romStr = "MDC" n = 66 dis = 65 62 61 57 56 26 16 -24 -34 -334 -434 -834 -934 dis = 65 62 61 57 56 26 16 Inf Inf Inf Inf Inf Inf idx = 7 romStr = "MDCL" n = 16 dis = 15 12 11 7 6 -24 -34 -74 -84 -384 -484 -884 -984 dis = 15 12 11 7 6 Inf Inf Inf Inf Inf Inf Inf Inf idx = 5 romStr = "MDCLX" n = 6 dis = 5 2 1 -3 -4 -34 -44 -84 -94 -394 -494 -894 -994 dis = 5 2 1 Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf idx = 3 romStr = "MDCLXV" n = 1 dis = 0 -3 -4 -8 -9 -39 -49 -89 -99 -399 -499 -899 -999 dis = 0 Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf idx = 1 romStr = "MDCLXVI" n = 0

4   Pass
x = 49; y_correct = 'XLIX'; assert(isequal(dec2rom(x),y_correct))

dis = 48 45 44 40 39 9 -1 -41 -51 -351 -451 -851 -951 dis = 48 45 44 40 39 9 Inf Inf Inf Inf Inf Inf Inf idx = 6 romStr = "XL" n = 9 dis = 8 5 4 0 -1 -31 -41 -81 -91 -391 -491 -891 -991 dis = 8 5 4 0 Inf Inf Inf Inf Inf Inf Inf Inf Inf idx = 4 romStr = "XLIX" n = 0

5   Pass
x = 45; y_correct = 'XLV'; assert(isequal(dec2rom(x),y_correct))

dis = 44 41 40 36 35 5 -5 -45 -55 -355 -455 -855 -955 dis = 44 41 40 36 35 5 Inf Inf Inf Inf Inf Inf Inf idx = 6 romStr = "XL" n = 5 dis = 4 1 0 -4 -5 -35 -45 -85 -95 -395 -495 -895 -995 dis = 4 1 0 Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf idx = 3 romStr = "XLV" n = 0

6   Pass
x = 0; y_correct = ''; assert(isempty(dec2rom(x)))