Problem 105

http://projecteuler.net/index.php?section=problems&id=105

ちょっと考えたら、シンプルな解法に気がついた。

import Data.List
monotone xs = all (f.sort$xs) [1..length xs `div` 2]
where f ys n = (sum.take (n+1)) ys > (sum.take n.reverse) ys
subsetSumNeq xs = all (f xs) [1..length xs `div` 2]
where f ys n = all (null.tail).group.sort.map sum. comb ys $ n
specialSum xs = monotone xs &&  subsetSumNeq xs
main = do f <- readFile "sets.txt"
let sets = map (read.("["++).(++"]")).lines $ f
print.sum.map sum.filter specialSum $ sets
comb _  = [[]]
comb [] _ = []
comb (x:xs) (n+1) = map (x:) (comb xs n) ++ comb xs (n+1)
More Reading
Newer// Problem 104
Older// Problem 106