Created
August 10, 2015 14:20
-
-
Save bitdivine/661431f858eb679f6a91 to your computer and use it in GitHub Desktop.
2->di 3->tri 16->hexakaideca 20->dodeca ... git it?
This file contains 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
// Language constants. | |
var x = ' hen di tri tetra penta hexa hepta octa ennea deca hendeca dodeca triskaideca tetrakaideca pentakaideca hexakaideca heptakaideca octakaideca enneakaideca icosa'.split(' '); | |
var y = ' ,,icosa,conta ,hecato,diacosio,cosioi ,chilia,diachilia,chilia'.split(' ').map(function(s){return s.split(',')}); | |
var z = x.map(function(x){return x+(x[x.length-1]==='a'?'':'a')}); | |
// Convert any number - up to a few thousand, to a numeric prefix. | |
function grekify(n){ | |
n = String(n); // Greek numbers are deca-mal | |
return x[n] || n && [(n[0]>2?z[n[0]]:''),y[n.length][n[0]>2?3:n[0]],grekify(n.slice(1))].join(''); | |
} | |
// Test: | |
for (i=1;i<30;i++){ | |
console.log(i,grekify(i)); | |
} | |
for (i=30;i<1000;i+=Math.floor(Math.random()*10)){ | |
console.log(i,grekify(i)); | |
} | |
for (i=1;i<=1<<10;i=i<<1){ | |
console.log(i,grekify(i)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yields: