Calculator: TI-84+SE

Hello, I want to do a game, and I need one 14x24 matrix (or more): For divide the screen in 4x4 blocks, and boolean values to set this blocks black (1), and white (0). Then, the black blocks will be unpassable, and the user will travel around the white blocks.

This matrix size, actually is 9bytes per element (floating point number), but I want to set it as boolean to save a lot of memory. The floating point numbers matrix is actually more than 3kB, and in a calculator with 24 kB of RAM, this is not acceptable.

How can I do this?

Thanks for your help
Given the fact that a floating pointer number consist of 3 parts, the 'header', the exponent, and the number itself, we know that the number itself is 7 bytes. That is equal to 7*8=56 bits. You can set/reset all of the bits with some math magic, and I believe lirtosiast once wrote a post about this. If your matrix was 14x24, you can store 2 rows (or columns) in a single fpn, because a fpn can hold 56 booleans. (2*24 < 56). If do do some tricks even more. The minimum you can get = 14*24/56=6 elements, and the normal mode I think 7, which is only 54/63 bytes. Hope this helps! Smile
Thanks for your answer

I think that will require a decrypt code or routine that make a fpn divide in 56 booleans, I can make it with a loop, but I will need temporal storage to store the map, and when the user will exit the game breaking the program, this matrix will be in RAM until the user delete it.

I can write a matrix in flash storage?
You can archive the matrix within the program.
And you don't need such hard math routine, just take a look at the "Useful routines" in the TI-Basic section. I've posted a small code snippet that converts a number to a list of bits, this:

Code:
2fPart(.5int(N2^seq(X,X,~55,0
where N is your fpn. I'm not 100% sure it will succeed with ALL the digits, but I hope so Smile
Thanks for your help, now I can start coding.

Regards
PT_ wrote:
You can archive the matrix within the program.
And you don't need such hard math routine, just take a look at the "Useful routines" in the TI-Basic section. I've posted a small code snippet that converts a number to a list of bits, this:

Code:
2fPart(.5int(N2^seq(X,X,~55,0
where N is your fpn. I'm not 100% sure it will succeed with ALL the digits, but I hope so Smile

I'm not sure how exactly you calculated the 56, but 2^56=7.2×10^16. Since the calc only has 14 decimal places of accuracy, it can't possibly have that many combinations. However I do like the idea of keeping a few large integers which when represented in binary, becomes a boolean matrix.
I had some fun messing with this concept, here is what I did (sort of bringing it to life)
1) Started with a 12x24 matrix of randInt(0,1).
2) Then stored the two first rows (48 elements) to a list.
3) Created a list containing powers of 2 up to 2^47
4) Multiplied both lists together
5) Took the sum of the resulting list (this is the decimal number which when represented in binary, gives the 48 first elements of the random matrix)
6) To go back to the original booleans, just use PT_'s routine with the -55 replaced with -47
Here is the code for converting a 12x24 matrix to a list of 6 integers:


Code:
ClrAllLists
seq(2^X,X,47,0,~1→L₂               //creating a list of powers of 2 up to 2^47
For(B,1,12,2
sum(L₂seq([A](B+(A>24),1+remainder(A,24)),A,0,47→L₃(1+dim(L₃               //converting two rows at a time into a single integer concatenated at the end of L₃
End

To go back to a list of booleans, simply run PT_'s routine on each element of the list like this:

Code:
{0
For(A,1,6
augment(Ans,2fPart(.5int(L₃(A)2^seq(X,X,~47,0             //If L₂ has not been destroyed at this point, then you could use
End                                                      //augment(Ans,2fPart(.5int(L₃(A)L₂⁻¹ instead
DeltaList(cumSum(Ans→L₁

This will be a list of 288 booleans which are the ones in the original matrix, read from left to right then top to bottom. It could easily be modified to store it back to a matrix if you wanted to do so.
In the MEM menu, the final list (L₃) takes up 66 bytes, while the original matrix takes up 2603 bytes.
Disclaimer: The code has not been fully optimized, but it works.
mr womp womp wrote:

I'm not sure how exactly you calculated the 56, but 2^56=7.2×10^16. Since the calc only has 14 decimal places of accuracy, it can't possibly have that many combinations. [...] Here is the code for converting a 12x24 matrix to a list of 6 integers: [...] This will be a list of 288 booleans which are the ones in the original matrix, read from left to right then top to bottom. It could easily be modified to store it back to a matrix if you wanted to do so.
In the MEM menu, the final list (L₃) takes up 66 bytes, while the original matrix takes up 2603 bytes.


The discrepancy comes from the BCD format of TI floats. If TI were using a binary float format, one could probably store almost 56 bits in a seven-byte-mantissa float.

Xeda once observed that rounding errors prevent one from using more than 44 bits in a float, although I'm not sure if those would affect your code. See here.

As in most cases, there's a speed-memory tradeoff. If you're converting frequently, multiplication and division by powers of ten is slightly faster than by powers of two. So you can store the data in digits instead of bits, and I think all 14 digits can be used, because there should be no rounding errors in calculations involving powers of ten. The 14x24 matrix then becomes a 24-element list taking up 336 bytes + header; multiple lists can be stored in a matrix and extracted using Matr►list(). It could take less than 2 seconds to convert everything.

On the other hand, if you're converting very infrequently and have very large memory requirements, it's possible to use the exponent and sign of a float to store seven more bits of information per float. However, this will surely take over 5 seconds to convert 14*24=336 squares to a matrix.
I read the post by Xeda, but I too am not sure it applies to regular old integers (I don't perform any operations on them other than summing up a list to obtain them, and then breaking them up into binary bits) which is why I don't know if rounding errors should be an issue... Of course, I could go ahead and do something like 1 imaginary number=3 rows, which would get the number of bits down under the 44 mark, and luckily, he has 12 rows, which is a highly composite number so a bunch of combinations would be possible (imaginary and real numbers per row type of combinations)

EDIT: It applies... I think the last 2 or 3 digits are sometimes incorrect when converted back to binary by using the code above.
  
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