₦airaland Forum

Welcome, Guest: RegisterLoginWith GoogleTrendingRecentNew

Stats: 3,329,063 members, 8,438,630 topics. Date: Friday, 03 July 2026 at 05:31 PM

Toggle theme

Math/programming Puzzle - Finding All Expressions That Evaluates To Some Value - Programming - Nairaland

Nairaland ForumScience/TechnologyProgrammingMath/programming Puzzle - Finding All Expressions That Evaluates To Some Value (1617 Views)

1 Reply (Go Down)

Math/programming Puzzle - Finding All Expressions That Evaluates To Some Value by Kodejuice(op):
(it was given at a math contest for ten year olds and apparently many math teachers couldn't figure out a solution):

We have numbers 1, 3, 4 and 6. Create an expression using any elementary operators (+, -, *, /), containing only these numbers, exactly once each, such that the result is 24, you can also include parens ( and ).

I felt the problem itself is inappropriate for 10 y.o. kids and irrelevant for a maths contest; but it seemed like a good programming exercise

So come up with a program to give the solution(s).

Use any Language you feel comfortable with
Re: Math/programming Puzzle - Finding All Expressions That Evaluates To Some Value by FrankLampard: 7:55am On Dec 28, 2016
My Brute force approach, would be to loop through all the number, then check which if the operators would sum to 24.
Re: Math/programming Puzzle - Finding All Expressions That Evaluates To Some Value by Kodejuice(op): 1:19pm On Dec 28, 2016
FrankLampard:
My Brute force approach, would be to loop through all the number, then check which if the operators would sum to 24.
Talk's cheap, show us code
Re: Math/programming Puzzle - Finding All Expressions That Evaluates To Some Value by FrankLampard: 4:24pm On Dec 28, 2016
Kodejuice:
Talk's cheap, show us code
OK
Re: Math/programming Puzzle - Finding All Expressions That Evaluates To Some Value by paranorman(m): 8:29pm On Dec 28, 2016
You mean the statement to executed should only contain unique operands(the numbers) that cannot be repeated, but the set (1, 3, 4, 6) may not be exhausted. You may use all operators, combine or just a single one?
Re: Math/programming Puzzle - Finding All Expressions That Evaluates To Some Value by Kodejuice(op): 4:41am On Dec 29, 2016
paranorman:
You mean the statement to executed should only contain unique operands(the numbers) that cannot be repeated, but the set (1, 3, 4, 6) may not be exhausted. You may use all operators, combine or just a single one?
You may combine the operators, but use the numbers once
Re: Math/programming Puzzle - Finding All Expressions That Evaluates To Some Value by Jolliano:
Kodejuice:
You may combine the operators, but use the numbers once
Must the four numbers be used?

If yes, here's my answer on python 2.7

from __future__ import division

numbers=[1,3,4,6]
result = int(numbers[3] / (numbers[0] - (numbers[1] / numbers[2])))
print(result)
Re: Math/programming Puzzle - Finding All Expressions That Evaluates To Some Value by Kodejuice(op): 3:21am On Dec 30, 2016
Jolliano:
Must the four numbers be used?

If yes, here's my answer on python 2.7

from __future__ import division

numbers=[1,3,4,6]
result = int(numbers[3] / (numbers[0] - (numbers[1] / numbers[2])))
print(result)
LoL, BULLCRAP... This is not a solution.
SHow the code that computed the value '6/(1-(3/4))'
Re: Math/programming Puzzle - Finding All Expressions That Evaluates To Some Value by noordean(m): 2:37pm On Dec 30, 2016
Jolliano:
Must the four numbers be used?
If yes, here's my answer on python 2.7
from __future__ import division
numbers=[1,3,4,6] result = int(numbers[3] / (numbers[0] - (numbers[1] / numbers[2]))) print(result)
LOL
Re: Math/programming Puzzle - Finding All Expressions That Evaluates To Some Value by 2uung(m): 3:27am On Dec 31, 2016
i dnt knw how use recursion(method dt calx itslf) very wel buh it x perfect 4 dx
1 Reply

Php Regular Expressions For BeginnersQuestion On Regular Expressions In JavaTest-run My Math Algorithms Open Display Library Site234

...A Very Good Python Programmer Needed AsapI Need A Webmaster Who Can Create A Professional Website With Cpanel Emails.