Don't have an account? Register now to chat, post, use our tools, and much more.
This is an archived, read-only copy of the United-TI subforum , including posts and topic from May 2003 to April 2012. If you would like to discuss any of the topics in this forum, you can visit Cemetech's TI-BASIC subforum. Some of these topics may also be directly-linked to active Cemetech topics. If you are a Cemetech member with a linked United-TI account, you can link United-TI topics here with your current Cemetech topics.

68k Calculator Basic => TI-BASIC
Author Message
Xphoenix

Elite

Joined: 04 Apr 2007
Posts: 756

 Posted: 04 Apr 2007 09:06:27 pm    Post subject: So I have a list that is supposed to hold a deck of cards. I need to shuffle the deck. Is there a function that let's me do this (am I missing something obvious)? Or is there method to do this? I have a method for doing this, but it is very inefficient.
Harrierfalcon
The Raptor of Calcs

Super Elite (Last Title)

Joined: 25 Oct 2006
Posts: 2535

 Posted: 04 Apr 2007 09:13:55 pm    Post subject: Do you have a format for doing this? Obviously 1-13 is Ace thru King, but what about suits? If your format is each suit is .1, .2, .3, and .4, then [font="courier new;font-size:9pt;line-height:100%;color:darkblue"]:seq(1+round(13fPart(Z/13),0)+int((Z+13)/13).1,Z,0,51->L1 :rand(52->L2 :SortA(L2,L1 L1 holds the deck of cards. L2 is a bunch of garbage. Btw, Welcome to United-TI! EDIT: Crap. I thought this was in z80 basic...sorry.Last edited by Guest on 04 Apr 2007 09:18:08 pm; edited 1 time in total
Xphoenix

Elite

Joined: 04 Apr 2007
Posts: 756

 Posted: 04 Apr 2007 10:24:18 pm    Post subject: This is in the 68k section... I don't need suits or K/Q/J (lol). I just need the numbers (1-13, each four times).
DarkerLine
ceci n'est pas une |

Super Elite (Last Title)

Joined: 04 Nov 2003
Posts: 8328

 Posted: 05 Apr 2007 10:33:48 am    Post subject: The principle is the same, the syntax is just a bit different. [font="courier new;font-size:9pt;line-height:100%;color:darkblue"]seq(int(i/4),i,4,55)→cards seq(rand(),i,1,52)→rnd SortA rnd,cards
Xphoenix

Elite

Joined: 04 Apr 2007
Posts: 756

 Posted: 05 Apr 2007 08:57:48 pm    Post subject: So "cards" would be the shuffled deck? What's "rnd" for? (If it's the same as L2, then what do I need garbage for? It's not even used in storing "cards.")
Harrierfalcon
The Raptor of Calcs

Super Elite (Last Title)

Joined: 25 Oct 2006
Posts: 2535

 Posted: 05 Apr 2007 09:16:53 pm    Post subject: I don't know 68K basic but I know why. It is used for shuffling. The method DarkerLine uses to make the deck creates it all in an ordered sequence. So, by storing a 52 random numbers to a list, the chance that an element equals any other will be very little. [font="courier new;font-size:9pt;line-height:100%;color:darkblue"]SortA rnd,cards presumably does the same function that it does in z80 basic. It sorts rnd, using cards as a freqlist. Say you have listtwo whose elements look like [font="courier new;font-size:9pt;line-height:100%;color:darkblue"]1 2 3 4 5, and you have a listone that looks like [font="courier new;font-size:9pt;line-height:100%;color:darkblue"]2 3 4 1 5. Then SortA listone,listtwo would change listone into [font="courier new;font-size:9pt;line-height:100%;color:darkblue"]1 2 3 4 5 and listtwo into [font="courier new;font-size:9pt;line-height:100%;color:darkblue"]4 1 2 3 5.Last edited by Guest on 05 Apr 2007 09:17:16 pm; edited 1 time in total
DarkerLine
ceci n'est pas une |

Super Elite (Last Title)

Joined: 04 Nov 2003
Posts: 8328

 Posted: 05 Apr 2007 09:22:26 pm    Post subject: It's a list of random numbers, which you temporarily use to shuffle [font="courier new;font-size:9pt;line-height:100%;color:darkblue"]cards. The statement [font="courier new;font-size:9pt;line-height:100%;color:darkblue"]SortA rnd,cards sorts [font="courier new;font-size:9pt;line-height:100%;color:darkblue"]rnd into order while keeping [font="courier new;font-size:9pt;line-height:100%;color:darkblue"]cards "in sync" with it: for example, if the fifth element of [font="courier new;font-size:9pt;line-height:100%;color:darkblue"]rnd were the smallest, it would go to the front, and the fifth element of [font="courier new;font-size:9pt;line-height:100%;color:darkblue"]cards would also be moved to the front. Sinc the random numbers are in random order and the cards are in increasing order, putting the random numbers in increasing order while keeping the cards in sync results in the cards being in random order. All you need to know if you don't understand this explanation is that you need [font="courier new;font-size:9pt;line-height:100%;color:darkblue"]rnd during this tiny bit of code, but once it's done you can delete it. In fact you should probably declare [font="courier new;font-size:9pt;line-height:100%;color:darkblue"]rnd as [font="courier new;font-size:9pt;line-height:100%;color:darkblue"]Local.
Xphoenix

Elite

Joined: 04 Apr 2007
Posts: 756

 Posted: 05 Apr 2007 09:56:05 pm    Post subject: Ok... That works. But I still though don't know the syntax for seq(. But I don't need to (currently). *few seconds later* NVM, I read the manual.Last edited by Guest on 05 Apr 2007 09:57:20 pm; edited 1 time in total
 Display posts from previous: All Posts Oldest FirstNewest First
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.

»
 Page 1 of 1 » All times are GMT - 5 Hours