{"id":253,"date":"2013-02-24T00:41:43","date_gmt":"2013-02-24T00:41:43","guid":{"rendered":"http:\/\/alexboisvert.com\/musings\/?p=253"},"modified":"2013-02-24T15:36:35","modified_gmt":"2013-02-24T15:36:35","slug":"two-related-problems-and-their-solutions","status":"publish","type":"post","link":"https:\/\/alexboisvert.com\/musings\/2013\/02\/24\/two-related-problems-and-their-solutions\/","title":{"rendered":"Two related problems (and their solutions)"},"content":{"rendered":"<p>Consider two problems you&#8217;ve probably heard before:<\/p>\n<ul>\n<li>Given a five-gallon bucket and a three-gallon bucket, measure exactly four gallons of water.<\/li>\n<li>Given a five-minute hourglass and a three-minute hourglass, measure exactly seven minutes.<\/li>\n<\/ul>\n<p>These problems are clearly related, but how?  Well, I&#8217;ll tell you how &#8212; by the good old GCD.  Here&#8217;s my method for solving these problems:<br \/>\n<!--more--><\/p>\n<ul>\n<li>Let N and M be the two numbers for the measures you have (3 and 5 in the above problems).  Let A be the amount you want to measure.<\/li>\n<li>Find d = gcd(N,M).  If A is not a multiple of d, the problem is impossible.  In our cases, we have d = 1, so we&#8217;re good.<\/li>\n<li>Find integers a, b (possibly negative) such that A = aN + bM.  This is always possible, as A is a multiple of d.  Usually it can be solved by inspection, but you can always go for the <a href=\"http:\/\/en.wikipedia.org\/wiki\/Euclidean_algorithm\">Euclidean algorithm<\/a> if you&#8217;re stuck.  For example, we have 3 * 3 &#8211; 1 * 5 = 4 (also 2 * 5 &#8211; 2 * 3) and 2 * 5 &#8211; 1 * 3 = 7.<\/li>\n<li>Use the linear combination to solve the problem!  (Wait, what?)<\/li>\n<\/ul>\n<p>The last step is the hardest to understand.  Let&#8217;s start with the buckets.  We interpret a positive bucket as filling a bucket with water, and a negative bucket as pouring one out.  So if we use the linear combination 3 * 3 &#8211; 1 * 5 = 4, we will have to fill 3 three-gallon buckets with water, and pour out 1 five-gallon bucket.  Specifically:<\/p>\n<ol>\n<li>Fill the three-gallon bucket and pour it into the five-gallon bucket. ( 1 * 3)<\/li>\n<li>Fill the three-gallon bucket again, and pour enough of it into the five-gallon bucket until the five-gallon is full (2 * 3).<\/li>\n<li>Pour out the five-gallon bucket. (2 * 3 &#8211; 1 * 5)<\/li>\n<li>Fill up the three-gallon bucket.  Now you&#8217;ve got four gallons! (3 * 3 &#8211; 1 * 5).<\/li>\n<\/ol>\n<p>That&#8217;s fairly easy to understand, because it&#8217;s easy to interpret a &#8220;negative bucket&#8221; as pouring out water.  For the hourglass problem we have to figure out how to measure &#8220;negative time.&#8221;<\/p>\n<p>We&#8217;ve got a five-minute hourglass and a three-minute hourglass.  We can subtract them to make two minutes: turn them both over at the same time.  When the three-minute one is done, there will be two left in the five-minute one.  If we then flip over the three-minute timer and wait until the five-minute one finishes, flip over the three-minute one to get two additional minutes.  See what we did there?  We measured the difference between the three-minute timer and the five-minute timer inside the three-minute timer.<\/p>\n<p>How does this apply to our problem? We&#8217;ve got 2 * 5 &#8211; 1 * 3 = 7.  Let&#8217;s separate that as 1 * 5 + ( 1 * 5 &#8211; 1 * 3) and interpret this as &#8220;Start the five-minute timer and three-minute timer at the same time.  Take the difference in the three-minute timer and add it on at the end.&#8221;  Easy-peasy!<\/p>\n<p>Challenge questions (all apply to both hourglasses and buckets):<\/p>\n<ul>\n<li>Given a four-minute hourglass and a seven-minute hourglass, measure nine minutes.<\/li>\n<li>Given a three-minute hourglass and a seven-minute hourglass, measure nine minutes.<\/li>\n<li>Given a two-minute hourglass and a seven-minute hourglass, measure nine minutes.<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Consider two problems you&#8217;ve probably heard before: Given a five-gallon bucket and a three-gallon bucket, measure exactly four gallons of water. Given a five-minute hourglass and a three-minute hourglass, measure exactly seven minutes. These problems are clearly related, but how? &hellip; <a href=\"https:\/\/alexboisvert.com\/musings\/2013\/02\/24\/two-related-problems-and-their-solutions\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9,5],"tags":[],"class_list":["post-253","post","type-post","status-publish","format-standard","hentry","category-math","category-puzzles"],"_links":{"self":[{"href":"https:\/\/alexboisvert.com\/musings\/wp-json\/wp\/v2\/posts\/253","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/alexboisvert.com\/musings\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/alexboisvert.com\/musings\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/alexboisvert.com\/musings\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/alexboisvert.com\/musings\/wp-json\/wp\/v2\/comments?post=253"}],"version-history":[{"count":6,"href":"https:\/\/alexboisvert.com\/musings\/wp-json\/wp\/v2\/posts\/253\/revisions"}],"predecessor-version":[{"id":260,"href":"https:\/\/alexboisvert.com\/musings\/wp-json\/wp\/v2\/posts\/253\/revisions\/260"}],"wp:attachment":[{"href":"https:\/\/alexboisvert.com\/musings\/wp-json\/wp\/v2\/media?parent=253"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/alexboisvert.com\/musings\/wp-json\/wp\/v2\/categories?post=253"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/alexboisvert.com\/musings\/wp-json\/wp\/v2\/tags?post=253"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}