Dear monasterians,
i've built a generator of integer partitions of n which gives you all the sets of nonzero integers that add up to exactly n.

the code (i'm terribly sorry about the names of the variables. and there are few bugs that you'll be able to see as you run it):

#!/usr/bin/perl -w print 'enter n : '; $kk = $n = $nn = readline(*STDIN); my @ready = @aa = (); while ($n) {$aa[$n] = 1;$n--;} @bb = @aa; while ($kk) { $aa[$nn - $kk + 1] += $aa[$nn - $kk]; $aa[$nn - $kk]=''; $ready[($nn - $kk)*3] = "@aa\n"; $aa[$kk - 1] += $aa[$kk]; $aa[$kk]=''; $ready[($nn - $kk)*3 + 1] = "@aa\n"; $aa[$nn - $kk + 1] += $aa[$nn - $kk]; $aa[$nn - $kk]=''; $ready[($nn - $kk)*3 + 2] = "@bb\n"; $bb[$kk - 1] += $bb[$kk]; $bb[$kk]=''; $kk--;} print @ready;

so my "questions" is if there's a way to make a few improvments ?

In reply to Generator of integer partitionts of n by chiburashka

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.