Anonymous user
24 game/Solve: Difference between revisions
m
→Alternative version
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])]
, ys <- nub . sort $ select n xs
]
▲ $ solve 24 [3,2,8,9]</lang>
{{Output}}
<pre>((
((3 * 8) - (2 / 9))▼
(((2 / 9) + 8) * 3)
(((8 + 9) / 2) * 3)
(((9 - 3) * 8) / 2)▼
▲(((9 - 3) / 2) * 8)
((2 + (8 * 9)) / 3)
▲((3 * 8) - (2 / 9))
((3 - (2 / 9)) * 8)
((
((
((
(((9 - 3) * 8) / 2)</pre>
== {{header|Icon}} and {{header|Unicon}} ==
|