Instead of printing out the partitions, how could I plug them into (I guess) an array & then use them in a polynomial? What I've been using up to now (thx to hdb months ago) is

while (my ($x, $y, $z) = @{ $iter->next // [] }) { push @wants, map { { join(', ', $x, $y, $z) => $_ } } grep { is_approximately_an_integer( @$_ ) } [ poly_roots( poly_derivative( # expanded form of x*(x - $x)*(x - $y)*(x - $z) 1, -$x - $y - $z, $x*$y + $x*$z + $y*$z, -$x*$y*$z, 0 ) ) ]; }

The stuff in the while is from the Algorithm::Combinatorics module & the subroutine goes through the zeros of the polynomial's derivative to pick out the ones that have zeros that are all close enough to an integer. I guess it would be to get the elements of @cnt in the prog above but I'm not sure how to do that. Is it as simple as replacing the $x, $y, $z with $cnt[0], $cnt1, $cnt2 in the code above? Or maybe defining my $x = $cnt[0]?

(a couple minutes later)

my @cnt; my $seq= 0; my $x = $cnt[0]; my $y = $cnt[1]; my $z = $cnt[2]; while( @cnt = $iter->() ) { #printf "%d) %s\n", ++$seq, join ' + ', @cnt map { { join(', ', $x, $y, $z) => $_ } } grep { is_approximately_an_integer( @$_ ) } [ poly_roots( poly_derivative( # expanded form of x*(x - $x)*(x - $y)*(x - $z) 1, -$x - $y - $z, $x*$y + $x*$z + $y*$z, -$x*$y*$z, 0 ) ) ]; }

Actually, now that I've tried that, I get errors in the line with the map & also the following one with the grep saying $x, $y, $z are uninitialized which I don't understand because I set them to be elements of @cnt.


In reply to Re^2: How to restrict partitions (NestedLoops) by crunch_this!
in thread How to restrict partitions by crunch_this!

Title:
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, details, 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, summary, 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.