Created
March 1, 2013 17:15
-
-
Save makersacademy/5066187 to your computer and use it in GitHub Desktop.
Ideas for an exericise
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
# Bicycles, docking stations, vans, central system to control the vans, people | |
# people would ride bikes | |
# vans would move them around | |
# a central station would control the vans | |
# repair facility would take the broken bikes and fix them | |
# repaired bikes would be delivered to stations | |
# report on the most/least used stations | |
# bikes would be taken out of service after 1000 rides | |
station # => it would have 15 bikes | |
people # => 100 | |
class Person | |
def initialize | |
@riding_a_bike = false | |
end | |
def riding_a_bike? | |
@riding_a_bike | |
end | |
def take_a_bike(station) | |
@riding_a_bike = true | |
end | |
end | |
5.times do | |
people.each{|p| p.take_a_bike(station) if rand < 0.05 } | |
people.select{|p| p.riding_a_bike? }.each{|p| p.return_a_bike(station) if rand < 0.05 } | |
puts Boris.general_report | |
# => 1 station, 10 bikes, 4 taken out | |
sleep 1 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment