| CARVIEW |
The Lumber Room
"Consign them to dust and damp by way of preserving them"
Archive for July 2016
A simple puzzle, with a foray into inequivalent expressions
[Needs cleanup… just dumping here for now.]
Mark Jason Dominus tweeted and later blogged about this puzzle:
From the four numbers [6, 6, 5, 2], using only the binary operations [+, -, *, /], form the number 17.
When he tweeted the first time, I thought about it a little bit (while walking from my desk to the restroom or something like that), but forgot about it pretty soon and didn’t give it much further thought. When he posted again, I gave it another serious try, failed, and so gave up and wrote a computer program.
This is what I thought this time.
Idea
Any expression is formed as a binary tree. For example, 28 = 6 + (2 * (5 + 6)) is formed as this binary tree (TODO make a proper diagram with DOT or something):
+
6 *
2 +
5 6
And 8 = (2 + 6) / (6 – 5) is this binary tree:
/
+ -
2 6 6 5
Alternatively, any expression is built up from the 4 given numbers [a, b, c, d] as follows:
Take any two of the numbers and perform any operation on them, and replace the two numbers with the result. Then repeat, until you have only one number, which is the final result.
Thus the above two expressions 28 = 6 + (2 * (5 + 6)) and 8 = (2 + 6) / (6 – 5) can be formed, respectively, as:
- Start with [6, 6, 5, 2]. Replace (5, 6) with 5+6=11 to get [6, 11, 2]. Replace (11, 2) with 11*2=22 to get [6, 22]. Replace (6, 22) with 6+22=28, and that’s your result.
- Start with [6, 6, 5, 2]. Replace (2, 6) with 2+6=8 to get [8, 6, 5]. Replace (6, 5) with 6-5=1 to get [8, 1]. Replace (8, 1) with 8/1=8 and that’s your result.
So my idea was to generate all possible such expressions out of [6, 6, 5, 2], and see if 17 was one of them. (I suspected it may be possible by doing divisions and going via non-integers, but couldn’t see how.)
(In hindsight it seems odd that my first attempt was to answer whether 17 could be generated, rather than how: I guess at this point, despite the author’s assurance that there are no underhanded tricks involved, I still wanted to test whether 17 could be generated in this usual way, if only to ensure that my understanding of the puzzle was correct.)
Written by S
Wed, 2016-07-20 at 00:38:51
Posted in mathematics, unfinished
Pages
Archives
- December 2016 (1)
- July 2016 (1)
- March 2016 (3)
- January 2016 (1)
- September 2015 (2)
- August 2015 (1)
- June 2015 (2)
- April 2015 (1)
- February 2015 (2)
- January 2015 (3)
- August 2014 (1)
- July 2014 (1)
- June 2014 (3)
- May 2014 (1)
- March 2014 (2)
- February 2014 (1)
- January 2014 (1)
- November 2013 (1)
- October 2013 (1)
- September 2013 (1)
- August 2013 (1)
- April 2013 (4)
- March 2013 (1)
- January 2013 (1)
- October 2012 (1)
- September 2012 (1)
- August 2012 (3)
- April 2012 (1)
- March 2012 (1)
- January 2012 (1)
- December 2011 (1)
- November 2011 (1)
- October 2011 (1)
- August 2011 (1)
- June 2011 (3)
- May 2011 (6)
- April 2011 (2)
- March 2011 (2)
- January 2011 (4)
- December 2010 (1)
- November 2010 (3)
- October 2010 (1)
- September 2010 (4)
- August 2010 (1)
- July 2010 (3)
- June 2010 (5)
- May 2010 (5)
- April 2010 (4)
- March 2010 (6)
- February 2010 (4)
- December 2009 (2)
- September 2009 (3)
- August 2009 (6)
- July 2009 (1)
- June 2009 (1)
- May 2009 (4)
- March 2009 (5)
- January 2009 (2)
- December 2008 (3)
- November 2008 (6)
- October 2008 (4)
- September 2008 (3)
- August 2008 (4)
- July 2008 (6)
- May 2008 (5)
- April 2008 (5)
- March 2008 (8)
- February 2008 (6)
- January 2008 (13)
- December 2007 (26)
- November 2007 (16)
- October 2007 (23)
- September 2007 (8)
- August 2007 (9)
- July 2007 (11)
- June 2007 (3)
- May 2007 (5)
- April 2007 (10)
- March 2007 (19)
- February 2007 (13)
- January 2007 (21)
- December 2006 (6)
- November 2006 (13)
- October 2006 (11)
- September 2006 (8)
- July 2006 (1)
- June 2006 (1)
- May 2006 (1)
- April 2006 (3)
- March 2006 (1)
- February 2006 (1)
- January 2006 (1)
- December 2005 (3)
- November 2005 (3)
| S | M | T | W | T | F | S |
|---|---|---|---|---|---|---|
| 1 | 2 | |||||
| 3 | 4 | 5 | 6 | 7 | 8 | 9 |
| 10 | 11 | 12 | 13 | 14 | 15 | 16 |
| 17 | 18 | 19 | 20 | 21 | 22 | 23 |
| 24 | 25 | 26 | 27 | 28 | 29 | 30 |
| 31 | ||||||
Meta
Blog Stats
- 1,160,045 hits
-
Subscribe
Subscribed
Already have a WordPress.com account? Log in now.