joshie75 wrote:
Well now that i've entered those few lines into my calculator heres my program as of now.

Code:
:1->N
:ClrHome
:ClrDraw
:AxesOff
:Input "Your word please",Str1
:length(Str1)->L
:Text(1,1,"Number of letters"
:Text(10,1,L
:Pause
:Lbl 1
:ClrHome
:Input "pick one letter ",Str2
:While Z>0
:inString(Str1,Str2,N)->Z
:Z+1->N
:End

When i enter my word, i entered, "GOODBOY" 0x5 yes i realize that is two words, i just used to for repetition of a letter; then it goes to the graph, i press enter to exit the pause, and then i enter the letter "O" as my guess and hit enter. It just says "Done".
hmm Razz
i guess it is because the fast the nothing is to be displayed;
how do i get it to display the number of letters found? Razz


It ends because you don't have a loop, I will let someone else recommend the best type for this situation, also, if you just want to view the number, on the same line as pause, put Ans, nothing in between, and tell me how that goes.
I'm still saying that this will probably be easier and more efficient to program by using lists, instead of trying to do everything with strings.
Hmm, programming gets confusing Sad with the Ans being displayed.. it is taking the Answer from Z+1.. I need to almost make it keep a "tally mark" for every time it finds that letter, then count up those "tallies" and display the total number of "tallies".
joshie75 wrote:
Hmm, programming gets confusing Sad with the Ans being displayed.. it is taking the Answer from Z+1.. I need to almost make it keep a "tally mark" for every time it finds that letter, then count up those "tallies" and display the total number of "tallies".


Nuuu, that will just tell you how many times it finds it in a string, add this to your code:


Code:
:1->N
:ClrHome
:ClrDraw
:AxesOff
:Input "Your word please",Str1
:length(Str1)->L
:Text(1,1,"Number of letters"
:Text(10,1,L
:Pause
:Lbl 1
:ClrHome
:Repeat K=104//waits until the "negative" symbol is pressed
:getKey->K
:Input "pick one letter ",Str2
:While Z>0
:inString(Str1,Str2,N)->Z
:Text(20,1,Ans
:Z+1->N
:End
:End


The location that letter is at will be displayed in Ans.
That will change depending on your Str2 input also.
ok another "Str1" question Razz
i know how to store the length of a Str via length(Strx)->L
but the question is... can i take that and make it output a certain amount of symbols?
say i was using the text feature for the graph screen. Text(.. and the length of the Str is 5 characters.. can i make it output 5 "?"s in a row to be later replaced by a letter if guessed correct? :S thanks in advance, you guys rock Smile
Absolutely. I'd say something like:


Code:
"?
:For(X,2,L
:Ans+"?
:End
:Ans->StrX
KermMartian wrote:
Absolutely. I'd say something like:


Code:
"?
:For(X,2,L
:Ans+"?
:End
:Ans->StrX


Hmmm... I think I can think of a different way.



Code:
:"?:->StrX
:For(X,1,L
:StrY+StrX->StrX
:End


That should work, though it is not tested.
And what's in StrY exactly in that particular piece of code?
KermMartian wrote:
And what's in StrY exactly in that particular piece of code?


An empty string, I probably should have used:

Code:
:StrX+"?"->StrX

But would that even work?
hey Kerm can we break down your code so i can more understand it? remember im a noobie Smile
so for the For( command...
from what i understand it counts from 2 til the length of the str? i dont get that :S
and for the ans+"?
what exactly does that part do?
Absolutely. I'd say something like:


Code:
"?
Implicitly stores "?" into the answer variable.

Code:
:For(X,2,L
Loop the variable X from X=2, X=3, X=4, ... up until X=L.

Code:
:Ans+"?
Append a "?" to the contents of Ans, and implicitly store that back to Ans. Ans will become "??", "???", "????" as the loop repeats

Code:
:End
Perform the next iteration of the loop

Code:
:Ans->StrX
Finally take the implicit Ans string and put it somewhere stable.
KermMartian wrote:
Absolutely. I'd say something like:


Code:
"?
Implicitly stores "?" into the answer variable.

Code:
:For(X,2,L
Loop the variable X from X=2, X=3, X=4, ... up until X=L.

Code:
:Ans+"?
Append a "?" to the contents of Ans, and implicitly store that back to Ans. Ans will become "??", "???", "????" as the loop repeats

Code:
:End
Perform the next iteration of the loop

Code:
:Ans->StrX
Finally take the implicit Ans string and put it somewhere stable.


If I had used For(X,2,L then mine would have been storing it directly to StrX instead of Ans, then to X, I do not think it matters on speed, but mine might be about .1 milisecond's faster. :p
As per request, here's a little tutorial on lists.

Lists, much like Strings, are methods of storing a variable amount of some form of data into one variable. And for ease of explanation, know that when I say variable, I mean something that can change, and in our case as programmers, will hold a value of some sort, be it numerical or characters (as in strings). Also know that this is not the only definition of variable I/we (the programming community) will use, as it's root meaning is able to vary. This second definition would be used to describe (in most cases) the length of a string, list, etc., as being variable, or (yes, again) able to vary.

A string can be said to be one or many characters in a sequence, surrounded by quotes. Anything beyond that is variable, as the length of the string, the pattern of them, and which ones make the pattern are all able to vary to the user's liking, as I'm sure you already know. A list is much the same, except with numerical values. Where as you could have a string that is "ABC", you can also have a list that is {1,2,3}. Notice how strings are surrounded by quotation marks, whereas lists are surrounded by opening and closing brackets. Also note that each "element" (or each value in the list) is separated by a comma. This way you know where the list begins, ends, and you can tell what each value is.

Another major difference between lists and Strings is that with lists, you can store a value directly into a certain element of a list, overlapping the previous value. With strings, if you want to over-write a particular element of the string, you have to recreate the part of the string before that element, write in the new element, and then recreate everything after that element, which is annoying, takes valuable time, and can often run you errors if certain conditions are met. Also, lists support many more commands than Strings, which will help you use them, like being able to find the sum of all the elements of the list, with just one command, or the product of them all, again with just one command.

You can recall a value from a list by naming the list, then putting parenthesis around the element of the list, like so:

Code:
:L1(1)

You store a value into a list by nearly the same method, like so:

Code:
:#→L1(1)


Another major difference between Strings and lists is that whereas there are only ten usable Strings that can be used by the user (Str0-Str9), you can make your own lists, with their own name on the calculator, on top of the 6 already made for you (L1-L6).

Here are some ways to make your own list: (Note: a custom made list can have a name from 1 to 5 characters long, using only the "A-Z" characters, and requires a small "L" before it's name for the calculator to recognize you mean a list. I signify the small "L" with a *L*. It can be found under [2nd],[LIST],[→],[B])

Code:
:SetUpEditor LISTA,LISTB,LISTC
-SetUpEditor does as it's name implies, it will set up lists among other things to be edited. This is a useful command, as it creates a list if it has not been made (btw, yes, you have to create a list, just like a string, if it has not been made already, especially so with custom lists), it will unarchive a list if it is archived, and it can create several lists at once, as you can see. However, this will not set dimensions nor values to the lists, as you have to set those yourself, as you will see below-

:#→dim(*L*LISTA
:Fill(0,*L*LISTA
:*L*LISTA→*L*LISTB
:*L*LISTB→*L*LISTC
-what this is doing here is setting the dimensions to a list, then filling it entirely with 0's. After that, it's storing the original into the next two, basically making copies of itself into the other two. If you want each of the lists to be different, then you'll need to set the dimensions of each one accordingly, and possibly their Fill( values as well-

:{1,2,3,4,5,6}→*L*LISTA
-this is (obviously) hard-coding in the list. This is usually not recommended as there are usually better methods to do than this, but often it is the best method. You can (as I'm sure you could imagine) hard-code in each list to be tailored for your own needs-

:seq(A,A,1,6→*L*LISTA
-this is the last method I'll go over. Using specialized commands that will output lists. This is basically the same as hard-coding in the, but using a command that will output a list, and storing that outputted list directly into *L*LISTA. seq( will make a sequence based on what is given to it. The first parameter is the sequence it will follow, much like a graph, except now with any variable you want. The second parameter is which variable you want to use. So here I'm making it count up A, using the variable A. The third parameter is the lower bound, which is where it will start counting. Here, it will start from 1, upwards. The fourth parameter is the upper bound, which is where it will stop counting, when it is equal to or greater than this value. For this line of code, it will go up as A, using variable A, from 1 to 6, essentially creating the same list as I just showed with the hard-coding example. A hidden fifth parameter is the increment, which you can use to count up by twos, count up by 3, or even down by -1. You will run into an error if the third parameter will never reach the fourth (i.e. the lower bound is above the upper bound and the increment is positive) so try to avoid that-


You can also compare a single value against a whole list. What this means is that if I want to know what values in L1 are equal to or greater than 0, then I can do this:

Code:
:L1>=0

HOWEVER, this will return as a list of it's own. It will return as a list of either zeros or ones, for false or true, respectively. If element one of L1 is true for the statement, it will return one, but if element two is false, then it will return zero. This is then made into a new list of it's own. If I wanted to know if there were 3 zeros in L1, then I could do this code:

Code:
:If 3=sum(0=L1)


What that means is that it is checking to see if 3 equals the sum of the list that is returned when I check if zero equals L1. You could use a similar code to find out how many letters in your given hang-man word equal a guessed letter. On top of that, you could also find out which ones of those letters equal the guessed letter.

You can also do a similar thing with comparing one list to another. By comparing one list to another, it will check each element for true/false. However, both lists need to have the same exact dimensions to be compared, because otherwise it doesn't know what to do with the left-over numbers that can't be compared to another number.

If you have any more questions, don't hesitate to ask, or check out this article on lists, and their commands. It doesn't go into much detail about their commands, but it will link you to very detailed articles about each command.
alright that made lists a little more clearly.. but be warned i am still new so i still have a hard time understanding and incorperating them :\

how would i store the alphabet as the list?
abcdefghijklmnopqrstuvwxyx->LALPHA
?
joshie75 wrote:
alright that made lists a little more clearly.. but be warned i am still new so i still have a hard time understanding and incorperating them :\

how would i store the alphabet as the list?
abcdefghijklmnopqrstuvwxyx->LALPHA
?


You can't :/ there is a way to get them from a string using inString() with the alphabet stored to a string, and then a list with 26 elements from 1-26, and get letters according to the number in the current list element, but I will let someone who can explain those do so since I manage to confuse myself trying to learn them originally.
lol alright.
so what youre saying is...

:abcdefghijklmnopqrstuvwxy->str3
:str3->LALPHA

maybe?
joshie75 wrote:
0x5 alright.
so what youre saying is...

:abcdefghijklmnopqrstuvwxy->str3
:str3->LALPHA

maybe?


Nuuuu, lol, to get the list nice and quick, try this:


Code:
:26->dim(LALPHA
:For(A,1,26
:A->LALPHA(A
:End


That should give you 1-26 in that list, and have the alphabet in Str3, then use this,


Code:
:input "1-26: ",A
:Output(1,1,sub(Str3,LALPHA(A),1


Now just change the value of A and see what you get.
[/code]
what is that first code doing?
at first i can see its setting the list as a list with 26 spaces.. correct?
then what is for( command for? and then the a->LALPHA(A what is that doing?
joshie75 wrote:
what is that first code doing?
at first i can see its setting the list as a list with 26 spaces.. correct?
then what is for( command for? and then the a->LALPHA(A what is that doing?



The first line: 26->dim(LAPLHA is making it have 26 open spaces you can use, if not, the rest of the code would return a DIM error.

The For(A,1,26 is looping the code until A has reached 26, so it is taking A, storing 1 to it, and adding 1 each time it reaches the End at the last line of that code.

The A->LAPHA(A is taking the current value of A, and storing it to the element in the list that is in the same position, let me edit it a bit so you can see what it is doing as it works.



Code:
:26->dim(LALPHA
:For(A,1,26
:A->LALPHA(A
:Output(1,1,LALPHA
:Output(3,1,LALPHA(A
:Output(4,1,A
:Pause
:End


Now you can see what it is doing as it goes. Smile
so basically that little code right there set the dimension to 26 spaces.. and then it assigned each space a number.. and to recall the letter B lets say.. ill use..
:LALPHA(2
?
  
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 2 of 4
» 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