Login [Register]
Don't have an account? Register now to chat, post, use our tools, and much more.
I have been working on a bunch of small programs lately (I am still fairly new to programming and don't know a whole lot about it) and I have gotten stuck on how to progress on this specific one.

My goal is to be able to have the user (or users as it's supposed to be for 1-4 players) choose a combination for three coin flips. Then, each coin flip is displayed on the screen one by one. Once a prediction is made by the repeated coin tosses, the program registers this and declares the winner.

Iv'e hit a brick wall on this one and don't really know how to move forward from here. Any help is greatly appreciated!

Code:
1→H
0→Z
ClrHome
Disp "SELECT NUMBER OF PLAYERS
Input "PLAYERS=",W
Lbl 0C



Lbl C0
IS>(Z,W-1
Goto CS
ClrHome
Output(1,9,"PLAYER
Output(1,16,Z
Repeat H=4
Output(3,4,"INPUT COIN FLIP
Output(3,20,H
Input Y
Y→⌊V(H
H+1→H
End
Goto C0
Output(3,20,




Lbl CS
0→H
ClrHome
Output(1,1,"P1:
Output(1,5,⌊V(1
Output(1,6,⌊V(2
Output(1,7,⌊V(3
randInt(0,1,54)→G
While H<26
H+1→H
⌊G(H)→L
If L=0
Then
Output(5,H,"H
Else
Output(5,H,"T
End
Pause
End
Lbl CR
H+1→H
⌊G(H)→L
If L=0
Then
Output(6,H-26,"H
Else
Output(6,H-26,"T
End
Pause
Goto CR


Note: I have been programming for the TI-84 Plus CE

Also, a second question. When I use the code editor here, or copy someones code here, I won't run on my calculator because it adds a space at the end of every line. I've had to manually delete every space to get it to run. Is there any way that I can prevent this from happening or get my calculator to run it?
So you basically want to check if a combination of 3 zeroes or ones is in the long list of the 54 coin flips?

Outside of this, I see a ton of optimizations Razz
First of all, you have the TI-84 Plus CE, which means the BASIC token toString() is available with the latest OS, so
Code:
Output(1,9,"PLAYER
Output(1,16,Z
can be
Code:
Output(1,9,"PLAYER "+toString(Z
, or something like this.
Secondly,

Code:
1->H
Repeat H=4
...
H+1->H
End
can be
Code:
For(H,1,4
, which is smaller and faster Smile
My last point is, that

Code:
While H<26
H+1→H
⌊G(H)→L
If L=0
Then
Output(5,H,"H
Else
Output(5,H,"T
End
Pause
End
Lbl CR
H+1→H
⌊G(H)→L
If L=0
Then
Output(6,H-26,"H
Else
Output(6,H-26,"T
End

can be optimised to

Code:
For(H,1,54
Output(5+int((H-1)/26),1+remainder(H,26),sub("HT",|G(H)+1,1
Pause
End

I will explain this code line by line, as it can be hard to understand Wink
You want to loop through all the coin flips, so For(H,1,54. Now, if H<27, you want to display them at line 5, and for H>26, at line 6. This is done by 5+int((H-1)/26). If H=26, it calculates 5+int(25/26) = 5+0 which is of course 5, and that is what we want. If H=27, then we calculate 5+int(26/26) which is... 6, exactly what we want! Now, for the first 26 coin flips, you want to display the outcode at column H, and if H>26, at column H-26. This is done by 1+remainder(H,26). remainder(H,26) returns the remainder of H/26, which is a number between 0 and 25, so that I why I added the "+1". The last part is to figure out what we want to display at the specific coordinates. sub("HT",|G(H)+1,1) gets the coin flip, and then selects the corresponding letter to it, which is either the "H" or the "T".

Outside the fact that this is smaller and faster, I've removed a Lbl/Goto, and I recommend you to do too, because normally a Goto/Lbl is pretty slow.

Hopefully you will understand this all, and if not, don't hesitate to ask us anything!

I also moved this to the TI-BASIC subforum, as this is the right place to ask questions about TI-BASIC.
Alpha527 wrote:

Also, a second question. When I use the code editor here, or copy someones code here, I won't run on my calculator because it adds a space at the end of every line. I've had to manually delete every space to get it to run. Is there any way that I can prevent this from happening or get my calculator to run it?



I believe someone wrote a website made to remove spaces form the end of lines in SC3, but I can't remember the website. Ask around, and see if you can get some one to tell you. I think @PT_ did it.
  
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 GMT - 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