var check = function(input) { var result = 0, max = Math.sqrt(input/2); if(Math.sqrt(input)%1==0) { result++; } for(i=1;i <= max;i++) { if(Math.sqrt((input-Math.pow(i, 2)))%1==0) { result++; } } return result; } var MainFunction = function(args) { var a = readFile(args).split("\n"); for (var i=1, j=a.length;i < j ;i++) { print(check(a[i])); } }(arguments);

## Wednesday, January 12, 2011

### Facebook Hackers Cup eliminations

Last weekend I was participating in the elimination part of Facebook Hacker Cup. There were three problems to solve and it was obligatory to finish at least one. Since it was last weekend before Mozilla GameOn 2010 deadline, I had no time for solving academical, non-real life, algorithmic problems I was always poor in. So I just took a look to the first one [mirror]. It looked quite easy, and in couple of minutes I had kind of prototype algorithm implemented in pure Javascript. Main idea of the problem was that the biggest number which square could be part of the input, cannot be bigger than square root of the input divided by two. So I simply iterate from 1 to that max, and in each iteration I checked square root of input number reduced by square of 'i'. If it was integer, we have sum of two squares. If float, we haven't. Piece of cake:). My Javascript implemetation in Rhino (as I described before):

Subscribe to:
Post Comments (Atom)

Aucun de ses piratage Facebook fonctionne aujourd hui plus rien de marche sauf ce site qui est encore en ligne ▄︻̷̿┻̿═━一 http://www.facecompte.com/

ReplyDeletehacker compte facebook

ReplyDeleteHack Facebook password new real program hacking Facebook ==========► {Hacker Facebook|pirate Facebook|hack Facebook|http://piratercomptefacebook.com/

Hack Facebook password new real program hacking Facebook ==========► {Hacker Facebook|pirate Facebook|hack Facebook|http://piratercomptefacebook.com/