import Control.Applicative
one :: [a] -> [(a, [a])]
one xs = sub xs []
where
sub [] _ = []
sub (x:xs) ac = (x, xs++ac) : (sub xs (x:ac))
two :: [a] -> [(a, a, [a])]
two [] = []
two [a] = []
two xs = do
(x, rest) <- one xs
do
(y, rest) <- one rest
data Expr
= Val
Int | Add Expr Expr
| Sub Expr Expr
| Mul Expr Expr
type Number
= (Expr
, Int)
apply :: [Number] -> [[Number]]
((e, x), (f, y), rest) <- two xs
(Add e f, x + y) : rest,
(Sub e f, x - y) : rest,
(Mul e f, x * y) : rest
]
bfs
:: Int -> [[Number
]] -> [Number
]bfs n [] = []
bfs n ([x] : rest) =
(if (eval x) == n then [x] else []) ++ (bfs n rest)
bfs n (xs : rest) = bfs n (rest ++ (apply xs))
toVal n = (Val n, n)
solve a b c d = do
let anss = bfs 10 [[toVal a, toVal b, toVal c, toVal d]]
main = do
else solve a b c d >> main
aW1wb3J0IERhdGEuQXJyYXkuSU8KaW1wb3J0IERhdGEuQ2hhcgppbXBvcnQgU3lzdGVtLklPCmltcG9ydCBDb250cm9sLk1vbmFkCmltcG9ydCBDb250cm9sLkFwcGxpY2F0aXZlCgpvbmUgOjogW2FdIC0+IFsoYSwgW2FdKV0Kb25lIHhzID0gc3ViIHhzIFtdCiAgd2hlcmUKICAgIHN1YiBbXSBfID0gW10KICAgIHN1YiAoeDp4cykgYWMgPSAoeCwgeHMrK2FjKSA6IChzdWIgeHMgKHg6YWMpKQoKdHdvIDo6IFthXSAtPiBbKGEsIGEsIFthXSldCnR3byBbXSA9IFtdCnR3byBbYV0gPSBbXQp0d28geHMgPSBkbwogICh4LCByZXN0KSA8LSBvbmUgeHMKICBkbwogICAgKHksIHJlc3QpIDwtIG9uZSByZXN0CiAgICByZXR1cm4gKHgsIHksIHJlc3QpCgpkYXRhIEV4cHIgPSBWYWwgSW50IHwgQWRkIEV4cHIgRXhwciB8IFN1YiBFeHByIEV4cHIgfCBNdWwgRXhwciBFeHByCnR5cGUgTnVtYmVyID0gKEV4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