Make a 24 Game Solver
Ruby, 253 243 (incomplete, many duplicates, no error message)

g=gets.split.map(&amp;:to_i).permutation(4)
s=[0,2,4,6]
%w[+ - * /].repeated_permutation(3).map{|x|g.map{|y|s.map{|b|s.select{|e|e&gt;b}.map{|a|y.zip(x).flatten[0..6].join.insert(a+1,?)).insert(b,?()}}}}.flatten.each{|x|puts x if 24==eval(x)rescue''}


I got this so far, but there are a lot of duplicates. Example run:

c:\a\ruby&gt;24
9 6 3 2
(9+3)+6*2
(9+3+6*2)
9+(3+6*2)
9+3+(6*2)
(9+3)+2*6
(9+3+2*6)
9+(3+2*6)
9+3+(2*6)
(3+9)+6*2
(3+9+6*2)
3+(9+6*2)
3+9+(6*2)
(3+9)+2*6
(3+9+2*6)
3+(9+2*6)
3+9+(2*6)
(9+6-3)*2
(6+9-3)*2
(9+6*2)+3
(9+6*2+3)
9+(6*2)+3
9+(6*2+3)
(9+2*6)+3
(9+2*6+3)
9+(2*6)+3
9+(2*6+3)
(3+6*2)+9
(3+6*2+9)
3+(6*2)+9
3+(6*2+9)
(3+2*6)+9
(3+2*6+9)
3+(2*6)+9
3+(2*6+9)
(6+2)*9/3
(2+6)*9/3
(9-3+6)*2
(6-3+9)*2
(9-3-2)*6
(9-2-3)*6
(6*2)+9+3
(6*2+9)+3
(6*2+9+3)
6*2+(9+3)
(6*2)+3+9
(6*2+3)+9
(6*2+3+9)
6*2+(3+9)
(2*6)+9+3
(2*6+9)+3
(2*6+9+3)
2*6+(9+3)
(2*6)+3+9
(2*6+3)+9
(2*6+3+9)
2*6+(3+9)
2*(9+6-3)
2*(6+9-3)
9*(6+2)/3
9*(2+6)/3
2*(9-3+6)
2*(6-3+9)
6*(9-3-2)
6*(9-2-3)
(9*3)-6/2
(9*3-6/2)
9*3-(6/2)
(3*9)-6/2
(3*9-6/2)
3*9-(6/2)
(9*6)/2-3
(9*6/2)-3
(9*6/2-3)
9*(6/2)-3
(6*9)/2-3
(6*9/2)-3
(6*9/2-3)
9/3*(6+2)
9/3*(2+6)
(6/2)*9-3
(6/2*9)-3
(6/2*9-3)


It will probably prove very difficult to eliminate duplicates. I am working on it, but I am afraid it will triple my code size, so I'm posting here first. aaaaaaahhhhh my brain hurts now, so I will continue working on this later :P