• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

tough program problems

slinetz

Senior member
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)
 
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.
 
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?
 
Back
Top