[Haskell-cafe] Partition int 180. Out of memory
Erik Rantapaa
erantapaa at gmail.com
Wed Nov 18 15:49:20 UTC 2015
On Wednesday, November 18, 2015 at 3:25:12 AM UTC-6, Kees Bleijenberg wrote:
>
> I want to partition the integer n=180 with terms >=5
>
> I.e. n=15 => [[5,5,5],[8,7],[9,6],[10,5],[15]]
>
For an alternate way to produce partitions, have a look at how the combinat
package does it:
https://hackage.haskell.org/package/combinat-0.2.8.1/docs/src/Math-Combinat-Partitions-Integer.html#line-308
In particular, in this part:
_partitions' (!h ,!w) d = [ i:xs | i <- [1..min d h] , xs <- _partitions' (i,w-1) (d-i) ]
if you change `i <- [1..min d h]` to ` i <- [5..min d h]` it appears you
will get the partitions which have size at least 5.
After you make the change, call the function like this: _partitions'
(180,180) 180
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20151118/7d032654/attachment.html>
More information about the Haskell-Cafe
mailing list