[ create a new paste ] login | about

Link: http://codepad.org/wprw8CLb    [ raw code | output | fork ]

Haskell, pasted on Aug 9:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
integerPartitions :: [Integer]
integerPartitions =
  let
    p = go (let kg k = (2*k):k:kg (k+1) in 0:kg 1) [] 0
    
    go :: [Int] -> [[Integer]] -> Int -> [Integer]
    go ks a c = s:(if c>0 then go ks b (c-1) else (let (d:kt)=ks in go kt b d))
      where
        (s,b) = sf a
        sf ((a1:t1):(a2:t2):r) = let (t,tr)=sf r in (a1+a2-t,t1:t2:tr)
        sf ((a1:t1):_)         = if c>0 then (a1,t1:[]) else (a1+1,t1:p:[])
        sf _                   = if c>0 then (0,[])     else (1,p:[])
  in
    1:p

main = print $ integerPartitions!!1000


Output:
1
24061467864032622473692149727991


Create a new paste based on this one


Comments: