Jump to Navigation

Google Treasure Hunt 2008 Question 2 Solution

Question 2 of the Google Treasure Hunt is out and is fairly easy compared to the last question. They request you to sum up numbers of a specific line in files where the path or file name contain a specific pattern and have a specific file ending. I quickly wrote an PHP script to do the job.

Here is the source:

Google Treasure Hunt Question 2 Calculation PHP Script

All you need to do is unpack the zip archive with the files in a folder named google, rename the downloaded file to google.php, change the last line accordingly to your problem and run the PHP script either via command line (you’ll need to have PHP installed for this) or via webbrowser, if you have some PHP-enabled webspace.

2 Responses to “Google Treasure Hunt 2008 Question 2 Solution”

  1. Jason:

    why do you use this?
    if(isset($c[$l])) {
    for($i=0;$i<strlen($c[$l]);$i++) {
    $result += $c[$l][$i];
    return $result;
    The sum of each digits of third line is to be found?
    And here, $r *= getsumlineoffile($file, 2);

    I haven’t check the answer, but what I understood from the question was to find the sum of line 3 from all files for first condition multiplied by sum of line 5 from all files for second condition

  2. Qian Qin:

    Looks like I didn’t read the question carefully enough. I corrected the solution a bit. Here’s the result of my script:

    Your question: 2 sums from 16572731202103087946.zip: line 1 in *mno*.pdf, line 4 in *pqr*.js
    Your answer: 4456274175
    Time received: 2008-05-20 19:21:00.414931 UTC

    Correct answer: 4456274175
    Your answer was: Correct