26 April 2007

fark is grabbing copyrights?

Some would think so. But if you read really closely, you're not submitting anything meaningful, you're submitting a web link. And if they want the copyright of that web link, then, ok, TinyURL it. They'll have the copyright to a TinyURL uid. And the copyright to any images on the page stay where they were.

Pretty simple.

08 April 2007

kata 6.

prag dave's anagrams resonated with me, because i'm working on hashing text down.

so follow along in irb, if you have /usr/share/dict/words:

class Symbol
def to_proc(*args) lambda {|*a| a.first.send self, *(args+a[1..-1])} end
alias [] to_proc
end # for faux currying

w = File.readlines('/usr/share/dict/words').map {|w| w.strip.downcase}.uniq ;:done
h = Hash.new([])
w.each {|word| nu = word.split('').sort.join; h[nu]+=[word]} ;:done
anas = h.values.find_all {|v| v.size > 1} ;:done
puts anas.map(&:join[',']) # all anagram n-tuples
puts "---"
puts anas.sort_by(&:size)[-30..-1].map(&:join[',']) # the top by set size
puts "---"
puts anas.sort_by {|a| a.first.size}[-30..-1].map(&:join[',']) # the top by word size

in fairness, the symbol-currying is in "sym2proc.r", so it's really just 10 lines of code, but that's the general idea.
(lots of the library functions look haskelly, but ruby just felt better for string processing)