Hi,

well here comes a puzzle (at least for me it is). So again I'm not seeking for an exact code just a single or more pointers. also this is (once finished) going to be rewritten in c and that is why I would like to avoiding hashing and regex. (Also feel free, If you have erdge to criticize my posting to this forum, since it is not strictly Perl associated question)

So the problem is as follows :
I have a random number generator R1 that produces from 1 to 4 integers, all spaning from 1-100. Also I have another random number generator R2 that reports one random number from 1-20.
so what i need to do is once the R1 gives me let say 4 numbers i need to store them into array where every position in the array represents one track:

R1 -> 17 1 20 12 $Array = [17,1,20,12] $Array[0] ->first track ...
Then R2 kicks in and generates number 4. After that R1 again produces let say 3 numbers (13 24 21). The problem now is how to efficiently (without hashing) figure out that 24 should go into $array[3]->third track since 20+4=24, and 21 into first track since 17+4=21 and 13 in second or fourth track - it doesn't matter. This process is repeated let say 5 times: so
R1 -> 17 1 20 12 R2 -> 4 R1 -> 21 13 24 4 17 21 1 13 20 24 12 R2-> 6 R1 -> 19 30 31 27 4 6 17 21 27 1 13 19 20 24 30 12 31 R2-> 3 R1 -> 22 34 4 6 3 17 21 27 1 13 19 22 20 24 30 12 31 34 ... ...
And so on ... Has anyone came across this type of problem before and solved it ? So i can deal with linked lists, chaining arrays but not hashing since the number of operations in hashing is too big for such a case. or at least i feel it is, maybe it is not, what do you think? any advices??

thank you

baxy

Update to the sundialsvc4's reply:

Well the rulesare pretty simple as stated. Can I actually make it more simpler, well maybe I don't know, where should i simplify ?
as far as the implementation goes , well if you were in my position you probably would not, given that the person in charge of the project is an old school , really old school type of a guy calling all the shoots and since he is paying me i have no choice then to comply.But other then that , thanks for the advice :)
cheers

UPDATE:

Ok , so what am i working on. It is a search engine that is based on "hiden" Viterbi probabilities (R1 and R2) and domino algorithm (numbers that im trying to match) so there is no extra information that i can give you, that is it. I just replaced those fancy words with simple ones. So what i did is, i replaced the real words with their fingerprints and bow bases on a HVB's am trying to put them back together (ofcourse much faster then regular search engine does since im not dealing with whole words).

PS

Based on the amount of replies, this really looks like is a tough problem without much room to move around.

Thank you

baxy


In reply to I need a help with this one- even don't know how to title this by baxy77bax

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.