There's more than one way to do things  
PerlMonks 
Re^4: Dynamically Updating Frequency Analysisby Limbic~Region (Chancellor) 
on May 08, 2013 at 19:04 UTC ( #1032665=note: print w/ replies, xml )  Need Help?? 
BrowserUk,
If the payload was 98 bytes and we add the letter X we get 99 so we start out by saying '99X..' but by adding 99 to the message we added two more bytes which made it '101X..' but because 101 is longer than 99 by 1 byte, the final value was 102X. This was a simple problem to solve though I never did understand why the length had to include itself. Getting back to the OP, here is the approach I have been playing with in my head. There will be 96 characters (Unix newline plus ASCII 32  ASCII 126). This means a 1/8 reduction simply by going to 7 bit characters and leaves room for 32 multicharacter tuples. Rather than keeping track of each tuple separately, keep track of data structures of size 3 (originally I thought 4 could fit into memory but I am not so sure). Single characters are ignored because they will be encoded using the 7 bit method.
Once the data structure is created, get the frequency of all the 2 character tuples (requires traversing the data structure). With this data in hand, use a heuristic algorithm to pick an approach. You could limit how long you look based on time or number of iterations or what not. Pick the tuple (either 2 or 3) that saves the most space. There should be enough data in the tree to measure the impact of every choice and recalculate frequencies. Once 32 have been chosen  remember the choices and the total size reduction and restart by picking the 2nd highest choice first. Does this make sense? It does in my head but I have been struggling with articulating ideas lately. Cheers  L~R
In Section
Seekers of Perl Wisdom

