<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body style="overflow-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;">I came up with a one-liner for computing coefficients of the generating function for integer partitions:<div><br></div><div><div>part :: Int → [Integer ]</div><div>part n = take n $ product [cycle (1 : replicate n 0) | n ← [0 . . (n − 2)]]</div><div></div><div><br></div><div>Karczmarczuk’s solution via the Haskell prelude:</div><div><br></div><div><div>part = 1 : b 1</div><div>  where b n = (1 : b (n + 1)) + (replicate n 0 ++ b n)</div></div><div><br></div><div>cycle and replicate are really underrated!</div><div><br><blockquote type="cite"><div>On Jan 20, 2025, at 8:54 AM, Douglas McIlroy <douglas.mcilroy@dartmouth.edu> wrote:</div><br class="Apple-interchange-newline"><div><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr">> catalanNumbers :: Num a => [a]<br>> catalanNumbers =<br>>   let xs = 1 : PowerSeries.mul xs xs<br>>   in  xs</div><div dir="ltr"><br></div><div>This example of a generating function come to life as a program deserves to be better known. Bill Burge presented it 50 years ago in "Recursive Programming Techniques", Addison-Wesley, 1975. I revisited it in "Power series, power serious", JFP 9 (1999) 323-335, where, with overloadied arithmetic, it became</div><div>      ts = 1 : ts^2</div><div>The technique is laid bare in ten one-liners at <a href="https://www.cs.dartmouth.edu/~doug/powser.html">https://www.cs.dartmouth.edu/~doug/powser.html</a>.</div><div><br></div><div>Doug</div></div></div>
</div></div>
_______________________________________________<br>Haskell-Cafe mailing list<br>To (un)subscribe, modify options or view archives go to:<br>http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe<br>Only members subscribed via the mailman list are allowed to post.</div></blockquote></div><br></div></body></html>