Perl: the Markov chain saw | |
PerlMonks |
Re^4: Algorithm to convert combinations to bitstringby Limbic~Region (Chancellor) |
on Jan 01, 2010 at 19:49 UTC ( [id://815220]=note: print w/replies, xml ) | Need Help?? |
spx2,
This doesn't meet the requirements. Since this thread is several years old, let me explain again what I was trying to accomplish. You have a function that will perform an expensive operation the first time it is passed a unique argument list but is free to short circuit and return early if it has been called with the same arguments again. This is typically accomplished using a %seen hash or the Memoize module. Unfortunately, the number of possible argument variations is too large to use standard tools - hence the desire to use a bit string. In my case, the arguments will always be a subset of a known set and they will always be a fixed size. On the other hand, we are not generating them - they will be passed to us. We need to convert the subset into an integer and either set that single bit if not already set and perform the expensive operation or return if already set. In summary, if we are doing N Choose K with K = 13 and N = 26 then there are 10,400,600 total possible combinations. This means our seen should be exactly 1,300,075 bytes (1 bit representing each possible combination). If your solution requires more memory than that or is not able to take an arbitrary subset and convert it into an integer to see if the bit is set or not then it doesn't meet the requirements. Cheers - L~R
In Section
Seekers of Perl Wisdom
|
|