Omnimaga
Calculator Community => TI Calculators => TI-BASIC => Topic started by: Raylin on November 05, 2009, 10:10:34 pm
-
Yeah. I'm trying to do the impossible.
How do you convert a string into a single distinguishable number and back again?
The current code I have for encoding is:
DelVar A
Input Str1
sub(length(Str1->A
For(X,1,length(Str1
A+2^inString("ABCDEFGHIJKLMNOPQRSTUVWXYZ_"sub(Str1,X,1->A
End
Disp A
EDIT: FYI, the string "OMNIMAGA" would produce 66180.08.
Now, you would think that that is pretty distinguishable, right?
Wrong.
Comments? Questions?
-
Yay!!! New Puzzle for me!!!!~~~ I'm with you to the quest of finding the solution :D
-
Well for now I am going to point out where you are going wrong, but I'll leave the rest up to you (unless you insist you really need help :P) Lets say the word is AB. So 2^1 + 2^2 = 2+4 = 6. Yay! But since we are adding two numbers into the same digit, we can't know if it is 2+4 or 4+2. The problem here is that new Characters ovewrite and change previous digits, and that needs to not happen :)
-
Yeah... You know what I figured??? The probability of 7 character combination is 8,031,810,176 possibility,
since there are 26 characters, you do 26^length of word
It's really big number, and after 8th character, the calculator rounds
-
Actualy its 14 digits. The calculator only displays 8 tho
-
So, what are you trying to say, Builderboy? Are you saying that 2^X isn't distinguishable enough to be decoded? Or are you saying that the encoding process is wrong?
And, yes, I really need your help. :)
-
Well let me first put this out. The calculator only stores 14 digits, and each digit can range from 0 to 9. That is 10^14 states. That many states can only hold nine 26 state characters. Meaning the largest word you can compress will be 5 letters or less. And that is with fantastic compression that would probably involve changing of bases XD
This is the way I would do it, which would be 7 characters per number:
If you have a number, with 14 digits, it looks like this
##############
And any character can be represented by a 2 digit number 00-25. So divide up the digits
##|##|##|##|##|##|##
Where each set of digits converts to a character in a string. This method gives you a fair 77% of the possible information able to be stored in a single number though. But you can do any character from 0-99, so that is a bonus.
-
Hmm...
expr(sub("E14E12E101E81E61E41E2",3X-2,3))inString("ABCDEFGHIJKLMNOPQRSTUVWXYZ",sub(Str1,X,1)) ?
-
I'm assuming the E represents the little Scientific notation E?
You could simplify to 10^(2X) or something of the like
-
10^(2X)?
That seems like a bit much. Care to explain?
And, yes, it represents the little scientific E. :p
EDIT: Oh. Ha. I'm a retard. I get it.
EDIT 2: YES! Encoding finished! Working on decoding.
EDIT 3: Having issues with decoding.
"?->Str1
For(X,1,dim(L1
DelVar (theta)DelVar BL1(X->A
Repeat B
If not(int(10^((theta))(exponent -1)A
1->B
Pause (theta)
(theta)+1(not(B->(theta)
End
For(C,(theta)-2,0,-2
27+(C<0)int(10^(C)(exponent -1)A->D
Pause D
Str1+sub("ABCDEFGHIJKLMNOPQRSTUVWXYZ_",D,1->Str1
fPart(10^((theta)-2)(exponent -1)A->A
End
End
"sub(Str1,2,length(Str1)-1
Pause Str1
Do you see what I'm trying to do here?
It refuses to work though.
What am I missing here?
-
I actually am working on this, and is almost done... I just need to work on decoding.
I will upload it as soon as I'm finished.
Or may be just put the code :P
-
Thanks, man. It's nice to know that I have a wingman on this project.
:)
EDIT: Finished! WOO!
Man, that thing was a beast to accomplish.
You guys want the code?
-
Double-post again. Sorry.
(DJ Omnimaga, if the post is getting marked new, then why is the topic not going up to the top? Why is the time not changing?)
-
Because the post isn't any newer. It will still be marked as new, but will still be sorted by date. Lately there were a lot of posts, though, so it might be slightly harder to notice through the latest post list.
-
Yeah!! I finished it too!!!!!!! My program will code and decode upto 10 programs accurately.
Coding takes 106 Bytes and Decoding takes 177 Bytes, when I set the program name to 1 character.
I probably can optimize it tho. ProphetsDementia, you wanna compare the programs???
I'll post the code first~
Coding:
:0->C
:Input Str1->A
:For(X,1,A
:inString("ABCDEFGHIJKLMNOPQRSTUVWXYZ",sub(Str1,X,1->B
:C+B(26^(A-X->C
:End
:C->A
:DelVar BDelVar CDelvar Str1Disp A
Decoding:
:" ->Str1 //1 space
:Input C
:C->B
:0->A
:Repeat B<=0
:A+1->A
:B-26^A->B
:End
:For(X,A-1,0,-1
:0->B
:Repeat C<=26^X or B=26
:B+1->B
:C-26^X->C
:End
:If X=0 and C=1
:B+1->B
:Str1+sub("ABCDEFGHIJKLMNOPQRSTUVWXYZ",B,1->Str1
:End
:sub(Str1,2,A->Str1
:DelVar ADelVar BDelVar CDisp Str1
The decoding happened pretty much by luck, I just put random codes in and hoped that it to work properly :P
-
You could do something like this:
Before you encode/decode:
"ABCDEFGHIJKLMNOPQRSTUVWXYZ ->Str2
To encode (input string in Str1, ouput number in Ans):
0
For(A,1,length(Str1
Ans+28^AinString(Str2,sub(Str1,A,1
End
To decode (input number in B, output string in Str3):
" ->Str3
For(A,2,12
int(28fPart(B/28^A
If Ans
Str3+sub(Str2,Ans,1->Str3
End
Then you could do sub(Str3,2,length(Str3)-1->Str3 to get rid of the space at the beginning.
In For(A,2,12 ,12 would be the maximum length of the string you'd expect. I don't imagine these strings would be very long, or else accuracy would be lost fairly quickly (and then you'd get overflow errors too if they were over 69 characters or so). You could also do a While loop or have a condition that exits the loop if int(28fPart(B/28^(A equals 0 too. It could be rewritten many ways, such as even (I think this would work):
" ->Str3
1
For(A,2,99
Str3+sub(Str2,Ans,1->Str3
int(28fPart(B/28^A
If Ans
End
This would make the loop exit as soon as the number is finished being converted, while still using a For loop and not a While loop. In this case you'd do sub(Str3,3,length(Str3)-2->Str3 to eliminate the stuff at the beginning.
Again, the main problem with this method would be possible loss of accuracy when calculating these really large numbers (the root of this problem would exist for pretty much any other string <-> number encoder/decoder because of the limit of how many digits the calculator stores - there are other more complicated methods such as using complex numbers to increase the limit, but not extremely significantly). You could use base 27 instead of base 28 if you want by subtracting 1 from inString(Str2,sub(Str1,A,1 before multiplying it by 27^A, but I don't think it would matter much.
-
I got Data Type error in encoding... can't try out decoding if i can't encode :(
-
Oh, sorry, I forgot to include the first line of my code. The encoding one should be:
0
For(A,1,length(Str1
Ans+28^AinString(Str2,sub(Str1,A,1
End
I'm going to update my previous post too.
-
I am uploading my program.
I think it's bug-free, but if you find one, tell me~
Oh, and when the string length goes over 10, it loses its accuracy
-
Mine's is a bit larger.
But, it keeps its accuracy after 10 characters and it can be as large as memory allows.
And it supports lower-case letters.
Hopefully, bug-free.
Might be slow.
Credit to me if you use please.
You may use the alternate name Raylin if you need to.
-
My decoding is slow too, especially if you have Z in the string.
I am not at home right now, so can't download, will do it later~
For TLM, I at first decided to not use name, but through my program, will include naming once more, now with encoding and decoding haha
Thanks to you Prophets!
-
Off-hand, what is TLM?
I've seen in in your signature multiple times.
-
The Lost Map (some RPG he is working on ATM)
-
the Tale of the Lost Map to be exact, the RPG I'm making...