Freshplum job application puzzel thingy

This was a puzzel made by the guys at Freshplum who is hiring at the moment. Hold your horse, you need to have a Ph.D. For all of us mortals with no Ph.D. (yet, hopefully) there are no more to do than solving the puzzel they made in order for people to send in their applications.

In the bottom of the hiring page https://freshplum.com/jobs/ there is the text:

Send to: x@freshplum.com where x = the number that appears most frequently below.

And below that there’s a lot of random numbers flashing by. The code generating them is here:

   1: var x;

   2: function go(){

   3:     x = Math.floor(Math.random() * 11) + Math.floor(Math.random() * 11);

   4:     $("#number").html('<p>'+ x +'</p>');

   5:     setTimeout('go()', 100);

   6: }

   7: $(document).ready(function(){

   8:     go();

   9: })

As you see in line 3, two random numbers between 0 and 10 are added together and put into #number. So the resulting number is between 0 and 20. Calculating the most common one can be done like this:

   1: $xArray = $yArray = array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10);

   2: $resultArray = array();

   3: foreach($xArray as $x) {

   4:     foreach($yArray as $y) {

   5:         $result = $x + $y;

   6:         $resultArray[$result] = $resultArray[$result] + 1;

   7:     }

   8: }

   9: foreach ($resultArray as $key => $val) {

  10:     if ($val == max($resultArray))

  11:         echo $key;

  12: }

The result of the script you can see here: http://codepad.org/YA5fX8aC

The most common number is 10, quite obvious really but there you have it.

2 Responses to Freshplum job application puzzel thingy

  1. You might be interested to know we have a new puzzle up: http://freshplum.com/puzzle/

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Go back to top