#Pyth, 68 bytes [try it here online](http://pyth.herokuapp.com). Uses http://stackoverflow.com/a/2163753/4230423 except that a)No cache since Pyth automatically memoizes, b)Prints each instead of appending to list, and c) is translated to Pyth. M?smg-Gddr1h?H<HGGG1Akd,QOgQQWQFNr1h?k<kQQKg-QNNI<dKB=d-dK)N=kN=Q-QN I'll post an explanation of this when I have the time, but here is the corresponding python code: g=lambda G,H: sum(map(lambda d:g(G-d, d), range(1, (H if H<G else G) + 1))) if G else 1 Q=input() k,d = Q,random.randrange(g(Q, Q)) while Q: for N in range(1, min(k, Q) + 1): K = g(Q-N, N) if d < K: break d -= K print N k=N Q -= N **Edit:** I finally got around to doing the explanation: M Lambda g(G,H) ? G If G truthy s Sum m Map g Recursive call -Gdd G-d,d r Range 1 1 to h +1 ? <HG If H<G (this does min) H H G Else G 1 Else 1 A Double assign kd Vars k and d , To vals Q Q (evaled input) O Randrange 0 till val gQQ Call g(Q, Q) WQ While Q is truthy FN For N in r Range 1 From one h Till +1 ?k<kQQ Min(Q,K) Kg K=g( -QN Q-N N N I<dK If d<k B Break (implicit close paren) =d-dk Subtracts d-=k ) Close out for loop N Prints N =kN Set k=N =Q-QN Subtracts Q-=N