Created
September 22, 2015 17:20
-
-
Save lortza/b8243392bffe4ef44588 to your computer and use it in GitHub Desktop.
Proposed quiz question for Tealeaf Academy Course 1, Lesson 1
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
# You are hosting a seminar and need to assign seats to your attendees. | |
# You have 3 rows with 3 seats in each row (total 9 seats). You have 6 attendees. | |
# Assign each person a seat making sure that everyone is seated as close | |
# to the front as possible. Row A is the first row. A seat name looks | |
# like "A1", not "1A". Then output a list of names and seat numbers so | |
# the usher can seat each person in the right place. | |
rows = ["A", "B", "C"] | |
seat_numbers = [1, 2, 3] | |
people = ["Angela", "Bill", "Christine", "Darla", "Edward", "Frank"] | |
# ======== SOLUTION ============ | |
available_seats = [] | |
seat_assignments = [] | |
# Create array of available seats | |
rows.each do |row| | |
seat_numbers.each do |num| | |
available_seats << "#{row}#{num}" | |
end#seat_numnbers | |
end #rows | |
# Assign a seat to each person | |
people.each do |person| | |
seat_assignments << {:name => "#{person}", :seat => "#{available_seats.shift}"} | |
end#people.each | |
# Generate list of names and seat assignments | |
seat_assignments.each do |person| | |
puts "#{person[:name]}: #{person[:seat]}" | |
end#seat_assignments.each |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment