Skip to content

Instantly share code, notes, and snippets.

@hsribei
Created June 30, 2009 13:36
Show Gist options
  • Save hsribei/138159 to your computer and use it in GitHub Desktop.
Save hsribei/138159 to your computer and use it in GitHub Desktop.
Google Fight
#!/usr/bin/env ruby
require 'rubygems'
require 'json'
require 'open-uri'
def google_fight(queries)
queries.max { |a,b| JSON.load(open("http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=#{a}"))["responseData"]["cursor"]["estimatedResultCount"].to_i <=> JSON.load(open("http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=#{b}"))["responseData"]["cursor"]["estimatedResultCount"].to_i }
end
if __FILE__ == $0
winner = google_fight(["em%20bahia", "na%20bahia"])
#=> "em%20bahia" (SURPRISE! It *should* be "na%20bahia")
puts winner
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment