I want to have a program that converts a string to numbers. for example Max -> {13,1,19}
Thanks!
This will store the numbers into L1
"WORD→Str1
seq(inString("ABCDEFGHIJKLMNOPQRSTUVWXYZ",sub(Str1,A,1)),A,1,length(Str1→L₁
Is there a reverse code for this? Like you have a list of numbers and want to turn it into letters?
Yes, but it's a little longer:
" "
For(A,1,dim(L₁
Ans+sub("ABCDEFGHIJKLMNOPQRSTUVWXYZ",L₁(A),1
End
sub(Ans,2,length(Ans)-1→Str1
Basically, you start with a string with any character at the beginning ("space" in this case), loop through for each number in the list and add that character to the string, then remove the extra character at the beginning of the string.
Wow thanks man! What's the best way to make it so that it turns a string of letters into one number? Like instead of "ABC" turning into {1,2,3}, "ABC" turning into 123.
If you have a TI-84+CE with the latest operating system, you can use the toString( command to convert the numbers to strings and add them together like I did in the For( loop above. If you have a previous model of calculator, you will need to look at the Number to String algorithm.
Thanks guys. This helped me a bunch. Is there any way you could explain how these commands work in depth? Thanks!!!
The first establishes the alphabet, sifts through each character in the string, compares the character to the alphabet, then stores the letter's position in the alphabet to a list.
The second does the reverse, it takes a number from the list, finds the indicated position in the alphabet, and adds the letter in said position to the string.
Look at string-to-list or list-to-string for more info
Could you also use Ans instead of Str1? Would that save on any memory?
I have a program on my TI-84 Plus that encodes and decodes messages using some Algebraic method. When you decode the message, it gives you a list of numbers, each corresponding to a letter of the alphabet (A = 1, Z = 26, etc.). Is there a way I can add this code to my program so that it converts the list of numbers to letters and displays it? I’m really new to programming on my calculator, so if you could really dumb down your response or even give me an example code, I’d really appreciate it. Thanks!
This code should work. It's a list>string routine
" "
For(A,1,dim(L₁
Ans+sub("ABCDEFGHIJKLMNOPQRSTUVWXYZ",L₁(A),1
End
sub(Ans,2,length(Ans)-1→Str1
But for me, this code actually returns a domain error. IDK why.
🧟Initiating Project Horde 🧟
That’s exactly why I asked, I got the same error
The error is coming in the way sub( works. sub( takes the arguments as [String, Start, Length]. Remember that in TI-Basic, strings are 1-indexed instead of 0-indexed like most other languages. According to the errors page, one of your arguments is outside of the specified range. Since having a Length of one will never go outside the bounds of the string, this means that your Start must be what is causing the issues. Try figuring out if there is a specific value which causes the error. The valid range should be 1≤L₁(A)≤26. Alternatively, this code should tell you where your issue is:
seq(I,I,26,1,-1→L₁
"?"
For(A,1,dim(L₁
Ans+sub("ABCDEFGHIJKLMNOPQRSTUVWXYZ",L₁(A),1
Pause Ans
End
sub(Ans,2,length(Ans)-1→Str1
You will need to press output after each step, but that code should have no errors and should produce:
?Z
?ZY
?ZYX
?ZYXW
?ZYXWV
?ZYXWVU
?ZYXWVUT
?ZYXWVUTS
?ZYXWVUTSR
?ZYXWVUTSRQ
?ZYXWVUTSRQP
?ZYXWVUTSRQPO
?ZYXWVUTSRQPON
?ZYXWVUTSRQPONM
?ZYXWVUTSRQPONML
?ZYXWVUTSRQPONMLK
?ZYXWVUTSRQPONMLKJ
?ZYXWVUTSRQPONMLKJI
?ZYXWVUTSRQPONMLKJIH
?ZYXWVUTSRQPONMLKJIHG
?ZYXWVUTSRQPONMLKJIHGF
?ZYXWVUTSRQPONMLKJIHGFE
?ZYXWVUTSRQPONMLKJIHGFED
?ZYXWVUTSRQPONMLKJIHGFEDC
?ZYXWVUTSRQPONMLKJIHGFEDCB
?ZYXWVUTSRQPONMLKJIHGFEDCBA
ZYXWVUTSRQPONMLKJIHGFEDCBA
If you get no errors with that snippet of code, that means that whatever values you have in L1 are the issue, and not the code
Ok. Thanks! I ran the code and figured out what I did wrong. I was using code to detect when the variable being stored in L1 is 0. However, this left a 0 in the list at the end of the list. Running through the List>String routine ran into an error with that 0.
So… short answer it works now.
🧟Initiating Project Horde 🧟
"If you get no errors with that snippet of code, that means that whatever values you have in L1 are the issue, and not the code"
I put the numbers 1, 2, 3, 4, 5, 6, 7, & 8 in L1 and still got an error message……?
Are they separated? As in L1 is:
{1 2 3 4 5 6 7 8}
Or is it
{12345678}
Because how this works is it relates each number with a point in the string and retrieves that letter.
Otherwise, make sure you typed everything correctly.
🧟Initiating Project Horde 🧟
TI-Basic_Dev_Newbie, can you please post your full code, and exactly what you have in the list? That's really the only way to help your specific case.
What happens when you run the code I posted?
Here's the code for the program I'm trying to fit this addition into:
:0→Θ
:0→dim(L₂
:0→dim(L₃
:0→dim(L₄
:0→dim(L)
:{2,2}→dim([B]
:6→[B](1,1)
:5→[B](1,2)
:7→[B](2,1)
:6→[B](2,2)
:"ABCDEFGHIJKLMNOPQRSTUVWXYZ →Str1
:ClrHome
:Menu("FUNCTION","ENCODE",1,"DECODE",2)
:Lbl 1
:Disp "MESSAGE"
:Input Str3
:length(Str3)→A
:If fPart(A/2)≠0
:Then
:Disp "ERROR: ADD SPACE"
:Stop
:End
:{2,A/2}→dim([A]
:For(N,1,length(Str3
:inString(Str1,sub(Str3,N,1),1)→O
:If N≤.5length(Str3
:Then
:O→[A](1,N)
:End
:If N>.5length(Str3
:Then
:O→[A](2,N-.5length(Str3)
:End
:End
:[B]*[A]→[C]
:Matr►list([C]ᵀ,L₁,L₂)
:augment(L₁,L₂)→L
:Disp L₁
:Stop
:Lbl 2
:1→V
:ClrHome
:Disp "NUMBER OF"
:Disp "CHARACTERS"
:Input F
:{2,F/2}→dim([D]
:Lbl 5
:1→M
:If V>F
:Then
:Goto 6
:End
:Disp "NUMBER"
:Input J
:If V≤.5F
:Then
:J→[D](1,V)
:End
:If V>.5F
:Then
:J→[D](2,V-.5F)
:End
:V+1→V
:Goto 5
:Lbl 6
:[B]⁻¹*[D]→[E]
:Matr►list([E]ᵀ,L₃,L₄)
:augment(L₃,L₄)→L₁
:Disp L₁
*Nothing after this point is part of
the original code*
:Pause
:Menu("CONVERT TO ABC?","YES",8,"NO",9)
:Lbl 8
*This is where I want the code that
converts the string of numbers to letters*
:Disp *blank*
:Lbl 9
:Stop
The code will first "encode" a small message, then give you a list of numbers. These numbers can be plugged back into the program using the "decode" option and it will give you another list of numbers, but these correspond to the letters of the alphabet. (I should also mention: if the word you're encoding has an odd number of letters, you're required to add a space somewhere [I just put it at the end] when typing your message. This means there's technically an addition to the alphabet, which the code just puts as 27.)
To answer your question, Trenly, I typed in your code and it worked fine.
Is there a way I can fit your program into mine, UBERhelp1? I would greatly appreciate any help!
First, run your program and see the values of L1. The program Trenly posted worked, so that means it is the values of the list that are causing the error. Post them here. That will help us determine what you should fix (because I'm assuming it's not working). Then just copy/paste the list>string routine where you want it.
Additionally, I see a few bugs/typos/idk in your code.
- In the beginning, you store 0 in 0, which makes no sense. Did you mean a O?
- I haven't typed up your code, but there is probably a way to use fewer lists/matrices. If you no longer need a list stored, you can replace its values with a new list's values. Same with matrixes.
- You don't need a clear home before the menu.
- Your code exits if you type something up wrong, which could be frustrating for someone trying to use it. I'd recommend using a goto to go back to the place where you typed up your message instead of a stop exiting the program.
🧟Initiating Project Horde 🧟
First off I just want to say, this isn't my code, as in I didn't program this myself. I made a few modifications, yes, but I don't even understand what half of the code means.
Second, that says "0→θ"
Here's my code WITH the addition:
:0→θ
:0→dim(L₂
:0→dim(L₃
:0→dim(L₄
:0→dim(L)
:{2,2}→dim([B]
:6→[B](1,1)
:5→[B](1,2)
:7→[B](2,1)
:6→[B](2,2)
:"ABCDEFGHIJKLMNOPQRSTUVWXYZ →Str1
:ClrHome
:Menu("FUNCTION","ENCODE",1,"DECODE",2)
:Lbl 1
:Disp "MESSAGE"
:Input Str3
:length(Str3)→A
:If fPart(A/2)≠0
:Then
:Disp "ERROR: ADD SPACE"
:Stop
:End
:{2,A/2}→dim([A]
:For(N,1,length(Str3
:inString(Str1,sub(Str3,N,1),1)→O
:If N≤.5length(Str3
:Then
:O→[A](1,N)
:End
:If N>.5length(Str3
:Then
:O→[A](2,N-.5length(Str3)
:End
:End
:[B]*[A]→[C]
:Matr►list([C]ᵀ,L₁,L₂)
:augment(L₁,L₂)→L
:Disp L₁
:Stop
:Lbl 2
:1→V
:ClrHome
:Disp "NUMBER OF"
:Disp "CHARACTERS"
:Input F
:{2,F/2}→dim([D]
:Lbl 5
:1→M
:If V>F
:Then
:Goto 6
:End
:Disp "NUMBER"
:Input J
:If V≤.5F
:Then
:J→[D](1,V)
:End
:If V>.5F
:Then
:J→[D](2,V-.5F)
:End
:V+1→V
:Goto 5
:Lbl 6
:[B]⁻¹*[D]→[E]
:Matr►list([E]ᵀ,L₃,L₄)
:augment(L₃,L₄)→L₁
:Disp L₁
* The following code is the addition that does NOT work (it says "ERR:DOMAIN" *
:Pause
:Menu("CONVERT TO ABC?","YES",8,"NO",9)
:Lbl 8
" "
For(A,1,dim(L₁
Ans+sub("ABCDEFGHIJKLMNOPQRSTUVWXYZ ",L₁(A),1
End
sub(Ans,2,length(Ans)-1→Str1
:Disp Str1
:Lbl 9
:Stop
You didn't answer my main question. You are getting the error because of the values of L1. Please just run your code until the point where you say
The following code is the addition….
Just end the code after that. Then type L1 on your home screen. If you have any values less than 1 or greater than 27, your code won't work. If that is the case, you could use the multiplicative inverse of your coding matrix to decode the message, then use the matrix>list command and the list>string routine.
I'm not 100% sure if this will work, but instead of the person writing the message having to add spaces, you could use:
0.1→L
Repeat fPart(L=0
length(Str3)/4→L
If not(fPart(L=0
Str3+" →Str3
End
in place of
:If fPart(A/2)≠0
:Then
:Disp "ERROR: ADD SPACE"
:Stop
:End
🧟Initiating Project Horde 🧟
UBERhelp1, your code doesn't work, it just continues loading forever:
0.1→L
Repeat fPart(L=0
length(Str3)/4→L
If not(fPart(L=0
Str3+" →Str3
End
OK, so here's EXACTLY what I did in my original program's test run:
1.) Ran prgmSECRET
2.) Selected "ENCODE"
3.) Typed in "CATS"
4.) The four numbers it gave me in return: {118 101 141 121}
5.) Ran prgmSECRET again
6.) Selected "DECODE" this time
7.) Typed "4" when prompted with "NUMBER OF CHARACTERS?"
8.) Entered list: {118 101 141 121}
9.) The four numbers it gave me in return: {3 1 20 19}
Using the final four numbers it gave me, I ran this code from a new program:
" "
For(A,1,dim(L₁
Ans+sub("ABCDEFGHIJKLMNOPQRSTUVWXYZ ",L₁(A),1
End
sub(Ans,2,length(Ans)-1→Str1
And it STILL gave me "ERR:DOMAIN"
It has to be with how you are storing values to the list.
Try using this code with this specific input:
3,1,20,19,27,13,5,15,23
Don’t split the input, dont use spaces. Just type it exactly as I typed it, and then press enter
Input “CODE:”,Str0
expr(“{“+Str0→L₁
"?"
For(A,1,dim(L₁
Ans+sub("ABCDEFGHIJKLMNOPQRSTUVWXYZ ",L₁(A),1
End
sub(Ans,2,length(Ans)-1→Str1
Thanks, Trenly, but the whole point of my asking for help was to find a way to convert all of the numbers in the list to letters without having to input anything (the code will take the numbers from the list created previously in the program and convert it, then display them). Do you know how I can do this? (maybe using a modified version of what you have above?)
The whole point of writing code is for you to learn. Your issue is how the list is created in the previous step. What you need to do is something like this:
Input "Code:",Str0
Expr("{"+Str0→L₂
//code for converting L2 {118,101,141,121} into the desired list L1 {3,1,20,19}
"?"
For(A,1,dim(L₁
Ans+sub("ABCDEFGHIJKLMNOPQRSTUVWXYZ ",L₁(A),1
End
sub(Ans,2,length(Ans)-1→Str1
The input would be exactly:
118,101,141,121
Since I didn't write your code, its hard for me to follow. Therefore, you will have to modify either your code or my code to work for your needs. If there is anything you don't understand about my code, please let me know.