Created
August 14, 2010 05:15
-
-
Save akeem/524010 to your computer and use it in GitHub Desktop.
quick and dirty answer to facebook seattle puzzle
This file contains hidden or 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
require 'rubygems' | |
require 'httparty' | |
require 'set' | |
class FBProblem | |
include HTTParty | |
format :json | |
base_uri "https://graph.facebook.com" | |
@@access_token = "2227470867|2.o3hpFoWopar3qd1jeO_QxA__.3600.1281769200-604188166|S_kd755ZvAIFy9E4ocds-8IvnxA." | |
class << self | |
def friends | |
get("/me/friends",:query => {:access_token => @@access_token}) | |
end | |
def friend_likes_and_interest | |
friend_like_array = Array.new | |
FBProblem.friends["data"].each{ |friend| | |
flike = Set.new | |
finterest = Set.new | |
get("/#{friend["id"]}/likes",:query => {:access_token => @@access_token})["data"].each{|item| | |
flike.add(item["id"]) | |
} | |
get("/#{friend["id"]}/interests",:query => {:access_token => @@access_token})["data"].each{|item| | |
finterest.add(item["id"]) | |
} | |
f_data = (flike + finterest) | |
puts "#{friend["name"]} #{f_data.count}" | |
friend_like_array << f_data | |
} | |
return friend_like_array | |
end | |
def my_likes_and_interest | |
likes = Set.new | |
interest = Set.new | |
get("/me/likes",:query => {:access_token => @@access_token})["data"].each{|item| | |
likes.add(item["id"]) | |
} | |
get("/me/interests",:query => {:access_token => @@access_token})["data"].each{|item| | |
interest.add(item["id"]) | |
} | |
return likes+interest | |
end | |
end | |
end | |
my_stuff = FBProblem.my_likes_and_interest | |
friend_array = FBProblem.friend_likes_and_interest | |
current_score = 0 | |
friend_array.each{ |current_friend| | |
temp_score = current_friend.intersection(my_stuff).count | |
if temp_score > current_score | |
current_score = temp_score | |
end | |
} | |
puts "the score of similarity is #{current_score}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment