I happened to think of this not too long ago, but didn't think it through very much, and as I started to realize how big games get if they use Matrices, Strings, or Lists for the maps, I figured this would be a great idea, although I haven't tried it yet, as the method I will need help getting together and working nicely.

First off I will show an example of a 5x5 Matrix, a 25 length string, and a 25 element list:


Code:
[0,0,0,1,1]
[1,1,1,0,0]
[2,2,2,2,0]
[0,0,0,4,4]
[5,5,4,0,0]

{0,0,0,1,1,1,1,1,0,0,2,2,2,2,0,0,0,0,4,4,5,5,4,0,0}

"0001111100222200004455400"


Each of those can be compressed to this string:


Code:
"0/3/1/5/0/2/2/4/0/4/4/2/5/2/4/1/0/2/"


Now I will explain.

Every "odd" number place(i.e. the 0,1,0,2 etc...) in the above string stands for what is in the matrix/list/string, and the number following the "/" after the "odd" number place is how many there are in a row.

Also I do know this won't compress some situations nearly as much to be worth it, not compress at all, or even expand the size, depending on what you are trying to compress.

I hope this makes sense.
That is called RLE (Run Length Encoding). Here is an article on TI|BD:
http://tibasicdev.wikidot.com/rle-compress
souvik1997 wrote:
That is called RLE (Run Length Encoding). Here is an article on TI|BD:
http://tibasicdev.wikidot.com/rle-compress
Seconded. RLE is particularly effective in compressing binary images (such as the ones used for monochrome and grayscale pictures on calculators) by storing the number of sequential 0s and 1s rather than the 0s and 1s themselves.
KermMartian wrote:
souvik1997 wrote:
That is called RLE (Run Length Encoding). Here is an article on TI|BD:
http://tibasicdev.wikidot.com/rle-compress
Seconded. RLE is particularly effective in compressing binary images (such as the ones used for monochrome and grayscale pictures on calculators) by storing the number of sequential 0s and 1s rather than the 0s and 1s themselves.


Although I do have another question, it only shows a way for lists, is there an easy tweak to get it for Matrices and Strings, of course the routine would change slightly, I will post the Compression and Decompression from that link for easier access:

Compression:

Code:

:1→J
:For(I,2,dim(L₁
:If L₁(I)=L₁(J:Then
:.002+L₁(J→L₁(J
:Else
:If L₁(I)=int(L₁(J:Then
:.001+L₁(J→L₁(J
:Else
:J+1→J
:L₁(I→L₁(J
:End:End:End
:J→dim(L₁


Decompression:


Code:
:dim(L₁→J
:sum(E3fPart(L₁)+not(fPart(L₁→dim(L₁
:For(I,Ans,1,-1
:int(L₁(J→L₁(I
:If .001<fPart(L₁(J:Then
:L₁(J)-.001→L₁(J
:Else
:J-1→J
:End:End
Almost the same things for matrices as for lists, except that you need to iterate over two dimensions with a two-level loop rather than just the one. Same concept though. For strings, I feel like RLE would be relatively useless (if a string is appreciable compressible with RLE, then representing the data in a string is probably a bad decision in the first place), but you could use the same concept as the list compressor but compare characters instead of values.
KermMartian wrote:
Almost the same things for matrices as for lists, except that you need to iterate over two dimensions with a two-level loop rather than just the one. Same concept though. For strings, I feel like RLE would be relatively useless (if a string is appreciable compressible with RLE, then representing the data in a string is probably a bad decision in the first place), but you could use the same concept as the list compressor but compare characters instead of values.


My thought was to take a list or a matrix and compress to a string, mainly for easier use in an appvar, and therefore reduce the size, but then again:

Code:
"{"+expr(Str1)+"}"

Would be just as well if you stored the list as a string with all the commas in it, what are your thoughts on this?
Not a bad idea as all, as long as each number plus its comma is fewer than nine characters. You can even store the braces in the string too, if you want. And if all the numbers in the string are the same length, you could omit the commas in the string and insert them later.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement