tough program problems

slinetz

Senior member
Apr 2, 2000
824
0
0
here is the problems i encountered

give you a random 4 digit #, u will have to some how find a way to make it to 24 by using +,-,*,/

examples: 4362 = > 4*3+6*2

if there is no solution wrote no solution output.

any clever to do it? (if you really want to list all possibility , it is going to be a drag)
 

Kyteland

Diamond Member
Dec 30, 2002
5,747
1
81
Brute force it baby! There are only 3 operators, with 4 possibilities each, so you only need to do 64 checks per number. With 10000 possible numbers that is only 640,000 operations. Your computer can do that in the blink of an eye.

Any "clever" algorithm will probably take longer than that, both to code and to execute, so why bother?

Edit: my math sucks.
 

DaveSimmons

Elite Member
Aug 12, 2001
40,730
670
126
Crossposting your homework to both Off-Topic and Software?

Interesting problem to figure out how to permute all the combinations of digits and operators. Did your instructor give you any hints, or solutions to simpler versions of the problem?