Skip to content

Instantly share code, notes, and snippets.

@bitdivine
Created August 10, 2015 14:20
Show Gist options
  • Save bitdivine/661431f858eb679f6a91 to your computer and use it in GitHub Desktop.
Save bitdivine/661431f858eb679f6a91 to your computer and use it in GitHub Desktop.
2->di 3->tri 16->hexakaideca 20->dodeca ... git it?
// 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));
}
@bitdivine
Copy link
Author

bitdivine commented Jul 6, 2016

[4,6,8,12,20].map((x)=>grekify(x)+"hedron")

Yields:

["tetrahedron", "hexahedron", "octahedron", "dodecahedron", "icosahedron"]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment