title: Compress a very large number (in Python)
body: <p>I need a very very very large number (143 millions digits) to be compressed. I'm looking for a solution that compresses it without loss to at least 10% of it. I've tried zlib, zipfile, gzip, and so on, but none of those will really compress this number. So this is an idea I had, but the problem is that I don't know how to implement it</p>
  
  <p>First, I have the number.</p>
  
  <blockquote>
    <p>234512</p>
  </blockquote>
  
  <p>Then I must split it in blocks of numbers that are smaller than 256.</p>
  
  <blockquote>
    <p>234,51,2</p>
  </blockquote>
  
  <p>I could split it if the size was fixed (eg, always 3 digits) but it may have 1,2 or 3 digits per block, so I got stuck here.</p>
  
  <p>And after I get blocks of numbers smaller than 256, I will turn them into chars and write to the file.</p>
  
  <p>EDIT: Since with that method I would lose landing zeros, I created an algorithm that compress ~50% of the number size:</p>
  
  <ol>
  <li><p>As I have only 0-9 numbers as digits, I could say they're in hexadecimal (although they aren't) and convert to base 10, reducing its size. EDIT 2: skip this step. Actually, doing it will just increase its size!</p></li>
  <li><p>I will get a smaller number with 0-9 numbers as digits, then I could again assume they're in hexadecimal. Thus, use unhexlify to turn it into a lot of bytes, which are half of the size! (if it's odd-length, add 'a' at the append to the number)</p></li>
  </ol>
  
  <p>The code:</p>
  
  <pre><code>if len(o)%2: o+='a' #avoid odd-length
  return unhexlify(o)
  </code></pre>
  
  <p>And the return data I can even compress with zlib. Total of 45% compression ratio.</p>