9
$\begingroup$

Sorry to post what is probably a very pedestrian question here (it's actually from my son's homework; he's eight), but it's driving us crazy and I really want to know how I'm meant to approach it.

We need to write an expression that uses the numbers 1, 2, 3, 4, 5, 6 and 7, in that order, to give an answer of 100. We can use multiplication, division, addition and subtraction operators, and brackets.

Is there a technique here or is brute force the correct approach. I'm a software developer and I can't even work out how to write a program to solve this.

  • 0
    This does not provide an answer to the question. Once you have sufficient [reputation](http://math.stackexchange.com/help/whats-reputation) you will be able to [comment on any post](http://math.stackexchange.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](http://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/low-quality-posts/685336)2016-09-21

7 Answers 7

0

This explanation is perfect. I think the teacher's objective behind giving the question at eight year old level must have been to make them think this way. The fact $6 \times 7 = 42$ should immediately hit you. That is when you will be able to like .. well, I need one or more products that add or subtract close to $100$, and I need the rest of the numbers to make up the difference.

Beautiful exercise in thinking.

15

From a brute force Python program, here's the list of possible solutions. I apologize for the "mathematical duplicates" caused by the inclusion of parenthesis, but the list was too long to QC.

+1.0-2.0+3.0+(4.0*5.0-6.0)*7.0 +1.0-2.0+3.0+(4.0*(5.0)-6.0)*7.0 +1.0-2.0*3.0+(4.0+5.0+6.0)*7.0 +1.0-2.0*3.0+(4.0+(5.0)+6.0)*7.0 +1.0+(2.0+3.0)*4.0*5.0+6.0-7.0 +1.0+(2.0+3.0)*4.0*5.0+(6.0)-7.0 +1.0+(2.0+3.0)*4.0*(5.0)+6.0-7.0 +1.0-(2.0)+3.0+(4.0*5.0-6.0)*7.0 +1.0-(2.0)+3.0+(4.0*(5.0)-6.0)*7.0 +1.0-(2.0)*3.0+(4.0+5.0+6.0)*7.0 +1.0-(2.0)*3.0+(4.0+(5.0)+6.0)*7.0 -1.0+2.0*3.0*4.0+(5.0+6.0)*7.0 -1.0+2.0*(3.0*4.0*5.0-6.0)-7.0 -1.0+2.0*(3.0*4.0*(5.0)-6.0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nums = range(1,8)  for someSigns in itertools.product(signs,repeat=7):     evalStr = ""     for i, j in zip(someSigns, nums):         evalStr += i + str(float(j))     try:             if eval(evalStr) == 100:                 print evalStr     except:         continue 
  • 0
    Genius - thanks, Mark!2012-09-24
12

$-1\cdot2+3\cdot4\cdot5+6\cdot7$ There is no general method that I am aware of.

  • 2
    Just wrote a quick brute force python program. Without using parenthesis to change the order of operations, this is the only correct answer.2012-09-23
7

Another way:

$-1\cdot 2-3+(4+5+6)\cdot 7$

  • 0
    Thanks a lot, Argon! Thanks for correcting my tags as well :-)2012-09-23
5

Let's try something a little simpler.

The first step is to get a feel for things. What happens if we add up all the numbers 1+2+...+7? We get 28, which is too small. How do we get a bigger number? Subtracting or dividing will just make it smaller. So we have to multiply. We need it about 4 times bigger (3 x 28 = 84, 4 x 28 = 112). Well that is a bit misleading because the 4 will not be multiplying itself, it is more like 4*24. But let's get on and try 4.

There are two obvious ways of getting multiplication by 4. The first is (1+2+3) 4+5+6+7=42 - too small. [Bother cannot figure out how to turn off the italics!] The other is (1+2+3)+4(5+6+7) = 78. Still too small. So this is slightly trickier than it looks.

If we go to 5*(6+7) it will be too big.

Pause. 6*7=42. And (3*4*5)=60. So that would get us close. To 102 in fact. Could we get the -2 from the 1,2,3? That bit I leave to you.

But you may still complain that I pulled 6*7 and 3*4*5 out of thin air. Well, not completely. My thought process was as follows:

I need something bigger. 6*7=42. Oh, but then 3*4*5=60.

That does not look like a particularly logical progression. It isn't logical, but it is natural. 6,7 just shrieks 42. That is hardwired into my brain. 3,4,5 certainly whispers 60, maybe even speaks it.

There are for me two lessons from this. (1) you need to rote learn things. No progress is possible until your brain is stocked with useful facts. They have to be in your brain. Because you need really fast retrieval. If you have to mess around working out 6*7=42, it is much harder. (2) You need some organised playing around. By far the best books on that are the old Polya ones. An 8 year old could probably cope with his short book.

2

If you want a general solution you can just bruteforce it. My naive approach was to print out all possible strings and eval them.

I've put up the source code to do this and like tasks at my Github repository: https://github.com/cairo140/operations

I had to invent a notationally odd superplus and superminus. Basically, x.superplus(y) is equivalent to (x+y) so that 1*2.superplus(3)*4 is 1*(2+3)*4. I believe that between allowing a - to be put ahead of the leading 1 and using superplus and superminus, you can account for all possible permutations ordinarily available through parentheses. I haven't convinced myself of this fact yet, but counterexamples are welcome.

These are all the possible solutions to get 100. Both the examples posted at this time are included in the result set. At the moment, unfortunately there can be redundant solutions.

100=-1+2.superplus(3)*4*5-6+7 100=1+2.superplus(3)*4*5+6-7 100=-1*2+3*4*5+6*7 # did's solution 100=-1+2*3*4+5.superplus(6)*7 100=-1*2-3+4.superplus(5).superplus(6)*7 100=1-2*3+4.superplus(5).superplus(6)*7 100=-1*2.superplus(3)+4.superplus(5).superplus(6)*7 # Argon's solution 100=1*2.superplus(3)*4*5+6/7 100=1*2.superplus(3)*4*5-6/7 100=1+2.superplus(3)*4*5+6.superminus(7) 100=-1+2.superplus(3)*4*5-6.superminus(7) 100=-1*2.superplus(3)*4*5*6.superminus(7) 100=-1*2.superplus(3)*4*5/6.superminus(7) 

Some other examples (e.g., at least one way to use 1 2 3 4 5 6 7 to get each number up to 100) are available at the Github repository.

  • 0
    Good solution (cleaner code then my hack), but it doesn't take into division and multiplication with parens.2012-09-23
2

The answer to this question is as follows, 1+2+34+56+7=100. We have now used all of the numbers required to equal 100.

  • 0
    this is kinda brilliant, but i'd like to hear if this is within the rules!2016-07-02