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.
TI-Basic Brain Teasers =>
TI-BASIC
Author |
Message |
|
luby I want to go back to Philmont!!
Calc Guru
Joined: 23 Apr 2006 Posts: 1477
|
Posted: 03 Jan 2007 09:45:08 am Post subject: |
|
|
How bout this as a teaser. finding a random integer from 0 to 10. I got it in (counts on fingers) 4? bytes (not in a program and not including the newline byte) displays as ans
Last edited by Guest on 28 Sep 2007 09:25:18 pm; edited 1 time in total |
|
Back to top |
|
|
vuurrobin
Advanced Member
Joined: 09 Aug 2006 Posts: 428
|
Posted: 03 Jan 2007 11:19:18 am Post subject: |
|
|
I am not sure what you mean but is it [font="courier new;font-size:9pt;line-height:100%;color:darkblue"]int(10rand |
|
Back to top |
|
|
nitacku
Advanced Member
Joined: 23 Aug 2005 Posts: 408
|
Posted: 03 Jan 2007 12:33:50 pm Post subject: |
|
|
Create an algorithm that given a random number from 1-52 will output the corresponding suit and rank of the card from a deck.
Suit should be in the order of Hearts, Diamonds, Clubs, Spades
Rank should be in the order of Ace, 2, ..., Ten, Jack, Queen, King
Example:
A random number of 17 corresponds to the 4 of Diamonds, so the algorithm will output "D4"
For simplicity, A, T, J, Q, K can represent Ace, Ten, Jack, Queen, and King
Also H, D, C, S can represent Hearts, Diamonds, Clubs, and Spades
EDIT: Start the algorithm with randInt(1-52
Last edited by Guest on 03 Jan 2007 12:36:46 pm; edited 1 time in total |
|
Back to top |
|
|
Weregoose Authentic INTJ
Super Elite (Last Title)
Joined: 25 Nov 2004 Posts: 3976
|
Posted: 03 Jan 2007 03:17:05 pm Post subject: |
|
|
vuurrobin wrote: I am not sure what you mean but is it [font="courier new;font-size:9pt;line-height:100%;color:darkblue"]int(10rand If you can find a random decimal that equals one. As it is, I don't think his challenge is possible in four bytes—unless you do [font="courier new;font-size:9pt;line-height:100%;color:darkblue"]int(rand3 first and then output in binary.
[EDIT]
Of course, this is me forgetting to subtract a byte for the newline. :roll:
nitacku wrote: Create an algorithm that given a random number from 1-52 will output the corresponding suit and rank of the card from a deck. This would have been more simple with less space given a random number from 0 to 51; I have my entry for the 1-52 case at 68 bytes nonetheless (as a program, excluding the characters in the title).
Last edited by Guest on 03 Jan 2007 05:10:47 pm; edited 1 time in total |
|
Back to top |
|
|
nitacku
Advanced Member
Joined: 23 Aug 2005 Posts: 408
|
Posted: 03 Jan 2007 04:26:32 pm Post subject: |
|
|
This is what I have:
[HIGHLIGHT]
:randInt(1,52)-1
:Disp sub("HDCS",1+int(Ans/13),1)+sub("KA23456789TQ",1+13fPart(Ans/13),1
[/HIGHLIGHT]
I think there is an error in the OS because sometimes I get a domain error unless I do:
round(1+13fPart(Ans/13)). Somehow there is still invisible decimals being left on the number even though it will display a whole number.
Last edited by Guest on 03 Jan 2007 04:33:05 pm; edited 1 time in total |
|
Back to top |
|
|
Recursive Acronym
Advanced Member
Joined: 11 Dec 2006 Posts: 499
|
Posted: 03 Jan 2007 05:02:21 pm Post subject: |
|
|
vuurrobin wrote: I am not sure what you mean but is it [font="courier new;font-size:9pt;line-height:100%;color:darkblue"]int(10rand
[post="94125"]<{POST_SNAPBACK}>[/post]
Actually, that would be "int(11rand". I am suprised at how often people mix this up. [EDIT:] I am surprised at how often I misspell "surprised".
nitacku wrote: This is what I have:
[HIGHLIGHT]
:randInt(1,52)-1
:Disp sub("HDCS",1+int(Ans/13),1)+sub("KA23456789TQ",1+13fPart(Ans/13),1
[/HIGHLIGHT]
I think there is an error in the OS because sometimes I get a domain error unless I do:
round(1+13fPart(Ans/13)). Somehow there is still invisible decimals being left on the number even though it will display a whole number.
[post="94139"]<{POST_SNAPBACK}>[/post]
You can optimize, first of all, by changing the first line to randint(0,51.
Last edited by Guest on 03 Jan 2007 05:08:56 pm; edited 1 time in total |
|
Back to top |
|
|
Weregoose Authentic INTJ
Super Elite (Last Title)
Joined: 25 Nov 2004 Posts: 3976
|
Posted: 03 Jan 2007 05:25:45 pm Post subject: |
|
|
nitacku wrote: I think there is an error in the OS because sometimes I get a domain error unless I do:
round(1+13fPart(Ans/13)). Somehow there is still invisible decimals being left on the number even though it will display a whole number. Yes, it stores fourteen places but displays only ten on the home screen. Speaking of which, you can output to the home screen without using [font="courier new;font-size:9pt;line-height:100%;color:darkblue"]Disp if it's the last line in the program.
Last edited by Guest on 03 Jan 2007 05:34:53 pm; edited 1 time in total |
|
Back to top |
|
|
luby I want to go back to Philmont!!
Calc Guru
Joined: 23 Apr 2006 Posts: 1477
|
Posted: 03 Jan 2007 05:29:21 pm Post subject: |
|
|
Recursive Acronym wrote: [Actually, that would be "int(11rand". I am suprised at how often people mix this up. [EDIT:] I am surprised at how often I misspell "surprised".
give the man the cookie. I believe the algorithm is [font="courier new;font-size:9pt;line-height:100%;color:darkblue"]int(rand*(high-low+1)+low) |
|
Back to top |
|
|
|
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