Last active
December 20, 2015 04:29
-
-
Save Cycymomo/6071684 to your computer and use it in GitHub Desktop.
140bytes - deromanize (roman to arabic) http://www.developpez.net/forums/d1362763/webmasters-developpement-web/javascript/ludique-defis-code-en-tweet/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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) ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment