Skip to content

Instantly share code, notes, and snippets.

@rayning0
Last active December 24, 2015 01:29
Show Gist options
  • Save rayning0/6723770 to your computer and use it in GitHub Desktop.
Save rayning0/6723770 to your computer and use it in GitHub Desktop.
Badges
# You're hosting a conference and need to print badges for the speakers. Each badge should say: # "Hello, my name is _____."
#
# Write a method that will create and return this message, given a person's name.
def badge(name)
"Hello, my name is #{name}"
end
# Now the list of speakers is finalized, and you can send the list of badges to the printer. Remember that you'll need to give this list to the printer, so it should be accessible outside of the method.
#
# Modify your method so it can take a list of names as an argument and return a list of badge messages.
def badgelist(*names)
msg = []
names.each do |name|
name.each do |n|
msg << "Hello, my name is #{n}"
end
end
msg
end
=begin
Your conference speakers are: Edsger, Ada, Charles, Alan, Grace, Linus and Matz. How you scored these luminaries is beyond me, but way to go!
You just realized that you also need to give each speaker a room assignment. You have rooms 1-7. You'll need to print this for the speakers, so make sure to return a list of room assignments in the form of: "Hello, _____! You'll be assigned to room _____!"
=end
def roomassign
[*1..7].shuffle
end
def roomlist(*names)
room = []
r = roomassign
names.each do |name|
rm = 0
name.each do |n|
room << "Hello, #{n}! You'll be assigned to room #{r[rm]}!"
rm += 1
end
end
room
end
def printbadges
speakers = %w[Edsger Ada Charles Alan Grace Linus Matz]
badgelist(speakers).each do |b|
puts b
end
puts
roomlist(speakers).each do |r|
puts r
end
end
printbadges
=begin
Write a method that assigns each speaker to a room, and make sure that each room only has one speaker. Return a list of room assignments
Now you have to tell the printer what to print. Create a method that will output the results of the badge method and schedule method to the screen so the printer can do his thing.
Write a method to run the rest of your program and print the results to the screen. No other method should print to the screen.
=end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment