Skip to content

Instantly share code, notes, and snippets.

@saich
Created July 1, 2012 10:40
Show Gist options
  • Save saich/3027869 to your computer and use it in GitHub Desktop.
Save saich/3027869 to your computer and use it in GitHub Desktop.
Simple automated solution to hackerrank.com beta invite challenge
var cmd = $("#prompt-input");
function newGame(num) {
triggerInput(cmd, "clear");
if(num % 6 == 0) num++;
triggerInput(cmd, "challenge " + num);
}
function triggerInput(cmd, str) {
cmd.val(str);
var evt = $.Event("keydown");
evt.keyCode = 13; // Enter..
cmd.trigger(evt);
}
cmd.ajaxSuccess(function(evt, data) {
var response = $.parseJSON(data.responseText);
var game = response.game;
var n = response.n;
game = game ? game : n ? response : null;
if(game) {
var n = parseInt(game.n, 10);
var current = parseInt(game.current, 10);
if(current > 0)
triggerInput($("#game-input"), "" + (current % 6));
else
setTimeout(newGame, 1000, n + 1); // wait for 1 second between new games...
}
});
newGame(6); // start...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment