The large number is coming from me. In essence I'm trying to look through every combination of a set that size and find an optimal solution.

I have an array of objects equal to the number of bits and wanted to +1 to try the next combination, evaluate it, and then proceed to the next. Each bit turns that particular element in the corresponding array on/off. I was planning on using bigint to deal with the large numbers.

I considered at first nesting loops but decided I didn't like that approach as with each new element I'd have to keep rolling back over the elements already in the chain to see if it had been used already in the chain, plus I wondered how much CPU I'd burn with the structure.

I also figured with a "bit" approach to the problem, it would probably make it easier to start forking off instances to analyze various combinations.

So at the end of the day here perhaps I'm just making the problem more difficult and I asked the wrong question to begin with.

How would you quickly iterate over every combination of an array with 80 elements where each element is used a maximum of once in the combination? To make it faster, I've already determined the optimal solution will use at least 7 of the elements and no more than 25.

Solutions that precompute the combinations before allowing me to evaluate them don't work well as I have to store all of those combinations and I anticipate only keeping a low number of them - hence I want to evaluate each combination as it comes.


In reply to Re: Turning very larger numbers into an array of bits by gblack
in thread Turning very larger numbers into an array of bits by gblack

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.