Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,201,518 members, 7,978,714 topics. Date: Friday, 18 October 2024 at 01:00 PM |
Nairaland Forum / Science/Technology / Programming / Math/programming Puzzle - Finding All Expressions That Evaluates To Some Value (1480 Views)
Php Regular Expressions For Beginners / Question On Regular Expressions In Java / Test-run My Math Algorithms Open Display Library Site (2) (3) (4)
Math/programming Puzzle - Finding All Expressions That Evaluates To Some Value by Kodejuice: 7:03pm On Dec 27, 2016 |
(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. 2 Likes |
Re: Math/programming Puzzle - Finding All Expressions That Evaluates To Some Value by Kodejuice: 1:19pm On Dec 28, 2016 |
FrankLampard: Talk's cheap, show us code 1 Like |
Re: Math/programming Puzzle - Finding All Expressions That Evaluates To Some Value by FrankLampard: 4:24pm On Dec 28, 2016 |
Kodejuice: 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: 4:41am On Dec 29, 2016 |
paranorman: You may combine the operators, but use the numbers once |
Re: Math/programming Puzzle - Finding All Expressions That Evaluates To Some Value by Jolliano: 11:38pm On Dec 29, 2016 |
Kodejuice: 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: 3:21am On Dec 30, 2016 |
Jolliano: LoL, BULLCRAP... This is not a solution. SHow the code that computed the value '6/(1-(3/4))' 2 Likes |
Re: Math/programming Puzzle - Finding All Expressions That Evaluates To Some Value by noordean(m): 2:37pm On Dec 30, 2016 |
Jolliano: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)
Do You Have An Online Shop For Sale Or Can You Develop One? / How To Consume Restful API In C# / Do You Need A Backend Developer (PHP Or Laravel)
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 15 |