Here you will find my answers to the problems proposed by Google in some magazines as ads, in order to hire new engineers and scientists.

Problem 1

"Communications of the ACM" (August 2004 volume 47, number 8)

The problem stated (slightly edited for sake of mathematics):

find Y such as f(f(f(Y))) = 60097
find Z such as f(f(Z)) = 1
where f(x) = 3[E(x)^3]-x
and E(x) = number of letters of x written in American English.

[The original problem stated:

To send a fax, dial the four-digit access code Y
where 60097 equals f(f(f(Y))).

This machine has extension number Z
where f(f(Z))=1.
...
]

To solve the problem I wrote a few lines of perl:

------------------------------------------------
#!/usr/bin/perl -w


my %numbers;

for(0..9999) {
        $numbers{$_} = &count_letter($_);
}

for(0..9999) {
        my $f = &my_func($_);
        my $f2 = &my_func($f);
        my $f3 = &my_func($f2);
        print "$_ $f $f2 $f3\n" if($f2 == 1);
        print "$_ $f $f2 $f3\n" if($f3 == 60097);
}

sub count_letter {
        my $n = shift;
        (my $letter = `number -l $n`) =~ s/\s+|\.|-//g;
        return length $letter;
}

sub my_func {
        my $x = shift;
        $numbers{$x} = &count_letter($x) if(!defined($numbers{$x}));
        my $c = $numbers{$x};
        my $y = 3*($c**3)-$x;
        return $y;
}
------------------------------------------------
Note: I used a small program, number , tha translates a cardinal number in its american spelling. You can find it in almost all Linux distribution and *BSD.
I left to you the exercise to run the program and find Y and Z.

Problem 3

"Linux Journal" (August 2004 issue 124)

The problem stated (slightly edited for sake of mathematics):

find A, B, C, D, E such as A*B+C-D+E not in
{94 ,134 ,233 ,426 ,496 ,915 ,917 ,1072 ,1431 ,1553 ,1569 ,1580 ,1622 ,1649 ,1673 ,1886 ,1922 ,2094 ,2139 ,2249 ,2437 ,2491 ,2569 ,2714 ,2812},
where A, B, C, D, E are permutations of
{16, 23, 61, 7, 7, 7, 13, 13, 13, 19, 19, 21, 27, 56, 56, 73, 77, 97, 11, 37, 41)}

[The original problem stated:

Press five different
buttons to be put into this formula
...
which will be calculated to get the snack you want
Identify the snack you can't get.
...
]

The permutations of k elements from a set of n are:
P(n,k) = n!/(n-k)!
P(21,5) = 21!/16! = 2441880

To solve the problem I wrote again a few lines of perl:

------------------------------------------------
#! /usr/bin/perl -w

my @buttons = (16, 23, 61, 7, 7, 7, 13, 13, 13, 19, 19, 21, 27, 56, 56, 73, 77, 97, 11, 37, 41);

my @used = split "", (0 x 21);

my %snacks = ( 917 => "0",
   134 => "0",
   1569 => "0",
   1649 => "0",
    1431 => "0",
   1622 => "0",
   233 => "0",
   2094 => "0",
   1072 => "0",
   915 => "0",
   1922 => "0",
   2437 => "0",
   2714 => "0",
   2491 => "0",
   1886 => "0",
   2812 => "0",
   426 => "0",
   1673 => "0",
   94 => "0",
   2139 => "0",
   2569 => "0",
   496 => "0",
   2249 => "0",
   1553 => "0",
   1580 =>"0"
);

for (my $a = 0; $a < 21; $a++) {
   next if $used[$a] == 1;
   $used[$a] = 1;
   for (my $b = 0; $b < 21; $b++) {
      next if $used[$b] == 1;
      $used[$b] = 1;
      for (my $c = 0; $c < 21; $c++) {
         next if $used[$c] == 1;
         $used[$c] = 1;
         for (my $d = 0; $d < 21; $d++) {
            next if $used[$d] == 1;
            $used[$d] = 1;
            for (my $e = 0; $e < 21; $e++) {
               next if $used[$e] == 1;
               my $snack = $buttons[$a] * $buttons[$b] + $buttons[$c] - $buttons[$d] +$buttons[$e];
               $snacks{$snack} = 1 if (defined $snacks{$snack} && ($snacks{$snack} == 0));
             }
             $used[$d] = 0;
         }
         $used[$c] = 0;
      }
      $used[$b] = 0;
   }
   $used[$a] = 0;
}


foreach my $snack (keys %snacks) {
   print "$snack = $snacks{$snack}\n";
}

------------------------------------------------

You're heartly welcome if you drop me a note (marco+site@equars.com) to discuss anything about the problems and their solutions.