Google Treasure Hunt

Computers, Technology — Tim Nowaczyk @ 2:10 pm

Every once in a while, I search online to see if anyone is doing Perl Golf anymore.  While looking around, I found some people discussing a new competition that Google is sponsering called the Google Treasure Hunt.  There are four questions, one per week, and the first person to answer them all, wins a prize.  Now, I’m by no means a great programmer, but I thought I’d give the questions a try.

The first question I tried, which was the current one, showed a picture of a dozen interconnected network devices and listed the routing tables of the devices.  I was asked to find the path of a packet sent from a certain host to an IP address.  I didn’t even need to write any software to do that.  Five minutes later I had the correct solution.  “Cool!  I guess I’ll try one of the older problems” I thought to myself.

The next problem also went pretty quickly.  I was asked to download a zip file which contained a bunch of files in a number of folders.  I was asked to add the number on the fourth line of any .pdf file that had ‘aaa’ in its file name or path, then add the number on the second line of any .js file with xyz in its filename or path, then multiply these two numbers.  Another easy one.

# for i in `find | grep aaa.*\.pdf`; do head -n4 $i | tail -n1; done | perl -ne '$sum += $_; END{print $sum.$/}'
# for i in `find | grep xyz.*\.js`; do head -n2 $i | tail -n1; done | perl -ne '$sum += $_; END{print $sum.$/}'

I decided to challenge myself with the third problem.  It was a recursive problem, so I figured I’d learn haskell to tackle it.  I got it to work, but it would take many hours to find the answer.

module Main where
rob 1 _ = 1
rob _ 1 = 1
rob n m =
if n == m then 2 * (rob n (n-1))
else (rob (n-1) m) + (rob n (m-1))
main = print $ rob 52 51

In the end I used perl and got the answer in a minute or so.


#!/usr/bin/perl
use bigint;

my @cache;

sub calc
{
my $m = shift;
my $n = shift;
($n, $m) = ($m, $n) if ($m < $n);

return $m if ($n == 2);

my $r = $cache[$m][$n];
return $r if ($r);

if ($m == $n) {
$cache[$m][$n] = 2 * calc($m, $n-1);
}
else {
$cache[$m][$n] = calc($m-1, $n) + calc($m, $n-1);
}
return $cache[$m][$n];
}

print calc (52, 51). $/

The fourth question came out early this morning, and is much tougher.

Question:

Find the smallest number that can be expressed as
the sum of 3 consecutive prime numbers,
the sum of 43 consecutive prime numbers,
the sum of 399 consecutive prime numbers,
the sum of 999 consecutive prime numbers,
and is itself a prime number.

For example, 41 is the smallest prime number that can be expressed as
the sum of 3 consecutive primes (11 + 13 + 17 = 41) and
the sum of 6 consecutive primes (2 + 3 + 5 + 7 + 11 + 13 = 41).

It’s another one that haskell should be really good at, but I don’t know enough of it. I could use perl, but I’d have to brute-force it. I guess I finally met my match.

Configuring Postfix to accept, but discard your mail.

Computers — Tags: — Tim Nowaczyk @ 11:40 am

I was having problems with postfix accepting a message that was addresses to 57,000 BCC’d recipients and was at a loss as to what was causing the problem.  I foolishly didn’t have verbose logging enabled before sending the message, so I didn’t have much in the way of logs.  Now, how to debug this without possibly sending lots of testing messages to the entire student body of the University.  Google wasn’t giving me anything, but I finally found the answer and am writing it down in the hopes that it helps someone.  What I wound up doing was setting up a content filter on the snmp service that redirects the mail to the discard service.

Change your smtp configuration to look like the following, then run /etc/init.d/postfix reload


smtp      inet  n       -       -       -       -       smtpd
-o content_filter=discard:dummy

Now I’m just waiting for the authorization to send some test messages to see if postfix accepts the mass mail successfully.

Home Firewall/File Server

Computers — Tim Nowaczyk @ 2:38 pm

LinkSys makes a little device, model number NSLU2. It was designed as a cheap home NAS server that uses external USB hard drives. The great thing about this device is that it runs linux. There is a project underway that has written replacement firmware for it that provides lots of new services. This is a great idea for a firewall/IDS/File Server/Wireless router type of solution.

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License.
(c) 2008 Semantic Pillow | powered by WordPress with Barecity