| about | help | code help+videos | done | prefs |
transfer_water
This was the CarTalk Puzzler called "Two Glasses of Water Puzzler": RAY: This Puzzler was sent in by Frank Juskolka. Frank writes, "You have a four-ounce glass and a nine-ounce glass. You have an endless supply of water. You can fill or dump either glass. TOM: Do you have a plastic bag in your pocket? No. Okay. Just checking. RAY: It turns out, you can measure six ounces of water using these two glasses. The question is: 1. How many steps are involved; and B. What's the fewest number of steps in which you can measure six ounces? Well, that was how the question was phrased on CarTalk. It seems to me that 1. and B. are a bit redundant, so we'll change things up a bit, and we'll take the puzzle in two pieces. In this first piece you are asked to asked to define the function transfer_water(a, b, A, B), in which the parameters a and b represent the number of ounces currently in two glasses, and A and B represent the capacity of the two glasses. The function should return a list of (a, b) pairs representing all the possible measurements you can get to with one pouring. The items in the list should be in sorted order, and there should be no duplicates. It should be mentioned that in addition to filling or dumping a glass, you can pour from one glass to the other, until one glass is full or the other is empty, whichever comes first. ...Save, Compile, Run (ctrl-enter) |
Progress graphs:
Your progress graph for this problem
Random user progress graph for this problem
Random Epic Progress Graph
Difficulty: 900 Post-solution available
Copyright Nick Parlante 2017 - privacy