Problem 148

http://projecteuler.net/index.php?section=problems&id=148
観察から、規則性をみつけ(証明はしていないが、納得できる規則性なのでよしとする)、それを利用。
要するに7進数展開して、ごにょごにょっとすると答えが出てくる。

import Data.List

toSepta =reverse. unfoldr f
    where f 0 = Nothing
          f n =let (q,r) = divMod n 7 in Just(r,q)

decode = fst. foldl f (0,1)
    where f (x,p) y =  (28*x + p*(div (y*(y+1)) 2), (y+1)*p)

main = print. decode. toSepta$10^9