New Features in Python 1.6
effbot at telia.com
Tue Apr 4 16:05:47 EDT 2000
Philip Newton wrote:
> >why not just use two different compression algorithms repeatedly,
> >until you've squeezed the file down to a suitable size? it takes a
> >little work, but you can design them so that one of them can always
> >strip away at least one bit from the input stream.
> Yes? I challenge you to provide any algorithm that will strip away one
> bit from the four sequences 11, 10, 01, and 00, while still being able
> to restore the previous state.
okay, okay, I shouldn't have posted that several days after
april 1st... but hey, this group is (indirectly) named after a
infamous comedy troupe, so what did you expect?
anyway, here's the code:
n = number_of_bits
while n > minsize:
print "used algorithm 1"
print "used algorithm 2"
raise IOError, "deranged data"
n = n - 1
where skip_false_bit() and skip_true_bit() returns true if
the succeed to actually compress the data.
to decode, just call insert_false_bit() and insert_true_bit()
repeatedly, in the *right* order ;-)
More information about the Python-list