News for hackers. Stuff that matters.
Re:Is this prime? by gfmio on Tuesday March 08, 2016 @05:36PM (#11249361)
24607 (with the cheat), 621 (without) :D Fun evening challenge :P

  function isPrime(n){
    if ((n<=1) || (!n % 2)) {
      return false;
    }

  for (var k = 3; k < Math.round(Math.sqrt(n) + 0.5); k = k+2) {
      if (n % k == 0) {
        return false;
      }
    } 
    return true;
  }
  var nSpan = $("span#n")
  var yesButton = $("button#yes");
  var noButton = $("button#no");
  var body = $("body");
  function solve(){
    if (isPrime(parseInt(nSpan.innerHTML)) {
      yesButton.click();
    } else {
      noButton.click();
    }
    if (body.className != "end") {
      setTimeout(solve,0);
    }
  }
  solve();

There are no comments on this comment yet.