18
$\begingroup$

I consider it an amazing though very challenging puzzle:

1 2 3 4 5 = 5 4 3 2 1

One must insert exactly five pluses (i.e. five addition signs) somewhere between those ten displayed figures in such way that it becomes a true mathematical equality. Also, you can't rearrange/transpose the figures; no other inserts (no other symbols) besides five pluses are allowed; decimal positional system is used.

Today I gave thought to it and I actually managed to solve it on my own. My problem is I solved it by accident. It was luck!

The question is: can it be solved rationally? I.e. does this puzzle have a precise and thorough solution (when you realize what you are doing and there is no chance for mistakes)? One thing is luck, another thing is mathematical approach.

$\endgroup$
6
  • 13
    $\begingroup$ As a side note, the number of the ways to insert the plus signs is finite, and checking every single option is also very much a mathematical approach. $\endgroup$ Dec 6, 2023 at 21:52
  • 1
    $\begingroup$ @RomanOdaisky: add to this that some alternatives can be dismissed right off the bat. For example '543' can not be one unit since the left side cannot approach it (it's either too much 1234 or too little 123 + something) $\endgroup$ Dec 7, 2023 at 16:41
  • $\begingroup$ @RomanOdaisky also, the numbers of ways to solve the problem is not only finite, but even if we were allowed to insert 8 plus signs, that would turn up to only 64 possible combinations. $\endgroup$ Dec 7, 2023 at 16:44
  • 1
    $\begingroup$ Between probably doesn't include just adding one in front? $\endgroup$
    – DonQuiKong
    Dec 8, 2023 at 6:30
  • 1
    $\begingroup$ @QuoraFeans $2^8=256$ possibilities for up to 8 plus signs. $\endgroup$ Dec 8, 2023 at 17:09

11 Answers 11

28
$\begingroup$

Another way to think about it is to start with plus signs in all eight positions. The sums are equal at $15$. When you remove a plus sign you add

$9$ times the digit that moves from the ones place to the tens place. We need the new tens digits to add to the same value on both sides of the equation. We can't move successive digits because removing plus signs on two digits in a row will move one to the hundreds place. If something moves to the hundreds place the other side only loses one plus sign and can't move anything to the hundreds place to match. The only addition facts of interest are $1+3=4, 1+4=5$. We can only move the $1$ on the left side of the equation, so the $4$ and $5$ must be on the right. This gives the two solutions

$12+34+5=5+43+2+1$ and $12+3+45=54+3+2+1$.

$\endgroup$
3
  • 5
    $\begingroup$ This is a really nice and rigorous way to prove it. $\endgroup$
    – justhalf
    Dec 7, 2023 at 5:28
  • $\begingroup$ To make this reasoning complete you need to mention that there cannot be a solution with a 3-digit number in it. $\endgroup$
    – Stef
    Dec 9, 2023 at 16:21
  • $\begingroup$ @Stef: I added it. $\endgroup$ Dec 9, 2023 at 16:23
39
$\begingroup$

Well, here is how I would (and did) solve it:

First step: Without the « five + » constraint

Well: 1+2+3+4+5 = 5+4+3+2+1. That is not the difficult part; this is just the commutative property of the addition.

Second step: Getting rid of some « + »

Our previous solution had eight « + » ; we want only five, so we need to get rid of three of them. If we decide to get rid of three « + » on the same side of the equation, we would get a sum with a 3-digit or 4-digit number on one side, and 15 on the other side. Therefore, we need to get rid of two « + » on one side and one « + » on the other side. Obviously, the side on which we would remove two « + » signs will quickly get big because we would have at least two two-digit numbers in the sum. To find a solution, I would therefore try to minimize that sum, and so I tried 12+34+5 = 51. Now, we need to see if we can work out the right side with only one « + » removal to make it equal to 51. We see quickly that removing the « + » between 5 and 4 would give 54 (too much), so we try removing the one between 4 and 3: 5+43+2+1=51.

A solution we found:

12+34+5=5+43+2+1

Extra note: finding all solutions

The maximum value you can make by removing only one « + » on either side is 60: 54+3+2+1. The second minimum value you can make by removing two « + » is also 60: 12+3+45. Therefore, there is one and only one other solution to the problem: 12+3+45=54+3+2+1.

$\endgroup$
3
  • $\begingroup$ Seems like a lot of irrelevant stuff, aside from the actual answer. $\endgroup$
    – paddotk
    Dec 8, 2023 at 16:08
  • 16
    $\begingroup$ @paddotk - what an incredibly odd thing to claim. Showing how an answer can be obtained in a systematic manner, and using that information to show that you have obtained not just a few answers, but all possible answers is far from "irrelevant". $\endgroup$ Dec 8, 2023 at 16:30
  • 10
    $\begingroup$ @paddotk The OP specifically requested not a solution to the problem, but an explanation of a methodical way of solving it, which is exactly what Jujustum delivered. $\endgroup$ Dec 8, 2023 at 20:02
13
$\begingroup$

The plus sign is also a unary operator. Therefore a solution with four plus signs

1+23+45 == 5+43+21 == 69

is also valid for five plus signs:

+1+23+45 == 5+43+21 == 69

$\endgroup$
3
  • 1
    $\begingroup$ The phrasing is "somewhere between", which I think precludes inserting one at the start. $\endgroup$
    – HappyDog
    Dec 8, 2023 at 12:11
  • 2
    $\begingroup$ You can put it anywhere you want. A+B is the same as A+(+B) (parentheses optional, but included for readability) $\endgroup$
    – tolos
    Dec 8, 2023 at 14:08
  • 2
    $\begingroup$ Yes, or put it before the 5 on the right-hand side. $\endgroup$ Dec 8, 2023 at 20:04
6
$\begingroup$

It seemed like there should be more addition signs on the right than left because the numbers you could make on the right side by omitting plus signs are bigger on account of the bigger numbers coming first.

Son I decided to start with something that seemed like it was in the middle of possibilities for the left side:

12 + 34 + 5

From there, it didn't take long to find a matching answer on the other side:

5 + 43 + 2 + 1

So that's my answer:

12 + 34 + 5 = 5 + 43 + 2 + 1

$\endgroup$
4
$\begingroup$

Here is a way to solve this problem using python:

# Solving the equation 1 2 3 4 5 = 5 4 3 2 1 by inserting five pluses to make both sides equal
# We need to find a way to arrange the pluses so that the sums of both sides are equal

# Possible approach: Try different combinations of pluses on each side and check if they match

def find_solution():
    # Possible positions to insert pluses (4 positions between 5 numbers)
    positions = [1, 2, 3, 4]

    # Iterate through all combinations of 5 pluses in these positions
    for i in range(1, 16):  # 15 = 1111 in binary, so iterate through 1 to 15 (binary: 0001 to 1111)
        for j in range(1, 16):
            left_pluses = format(i, '04b').count('1')
            right_pluses = format(j, '04b').count('1')

            # Only consider combinations where total pluses are 5
            if left_pluses + right_pluses == 5:
                left = ''
                right = ''

                # Construct the left side
                for k in range(4):
                    left += str(k + 1)
                    if format(i, '04b')[k] == '1':
                        left += '+'

                left += '5'

                # Construct the right side
                for k in range(4):
                    right += str(5 - k)
                    if format(j, '04b')[k] == '1':
                        right += '+'

                right += '1'

                # Evaluate both sides
                if eval(left) == eval(right):
                    return left, right

    return "No solution found"

# Find the solution
find_solution()
$\endgroup$
1
  • 2
    $\begingroup$ You can make this much shorter using the itertools module. You should also yield instead of returning; or, raise an exception instead of return "No solution found". $\endgroup$
    – wizzwizz4
    Dec 8, 2023 at 19:17
4
$\begingroup$

Solution that produces the result

+1+23+45=5+43+21 = 69
1++23+45=5+43+21 = 69
1+23++45=5+43+21 = 69
1+23+45=+5+43+21 = 69
1+23+45=5++43+21 = 69
1+23+45=5+43++21 = 69
12+3+45=54+3+2+1 = 60
12+34+5=5+43+2+1 = 51

Code in C is

#include <stdio.h>                                                                                                                                                         
#include <stdlib.h>                                                                                                                                                        
#include <string.h>                                                                                                                                                        
static size_t EvalSide(char* s, char** endp ){                                                                                                                             
    size_t sum = 0;                                                                                                                                                        
    for (;;) {                                                                                                                                                             
        while ( *s == '+') //skip unary '+'                                                                                                                                
            ++s;                                                                                                                                                           
        if (*s == '=' || *s == '\0') // '=' ends lhs; '\0' ends rhs                                                                                                        
            break;                                                                                                                                                         
        char* p;                                                                                                                                                           
        sum += strtoul(s, &p, 10);                                                                                                                                         
        s = p;                                                                                                                                                             
    }                                                                                                                                                                      
    *endp = s;                                                                                                                                                             
    return sum;                                                                                                                                                            
}                                                                                                                                                                          
static void Test(char* s) {                                                                                                                                                
    char* end_p;                                                                                                                                                           
    size_t lhs = EvalSide(s, &end_p);                                                                                                                                      
    size_t rhs = EvalSide( end_p+1, &end_p);                                                                                                                               
    if ( lhs == rhs )                                                                                                                                                      
        printf("%s = %zu\n", s, lhs);                                                                                                                                      
}                                                                                                                                                                          
static void InsertPlusses(char* s0, char*s, size_t len_s, size_t count){                                                                                                   
    if (count == 0)                                                                                                                                                        
        Test(s0);                                                                                                                                                          
    else                                                                                                                                                                   
        while ( count <= len_s ) { // while long enough to insert count '+'s                                                                                               
            if (s[0] != '=') { // don't insert '+' before '='                                                                                                              
                for (size_t k = len_s; 0 < k; --k) // insert '+' at start                                                                                                  
                    s[k] = s[k-1];                                                                                                                                         
                s[0] = '+';                                                                                                                                                
                InsertPlusses(s0, s+1, len_s, count-1); // insert remaining +'s after this one                                                                             
                for (size_t k = 0; k < len_s; ++k) // uninsert '+'                                                                                                         
                    s[k] = s[k+1];                                                                                                                                         
            }                                                                                                                                                              
            ++s; --len_s; // try next position                                                                                                                             
        }                                                                                                                                                                  
}                                                                                                                                                                          
int main(void)  {                                                                                                                                                          
    char s0[]="12345=54321\0\0\0\0\0\0"; // padding for 5 '+'s and terminator '\0'                                                                                         
    InsertPlusses(s0, s0, strlen(s0), 5);                                                                                                                                  
    return 0;                                                                                                                                                              
} 
$\endgroup$
3
$\begingroup$

This interested me so much I created an account just to respond!

Take the generalised case:

x x+1 x+2 x+3 x+4 = x+4 x+3 x+2 x+1 x

Try a solution at random

x * (x+1) + (x+2) + (x+3) * (x+4) = (x+4) + (x+3) + (x+2) + (x+1) * x

(x^2 + x) + x + 2 + (x^2 + 7x + 12) = 3x + 9 + (x^2 +x)

x^2 + 8x + 14 = 3x + 9

x^2 + 5x + 5 = 0

This gives us two values for x

I know that this does not necessarily give a solution as to where the plus signs should go to solve the specific problem you stated, what it does do is prove that for any positions of the plus signs, there exists solutions for x for the problem.

I think...

Could be wrong though, please correct me if so

-- Edit --

Have left the above as an example of my own stupidity, re-reading the question I see that no multiplication is allowed.

However concatenating (is that word applicable here?) two numbers in decimal, say x and x+1, gives you an equation for x without the squared terms, 10*x + (x+1) in this case.

Solving both sides as above for any specific positions of plus signs still gives an equation in x, which would solve for a single value of x.

$\endgroup$
3
$\begingroup$

Another brute-force Python solution, but shorter:

import itertools

MAYBE_PLUS = ['', '+']

for plusses in itertools.product(*([MAYBE_PLUS] * 8)):
    equation = '1{}2{}3{}4{}5==5{}4{}3{}2{}1'.format(*plusses)
    if equation.count('+') == 5 and eval(equation):
        print(equation)

This gives the output:

12+34+5==5+43+2+1
12+3+45==54+3+2+1
$\endgroup$
1
  • 1
    $\begingroup$ Instead of iterating on all counts of plusses using itertools.product and then filtering out solutions that have the wrong count of plusses, you could iterate directly on the correct counts of plusses, using itertools.combinations. This way you'd only test (8 choose 5) = 56 candidates instead of 2^8 = 256 candidates. $\endgroup$
    – Stef
    Dec 9, 2023 at 16:23
3
$\begingroup$

In my method I incorporate a parity check into the calculations.

First off, we know that there cannot be four + on either side because that makes one sum equal to 15 and the other having at least three digits. As argued by Hand-E-Food we also cannot have three + on the left, since that makes the left side $\le 1+2+3+45=51$ and the right side $\ge5+43+21=69$.

So we have two + on the left and three + on the right. With the right hand sum limited to a two-digit number the configuration on the left has to be one of these:

$1+23+45$

$12+3+45$

$12+34+5$

Now for the parity check. The sums $1+23+45$ and $12+34+5$ have an odd number of odd terms and so is odd, meaning the right side has to have an odd number of odd terms. This is possible only if the $2$ or the $4$ is the digit missing the + sign, and we have four candidates surviving the parity test:

$1+23+45=5+43+2+1$ No*

$1+23+45=5+4+3+21$ No*

(*Since the parity check does not allow concatenating $54$ on the right side, there is no way to counter the $45$ on the left.)

$12+34+5=5+43+2+1$ Yes

$12+34+5=5+4+3+21$ No

Thls leaves $12+3+45$ on the left to try, which is even. Now the right side has to have $5$ or $3$ missing the + sign leading to two more trials:

$12+3+45=5+43+21$ No $12+3+45=54+3+21$ Yes

We therefore get the two solutions in six trials.

$\endgroup$
2
$\begingroup$

Admittedly, I finish with trial and error, but after narrowing it down to 7 calculations.

Each number has 4 positions where a plus can be inserted.

Inserting 4 pluses on one side and 1 on the other makes 15 and >1000. So there must be 3 pluses on one side and 2 on the other.

The side with 3 plusses has 3 single-digit numbers, and 1 double-digit number. This cannot add to any number greater than 54+3+2+1 = 60 because 54 is the largest double-digit number possible.

The side with 2 plusses cannot have a triple-digit number as this is higher than 60. It must have 2 double-digit numbers and 1 single-digit number. This cannot add to any number less than 12+34+5 = 51 because 12 is the smallest double-digit number possible, and 34 < 45.

Trying instead with 3 plusses on the left side, and 2 on the right, the left maximum would be 1+2+3+45 = 51 and right minimum 5+43+21 = 69. So the 2 plusses are on the left, and the 3 plusses are on the right.

There are 3 configurations on the left and 4 on the right that fit the above deductions.

1+23+45 = 69 (greater than maximum)
12+3+45 = 60
12+34+5 = 51

54+3+2+1 = 60
5+43+2+1 = 51
5+4+32+1 = 42 (less than minimum)
5+4+3+21 = 33 (less than minimum)

There are two solutions:
12+34+5 = 5+43+2+1
12+3+45 = 54+3+2+1

$\endgroup$
1
$\begingroup$

Solution by brute-force search using Python 3.12 itertools

I used itertools to write the following solution enumeration and test script:

from itertools import chain, batched, product

def gen2str(iterable):
    '''
    Helper function. Flattens and turns character generator into string.
    '''
    return ''.join(list(chain(*iterable)))

## List with all digits from puzzle, in order.
digits = ['1', '2', '3', '4', '5', '5', '4', '3', '2', '1']

## Brute-forces all possible sign positionings, selects those with 5 pluses.
## '' stands for lack of sign in given position.
possible_signs = (t for t in product(['+', ''], repeat=10)
                  if len(''.join(t)) == 5)

## Zip matches signs to digits. Batched separates left side expression
## characters from right side expression characters.
for left, right in (batched(zip(signs, digits), 5) for signs in possible_signs):
    ## gen2str assembles strings from isolate characters (digits + signs),
    ## eval turns strings into python expressions. Print strings that eval the same.
    if eval(left_string := gen2str(left)) == eval(right_string := gen2str(right)):
        print(left_string, '==', right_string)

Runnig it, I got the following results (the first two are actually the same):

Python 3.12.0 (tags/v3.12.0:0fb18b0, Oct  2 2023, 13:03:39) [MSC v.1935 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.

= RESTART: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
+1+23+45 == 5+43+21
1+23+45 == +5+43+21
12+3+45 == 54+3+2+1
12+34+5 == 5+43+2+1
$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.