Created
June 30, 2009 13:36
-
-
Save hsribei/138159 to your computer and use it in GitHub Desktop.
Google Fight
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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