I'm having a problem with a program.

Here's what I have:

Code:
:For(A,1,5
:randint(1,6->L4(A
:End


What I want is a simple code block that will tell me if I have triples and what they are.

Ex: If this made a list like this {1 4 3 4 4}, I would want it to tell me that there is a set of triples, and tell me that the triples are the number 4.

Code:

ListNew.size = A
For x from 1 to length L4
ListNew.at(x)+1
EndFor


Then just loop through new list looking for a number equal to three. I'm sure there is a quicker way, but this is a method that works.
I moved this topic to TI-BASIC, the subforum in which it belongs. Anyway, the easy way to detect a triple would be the following:

Code:
:For(A,1,5
:randint(1,6->L4(A
:End
:SortA(L4
:If max(0=ΔList(ΔList(L4
:Disp "TRIPLE FOUND

How does this work? I'll show you an example. Consider the 5-element list {2, 4, 1, 4, 4}. After the SortA(), L₄ will contain {1, 2, 4, ,4 ,4}. The first ΔList() gets the difference between adjacent numbers. If any two adjacent numbers are the same, the ΔList() will return a zero: {1, 2, 0, 0}. The next ΔList() will do the same thing: {1, -1, 2, -2, 0}. the max(0=...) will return true if there are any zeroes in the list.

Edit: I found a counter-example. {1, 2, 4, 6, 8} will yield {1, 2, 2, 2} -> {1, 0, 0}, which is a false positive. I'll have to think further about interesting TI-BASIC tricks that could be employed here.
If three out of five elements are the same value, then that value is the median.

Code:
L1=median(L1
If 2<sum(Ans
Disp "Triple:",max(L1Ans
Oh, excellent point there. I was looking for a too-complex general-case solution for the given problem. I doff my hat to you as always, Weregoose.
Thanks. Im making a Dice game kind of like farkle and was having a hard time figuring out how to get the score from it. Hope this works. I should have the program done within the next week. I plan to try to add it to the archives.
Got it finished. If anyone wants it, here it is.
Dice
I'm glad to hear that you finished this. Are you planning to expand this idea into another future game or program, or do you intend to strike off on a different tack with your calculator program development?
I don't know where I would go from this game to put it in another program.
This is the full game of this game that I know of.
I plan to make some more games.
Right now, I'm brainstorming a game kind of like pokemon and yugioh, where you fight others with special powers to beat the powers of the land. ish.
  
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