Overcomplicated 2+2
by wittnl
JavaScript
// find first two domains to return HTTP 418, divide each by 209, sum and return
function ridiculous() {
this.host = "";
this.getOrigin = function getOrigin() {
if(this.host) {
var newHost = [];
var count = this.host.split("").reverse()
.map(function(char) { return char.charCodeAt(0) - 96 })
.reduce(function(prev, cur, idx) { return prev + cur * Math.pow(26, idx); });
var a = count;
a += 1; // This line is funky
c = 0;
var x = 1;
while (a >= x) {
c++;
a -= x;
x *= 26;
}
// Now you can do normal base conversion.
var s = "";
for (var i = 0; i < c; i++) {
//s = alpha.charAt(a % 26) + s;
s = String.fromCharCode(97 + a % 26) + s;
a = Math.floor(a/26);
}
this.host = s;
} else
this.host = "a";
return "http://" + this.host + ".com";
}
//var xhr = new XMLHttpRequest();
//xhr.open('GET', '/bar/foo.txt', false); // `false` makes the request synchronous
//xhr.send(null);
for(var i=0; i < Math.pow(10, 5); i++) {
console.log(this.getOrigin());
}
}
new ridiculous();