Problem 103

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

良く分からないから、とりあえず入力してみたらあっていた。

後でコードかこう。

[追記]

Problem 105を利用

import Data.List
import Data.Ord
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 = print.minimumBy(comparing sum)$[x|x<-comb [20..50] 7,specialSum x]
comb _  = [[]]
comb [] _ = []
comb (x:xs) (n+1) = map (x:) (comb xs n) ++ comb xs (n+1)

ま、遅いけど。いいんじゃん。よく分からない問題だし。

More Reading
Newer// Problem 99
Older// Problem 98