Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Conceptually you could convert this to a single 1264 bit number using the following algorithm:</p> <ol> <li>Initialize an accumulator variable to zero</li> <li>Iterate over all elements, but skipt those which you know to be zero</li> <li>For the other elements, add 2 to obtain values in the range [0,1,2,3,4]</li> <li>For each such value, multiply the accumulator by 5 then add the corresponding value</li> <li>When you have processed all elements, the accumulator will encode your arrays</li> </ol> <p>To reverse that encoding, youd do this:</p> <ol> <li>Read the encoded value into the accumulator</li> <li>Iterate over all elements, in reverse order, but skipt those which you know to be zero</li> <li>For each element, you obtain the corresponding value as the accumulator modulo 5</li> <li>Subtract 2 from that value</li> <li>Divide the accumulator by 5 using a truncating division</li> </ol> <p>The problem with all of this is the fact that JS doesn't provide 1264 bit numbers out of the box. You might try one of the libraries suggested in <a href="https://stackoverflow.com/q/4288821/1468366">How to deal with big numbers in javascript</a>.</p> <p>But unless you <em>absolutely</em> requre an extremely small representation, I'd suggest an alternative approach: you can encode up to 13 such values in a 32 bit signed integer, since 5<sup>13</sup>=1,220,703,125 &lt; 2,147,483,648=2<sup>31</sup>. So after encoding 13 values I'd write out the result using such a number, then reset the accumulator to zero. This way you'll need ⌈544/13⌉∙32=1376 bits, which is not that much worse in terms of space requirements, but will be <em>a lot</em> faster to implement.</p> <p>Instead of iterating once in forward and once in reverse direction, it might be easier to not multiply the accumulator by 5, but instead multiply the value you add to that by a suitable power of 5. In other words, you maintain a factor which you initialize to 1, and multiply by 5 every time you add a value. So in this case, first data values will have less significant positions than later data values, both for encoding and decoding, which means you can use the same iteration order for both.</p> <p>See the ideone link mentioned in my comment below for an example of this latter approach. It encodes the full 9*9*8 values in 50 integers, each of them using no more than 31 bits. It then decodes the original matrix from that encoded form, to show that all the information is still present. The example does not use any fixed zeros, in your case ⌈544/13⌉=42 integers should be enough.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload