Exercises from Chapter 8
More Flavors Competing
(Found here.)
Add some more flavors to the ULTIMATE FLAVOR TOURNAMENT program, and make it so that it’s easy to add new flavors.
How You Could Do It
1: | # note: match_A_B means "round A, match B" |
- | match_1_1 = ["vanilla", "chocolate"] |
- | match_1_2 = ["rhubarb", "pistachio"] |
- | match_1_3 = ["spumoni", "green tea"] |
5: | match_1_4 = ["cherry", "strawberry"] |
- | match_2_1 = [] # this will hold the winners from 1_1 & 1_2 |
- | match_2_2 = [] # this will hold the winners from 1_3 & 1_4 |
- | match_3_1 = [] # this will hold the winners from 2_1 & 2_2 |
- | winner = nil # this will hold the final winner |
10: | |
- | def ask_for_winner(flavors) |
- | puts "0. "+flavors[0] |
- | puts "1. "+flavors[1] ... |
Get Learn to Program, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.