import Data.List
main
= mapM_ (print . find4A
) ["1 5 3 6 : 10", "1 5 3 6 7 : 10"]find4A s
= (flip (map . (!!)) =<< elemIndices y
. map expr
) $ combo
[x1
] opPlusDigitList
where
combo as [] = as
combo as (h:t) = combo [a ++ b | a <- as, b <- h] t
opPlusDigitList
= map (\x
-> [op
++ x
| op
<- ops
]) $ xs
(xs0
, y0
) = break (==':') s
ops = [" + ", " - ", " * ", " / "]
where
(xxs
, yys
) = partition
(`
notElem`
["+", "-", "*", "/"]) $ words s
go [x1] _ = x1
go (x1:x2:xs) ("*":ys) = go ((x1 * x2) : xs) ys
go (x1:x2:xs) ("/":ys) = go ((x1 / x2) : xs) ys
go (x1:xs) ("+":ys) = x1 + go xs ys
go (x1:x2:xs) ("-":ys) = x1 + go ((-x2) : xs) ys
go _ _ = -1
aW1wb3J0IERhdGEuTGlzdAptYWluIDo6IElPICgpCm1haW4gPSBtYXBNXyAocHJpbnQgLiBmaW5kNEEpIFsiMSA1IDMgNiA6IDEwIiwgIjEgNSAzIDYgNyA6IDEwIl0KZmluZDRBIDo6IFN0cmluZyAtPiBbU3RyaW5nXQpmaW5kNEEgcyA9IChmbGlwIChtYXAgLiAoISEpKSA9PDwgZWxlbUluZGljZXMgeSAuIG1hcCBleHByKSAkIGNvbWJvIFt4MV0gb3BQbHVzRGlnaXRMaXN0CiAgd2hlcmUKICAgIGNvbWJvIGFzIFtdICAgICA9IGFzCiAgICBjb21ibyBhcyAoaDp0KSAgPSBjb21ibyBbYSArKyBiIHwgYSA8LSBhcywgYiA8LSBoXSB0CiAgICBvcFBsdXNEaWdpdExpc3QgPSBtYXAgKFx4IC0+IFtvcCArKyB4IHwgb3AgPC0gb3BzXSkgJCB4cwogICAgKHhzMCwgeTApICAgICAgID0gYnJlYWsgKD09JzonKSBzCiAgICB4MTp4cyAgICAgICAgICAgPSB3b3JkcyB4czAKICAgIHkgICAgICAgICAgICAgICA9IHJlYWQgJCB0YWlsIHkwICAgICAgICAgOjogRG91YmxlCiA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