Friday, February 20, 2009

A page about the wide finder

I have published the page of wide finder, which was created for a group discussion on Erlang.

The problem of wide finder was coined by Tim Bray, and is summarized in

The task is to read an Apache logfile and figure out which pages have been fetched the most.

The reference Ruby code

# 11 lines

counts = {}
counts.default = 0
ARGF.each_line do |line|
if line =~ %r{GET /ongoing/When/\d\d\dx/(\d\d\d\d/\d\d/\d\d/[^ .]+) }
counts[$1] += 1
keys_by_count = counts.keys.sort { |a, b| counts[b] <=> counts[a] }
keys_by_count[0 .. 9].each do |key|
puts "#{counts[key]}: #{key}"

Bray's original idea was to check if Erlang is good option for this problem on multi-core platforms.
Read more ...