could you please specify what you mean by
I'd ideally like to be able to chose to only allow increments of 2 or +5
if you allow both increments at the same time, then any value after 3 ( = 5 * 2 - 5 - 2 ) is representable as a sum of 2's and 5's, so you might as well go the brute force way, with (0..100) without 1 and 3, cut up to current sum ( sorry, unclear here - basically, use, jdporter's solution, with generate_solutions(1, 100 ...
buth with additional checks, ie,
return if ($i == 1 || $i == 3)
if you only want to allow 1 type of increment, say 5, then you might as well generate all partitions of 20 and multiply them by 5. The above solutions either give you only one increment, or, as in Ovid's allow only one of the two to be true, ie, 7 won't be a valid element..

Rethinking further the part about both increments allowed. What about starting with an array (100,0,0,0,0), and then, from the right hand side, try to move either a 2 or 5 to the right, with backtracking recursion, printing any time you succeed without making a negative number. Hmm, but that would make it possible to shift a 2 from a 5, with a remaining 3, which is bad...

Well, ok, I'll stop now.. the above idea, with just shifting 1's, should easily generate all unrestricted partitions of a number in a lexicographic order, so if you only needed 1 increment, it should suffice.. You can probably write the actual code for it faster than I.. in the meantime, I'll start thinking on generating weird restricted partitions...


In reply to Re: How to determine & record all possible variations for 5 items? by ivancho
in thread How to determine & record all possible variations for 5 items? by Stenyj

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.