Skip to content

Instantly share code, notes, and snippets.

@ivanpepelko
Last active December 11, 2015 10:19
Show Gist options
  • Save ivanpepelko/ab48e7023b9f5d011a33 to your computer and use it in GitHub Desktop.
Save ivanpepelko/ab48e7023b9f5d011a33 to your computer and use it in GitHub Desktop.
javascript:!function(){var r=prompt("Complexity?","ABCDEFGH"),t="";if(null===r)return!1;var n=parseInt(r);if(Number.isNaN(n))t=r.split("");else{isN=isN>16?8:isN;for(var o=0;o<isN;o++)t+=String.fromCharCode(65+o);t=t.split("")}var i=[];t.forEach(function(r){i.push([r,5*Math.round(4*Math.random()+1)])}),i=i.sort(function(r,t){return r[1]-t[1]});var a="",e="";return i.forEach(function(r){a+=r[0].repeat(r[1]),e+=r[0]+": "+r[1]+"\n"}),confirm(e)?void(location.href="http://huffman.ooz.ie/?text="+a):!1}();
(function() {
var comp = prompt("Complexity?", "ABCDEFGH");
var letters = "";
if (comp !== null) {
var trynum = parseInt(comp);
if (Number.isNaN(trynum)) {
letters = comp.split("");
} else {
isN = isN > 16 ? 8 : isN;
for (var i = 0; i < isN; i++) {
letters += String.fromCharCode(65 + i);
}
letters = letters.split("");
}
} else {
return false;
}
var occ = [];
letters.forEach(function(val) {
occ.push([val, Math.round(Math.random() * 4 + 1) * 5]);
});
occ = occ.sort(function(a, b) {
return a[1] - b[1];
});
var str = "",
task = "";
occ.forEach(function(val) {
str += val[0].repeat(val[1]);
task += val[0] + ": " + val[1] + "\n";
});
if (confirm(task)) {
location.href = "http://huffman.ooz.ie/?text=" + str;
} else {
return false;
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment