On Sep 19, 2007, at 10:15 AM, Mark Thomas wrote:

> Ok, here's the result of mine:
>
> mark@server1:~/rubyquiz/139$ time ./ip2country.rb 195.135.211.255
> UK
>
> real    0m0.004s
> user    0m0.004s
> sys     0m0.000s
>
>
> Here's my code:
>
> #!/usr/bin/ruby
> ARGV.each { |ip|
>   f = ip.split(/\./).join "/"
>   puts File.open(f).readlines[0] rescue puts "Unknown"
> }
>
> I think it's pretty obvious what the preparation step was. Of course,
> the tradeoff for this speed is a MASSIVE waste of disk resources, but
> that was unlimited in this contest, was it not? :-)

Pretty clever.

I bet with the right prep, this could even be a pretty viable  
approach.  Instead of building a file for each address you could  
create a directory structure for the hexadecimal representations of  
each piece of the address.  The final layer could be handled as you  
have here or with a search through a much smaller file.

James Edward Gray II