A problem related to the number 1963

729 Views Asked by At

You are allowed to use +, -, / and * (plus, minus, division and multiplication) signs and bracketing. These signs you can put between the numbers

1963

to form mathematical expressions. You must put at least one sign between two numbers and – cannot be used as “negative”, thus -1+9+6+3 is not allowed, but 1-9+6+3 is allowed.

The question is: what is the smallest natural number that cannot be expressed in this way? How to show (elegantly, without computer) that it is impossible to get 14?

I found myself the following representations:

$0=1*9-6-3$

$1=(1/9)*(6+3)$

$2=1+9/(6+3)$

$3=1*9/(6-3)$

$4=1+9/(6-3)$

$5=(1+9)/(6/3)$

$6=1*9-6+3$

$7=1+9-6+3$

$8=1+9-6/3$

$9=1*(9-6)*3$

$10=1+(9-6)*3$

$11=1*9+6/3$

$12=1+9+6/3$

$13=1+9+6-3$

1

There are 1 best solutions below

3
On BEST ANSWER
from fractions import Fraction

def Jaska(L):
    if len(L) == 1:
        yield L[0], Fraction(L[0])
    else:
        for l in range(len(L) - 1):
            for e1, v1 in Jaska(L[:l+1]):
                for e2, v2 in Jaska(L[l+1:]):
                    yield '(%s + %s)' % (e1, e2), v1 + v2
                    yield '(%s - %s)' % (e1, e2), v1 - v2
                    yield '(%s * %s)' % (e1, e2), v1 * v2
                    if v2 != 0:
                        yield '(%s / %s)' % (e1, e2), v1 / v2

def JaskaAll(L):
    solutions = dict([])
    for e, v in Jaska(L):
        if v.denominator == 1:
            v = v.numerator
        if v not in solutions:
            solutions[v] = []
        solutions[v].append(e[1:-1])
    return solutions

You can check

14 in JaskaAll([1,9,6,3])
to make sure.