From: Donald Patch Date: 2007-08-26T05:25:10+09:00 Subject: Re: Combinations of numbers/operators? Dan Zwell wrote: > Do you know you are only dealing with four numbers? It makes quite a > difference. A general algorithm to parenthesize all possible > combinations isn't that hard in principle (recursively split an array of > numbers, adding an operator and parentheses at each stage), but it's > awkward to code, aspecially while maintaining the "all permutations of > operations" that you originally asked about. Yeah, I know; this goes much farther than the original question. It occurred to me after looking at the output that I hadn't considered stuff like making the first integer a negative number or the impact of grouping/parentheses. Duh. Here's a related question: is there a math library in Ruby that would allow me to "solve for" a given number given several inputs? For example, I have the number 20 and want to know what combinations of 1,2,3,4 would yield this result? I'm not even sure what this is called to be able to look for a solution. Thanks! Stoopid noob! ;) -- Posted via http://www.ruby-forum.com/.