baxy77bax has asked for the wisdom of the Perl Monks concerning the following question:
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:
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: soR1 -> 17 1 20 12 $Array = [17,1,20,12] $Array[0] ->first track ...
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??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 ... ...
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: I need a help with this one- even don't know how to title this
by Util (Priest) on Nov 20, 2011 at 01:49 UTC | |
|
Re: I need a help with this one- even don't know how to title this
by choroba (Cardinal) on Nov 19, 2011 at 22:22 UTC | |
by baxy77bax (Deacon) on Nov 20, 2011 at 00:05 UTC | |
|
Re: I need a help with this one- even don't know how to title this
by locked_user sundialsvc4 (Abbot) on Nov 19, 2011 at 21:41 UTC |