facebook Hacker Cup 2012 Qualification Round

Christian Harms's picture

The facebook hacker cup is a google-code-jam like coding contest - starting with the 2012 qualification round this weekend. Try to solve the 2011 practice round. If you can submit your solution (the spinner after submit dont stops) try to check the result response with HTTPFox (it shows the correct / incorrect response) - hoping this will be fixed for this weekend.

All solutions can be testet with codejammer.com - a fine javascript solution for running code contests like facebook hacker cup or google code jam.

Qualification Round - Double Squares

A double-square number is an integer X which can be expressed as the sum of two perfect squares. For example, 10 is a double-square because 10 = 3² + 1². Your task in this problem is, given X, determine the number of ways in which it can be written as the sum of two squares. For example, 10 can only be written as 3² + 1² (we don't count 1² + 3² as being different). On the other hand, 25 can be written as 5² + 0² or as 4² + 3².

codejamer.com screenshot

codejamer.com screenshot

See the input data in the screen shot.

  1. ({
  2.   init: function(input) { input.shift(); return input; },
  3.   task: function(input, callback) {
  4.     var a,b, count=0, sum = +input.data;
  5.     for (a=0; a<=Math.sqrt(sum);a++) {
  6.       b = Math.sqrt(sum - a*a);
  7.       count += (b==Math.floor(b) && a<=b);
  8.     }
  9.     callback('Case #' + input.index + ': ' + count);
  10.   }
  11. })

Facebook Hacker Cup Qualification Round - Studious Student

You've been given a list of words to study and memorize. Being a diligent student of language and the arts, you've decided to not study them at all and instead make up pointless games based on them. One game you've come up with is to see how you can concatenate the words to generate the lexicographically lowest possible string.

Inputdata:

5
6 facebook hacker cup for studious students
5 k duz q rc lvraw
5 mybea zdr yubx xe dyroiy
5 jibw ji jp bw jibw
5 uiuy hopji li j dcyi

Result:

Case #1: cupfacebookforhackerstudentsstudious
Case #2: duzklvrawqrc
Case #3: dyroiymybeaxeyubxzdr
Case #4: bwjibwjibwjijp
Case #5: dcyihopjijliuiuy

And my small javascript solution:

  1. ({
  2.   init: function(input) { input.shift(); return input; },
  3.   task: function(input, callback) {
  4.     var s = input.data.substr(2).split(" ");
  5.     s.sort(function(a,b){return (a+b>b+a)*2-1})
  6.     callback('Case #' + input.index + ': ' + s.join(""));
  7.   }
  8. })

Comments

How to start a blog's picture

Hey, I am not tech savy but looking to this post it seems to be an interesting stuff, Coding those not easy from distance but once we are into it, can prove very interesting topic to play with.