Cycymomo
7/24/2013 - 3:34 PM

140bytes - deromanize (roman to arabic) http://www.developpez.net/forums/d1362763/webmasters-developpement-web/javascript/ludique-defis-code

/* Tests : */

console.log( deromanize("XII") + ' / ' + (deromanize("XII") === 12) );
console.log( deromanize("XLIX") + ' / ' + (deromanize("XLIX") === 49) );
console.log( deromanize("LXXIV") + ' / ' + (deromanize("LXXIV") === 74) );
console.log( deromanize("CCCLXXXIII") + ' / ' + (deromanize("CCCLXXXIII") === 383) );
console.log( deromanize("M") + ' / ' + (deromanize("M") === 1000) );
console.log( deromanize("MMMDCCCLXXXVIII") + ' / ' + (deromanize("MMMDCCCLXXXVIII") === 3888) );
// 140bytes - http://www.developpez.net/forums/d1362763/webmasters-developpement-web/javascript/ludique-defis-code-en-tweet/
/* 97b: */
function deromanize(s){
for(l=s.length,a=b=0;l;a-=i<b?d:-d,b=i)i='IVXLCDM'.search(s[--l]),d=(i%2?5:1)+'e'+(i>>1);return a
}

/* 99b: */
function deromanize(s){
for(l=s.length,a=b=0;i=j=' IVXLCDM'.search(s[--l]);a+=i<b?-d:d,b=i)for(d=1;--j;d*=j%2?5:2);return a
}