News for hackers. Stuff that matters.
Re:Put your programming skills to the test by laacz on Sunday February 12, 2012 @11:37AM (#3582181)
Divisible by 7 or 5. Not only 7.
Re:Put your programming skills to the test by tzs on Sunday February 12, 2012 @03:24PM (#3582879)
You are thinking of the challenge on the front page. He's talking about the first of the three "guest challenges" you get if you click the link on the front page to see more challenges.

The front page challenges asked for the sum of the integers from 1 to 1000, excluding those divisible by 5 or 7. Here was my sort of smart-ass answer:

   function jsChallenge() { 
     var num = 1000;
     var t = num;
     var sum = t*(t+1)/2;
     t = Math.floor(num/5);
     sum -= 5*t*(t+1)/2;
     t = Math.floor(num/7);
     sum -= 7*t*(t+1)/2;
     t = Math.floor(num/35);
     sum += 35*t*(t+1)/2;
     return sum;
}

The first guest challenge asks for the sum of the integers from 1 to 1000, excluding those that contain the digit 7.

Re:Put your programming skills to the test by cjhopman on Sunday February 12, 2012 @05:08PM (#3583191)
If you're going to be a smart-ass, then go all out.

  function jsChallenge() {
    function sum(n) {
      var k = Math.floor(1000 / n);
      return n * k * (k + 1) / 2;
    };
    return sum(1) - sum(5) - sum(7) + sum(35);
  }