تفاصيل العمل

Write a program that outputs all possibilities to put + or - or nothing between the numbers 1, 2, ..., 9 (in this order) such that the result is always 100. For example: 1 + 2 + 34 – 5 + 67 – 8 + 9 = 100.

Solution

uses an addition, the second uses subtraction, and the third equation concatenates the first two numbers. From here, we get the following:

f(2..9) = 100 - 1 = 99

f(-2, 3..9) = 100 - 1 = 99

f(12, 3..9) = 100

(Note how I moved the negative sign into the function on the second equation to keep the result the same.)

From here, we can keep working on each one of the equations above doing the same process:

2 + f(3..9) = 99

2 - f(3..9) = 99

f(23, 4..9) = 99

-2 + f(3..9) = 99

-2 - f(3..9) = 99

f(-23, 4..9) = 99

12 + f(3..9) = 100

12 - f(3..9) = 100

f(123, 4..9) = 100

You'd have to keep doing this until you completely eliminate the function f. From there, each branch where the equality holds represents a solution to the problem, so you can backtrack your steps to stitch the resultant equation together.

بطاقة العمل

اسم المستقل Ahmed A.
عدد الإعجابات 1
عدد المشاهدات 464
تاريخ الإضافة
تاريخ الإنجاز