24 game/Solve: Difference between revisions

m
Line 2,066:
eval (Op op x y) = lookup op ops <*> eval x <*> eval y
 
 
split :: [Int] -> [([Int],[Int])]
split xs = [(ys, xs \\ ys) | n <- [1..length xs - 1], ys <- select n xs]
 
select :: Int -> [Int] -> [[Int]]
Line 2,077 ⟶ 2,074:
]
 
split :: [Int] -> [([Int],[Int])]
split xs = [(ys, xs \\ ys) | n <- [1..length xs - 1], ys <- select n xs]
, ys <- nub . sort $ select n xs
]
 
main = mapM_ putStrLn
main = mapM_ (putStrLn . render . toDoc) $ solve 24 [34,26,89,9]</lang>
. nub . sort . map (render . toDoc)
$ solve 24 [3,2,8,9]</lang>
{{Output}}
<pre>(((8 / 2) +* (9) /- 3) * 8)
(((2 / 9) + (3) * 8))
((3 * 8) - (2 / 9))
(((98 - 3)(2 / 29)) * 83)
(((2 / 9) + 8) * 3)
(((8 + 9) / 2) * 3)
(((9 - 3) * 8) / 2)
(((9 - 3) / 2) * 8)
((2 + (8 * 9)) / 3)
((2 / 9) + (3 * 8))
((3 * 8) - (2 / 9))
((3 - (2 / 9)) * 8)
((89 - (2 /* 93)) * 38)
((8(2 / 29) * (9 -+ 3) * 8)
((9 - (2 *+ 9) / 3)) * 8)</pre>
(((9 - 3) */ 82) /* 28)
(((9 - 3) * 8) / 2)</pre>
 
== {{header|Icon}} and {{header|Unicon}} ==
Anonymous user