Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Node
- attr_accessor :name, :film_actor_hash
- def initialize(name)
- # Pass in film name and returns all actors in that film
- @film_actor_hash = Hash.new
- @name = name
- end
- end
- def bacon_links(node, counter)
- counter =|| 0
- node.film_actor_hash.each do |film, actors|
- actors.each do |actor|
- if actor.name == "Kevin Bacon"
- return film
- else
- counter += 1
- return if counter > 5
- bacon_links(actor, counter)
- end
- end
- end
- end
- def find_kevin_bacon(start_node)
- bacon_list = []
- start_node.film_actor_hash.each do |film, actors|
- actors.each do |actor|
- if actor.name == "Kevin Bacon"
- bacon_list << film
- else
- link = bacon_links(actor)
- bacon_list << link
- end
- end
- end
- bacon_list
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement