Last active
December 28, 2015 14:49
-
-
Save jgaskins/7517415 to your computer and use it in GitHub Desktop.
The enemy of my enemy of my enemy of my enemy of my enemy of my enemy is Kevin Bacon
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
class Person | |
attr_reader :name, :enemies | |
def initialize name | |
@name = name | |
@enemies = [] | |
end | |
def add_enemies enemies | |
@enemies.concat enemies | |
end | |
end | |
people = 100.times.map { |i| Person.new(i.to_s) } | |
people.each { |person| person.add_enemies people.sample(3) } | |
people.sample.enemies << Person.new("Kevin Bacon") | |
enemies = people.sample.enemies | |
6.times do |i| | |
enemies += enemies.flat_map(&:enemies).uniq | |
end | |
p enemies.map(&:name).include? "Kevin Bacon" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment