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.

This forum is locked: you cannot post, reply to, or edit topics. TI-Basic Brain Teasers => TI-BASIC
Author Message
calc84maniac


Elite


Joined: 22 Jan 2007
Posts: 770

Posted: 01 May 2007 06:26:22 pm    Post subject:

Make a 61 byte (or less) program whose input is a decimal number in Ans and the output is {Numerator,Denominator} IN SIMPLIFIED FORM. Get a bonus for using no variables other than Ans. (I didn't.)
Back to top
justusdude


Advanced Member


Joined: 24 May 2006
Posts: 265

Posted: 01 May 2007 07:51:23 pm    Post subject:

Quote:
Make a 61 byte (or less) program whose input is a decimal number in Ans and the output is {Numerator,Denominator} IN SIMPLIFIED FORM. Get a bonus for using no variables other than Ans. (I didn't.)


I got 15 bytes
How do you make the text invisible? I don't want to spoil it.

[EDIT]
I used the Frac function. Is that cheating?


Last edited by Guest on 01 May 2007 08:03:12 pm; edited 1 time in total
Back to top
stlcards08


Newbie


Joined: 04 Mar 2007
Posts: 35

Posted: 01 May 2007 07:57:19 pm    Post subject:

calc84maniac wrote:
Make a 61 byte (or less) program whose input is a decimal number in Ans and the output is {Numerator,Denominator} IN SIMPLIFIED FORM. Get a bonus for using no variables other than Ans. (I didn't.)
[post="102531"]<{POST_SNAPBACK}>[/post]

You want this to be user inputed decimal? If so, I thought it was impossible to get a user input stored to Ans without using another variable.
Back to top
calc84maniac


Elite


Joined: 22 Jan 2007
Posts: 770

Posted: 01 May 2007 08:10:53 pm    Post subject:

Just type in the number on the homescreen then run the program. And the output should be a two element list {N,D}.
Back to top
Weregoose
Authentic INTJ


Super Elite (Last Title)


Joined: 25 Nov 2004
Posts: 3976

Posted: 01 May 2007 08:32:22 pm    Post subject:

justusdude wrote:
How do you make the text invisible? I don't want to spoil it.
[­quote=Spoiler][­color=white]text[­/color][­/quote]

justusdude wrote:
I used the Frac function. Is that cheating?
Well, it doesn't output as a list, now, does it? :P

I think one can find the answer to this teaser sitting elsewhere in the forum. Rolling Eyes


Last edited by Guest on 01 May 2007 08:32:59 pm; edited 1 time in total
Back to top
stlcards08


Newbie


Joined: 04 Mar 2007
Posts: 35

Posted: 01 May 2007 09:08:20 pm    Post subject:

I got 31 bytes, but it uses 2 other variables.
Spoiler wrote:
Repeat fPart(AnsB)=0
Ans+1->A
End
{AnsB,Ans

I'm not clever enough to do it without a variable besides Ans


Last edited by Guest on 01 May 2007 09:12:43 pm; edited 1 time in total
Back to top
nitacku


Advanced Member


Joined: 23 Aug 2005
Posts: 408

Posted: 01 May 2007 09:54:04 pm    Post subject:

55 bytes, but I haven't come up with a way to do it without variables yet.
Spoiler wrote:
Ans->A
DelVar BRepeat A=B/C
B+1->B
Repeat A>=B/C
C+1->C
End
End
{B,C
EDIT: This will only work as long as the decimal is less than 1, but it will theoretically work for fractions up to infinity Wink It doesn't like repeating decimals like 1/3 though

EDIT2: slight optimization, removed 2 bytes


Last edited by Guest on 01 May 2007 10:18:43 pm; edited 1 time in total
Back to top
Weregoose
Authentic INTJ


Super Elite (Last Title)


Joined: 25 Nov 2004
Posts: 3976

Posted: 01 May 2007 10:03:00 pm    Post subject:

nitacku wrote:
I haven't come up with a way to do it without variables yet.
I haven't yet, either...

I have a program in [s]29[/s] 44 bytes, but it takes longer the larger the denominator:
Spoiler wrote:
[font="courier new;font-size:9pt;line-height:100%;color:darkblue"]For(X,1,E9
If fPart(XAns
End
{XAns,X
Ans/gcd(abs(Ans(1)),Ans(2

[EDIT]

It should now meet the simplified form requirement.


Last edited by Guest on 04 May 2007 11:00:56 am; edited 1 time in total
Back to top
calc84maniac


Elite


Joined: 22 Jan 2007
Posts: 770

Posted: 02 May 2007 09:19:15 am    Post subject:

I forgot to mention it should handle repeating decimals (such as 1/7) and ANY fraction (greater than 1, less than 1, or even negative.)
Back to top
stlcards08


Newbie


Joined: 04 Mar 2007
Posts: 35

Posted: 02 May 2007 04:41:10 pm    Post subject:

I've got mine at 29 bytes, and only one variable. However, it won't handle repeating decimals. It does do negative, >1 and <1 decimals

Last edited by Guest on 02 May 2007 04:42:29 pm; edited 1 time in total
Back to top
DarkerLine
ceci n'est pas une |


Super Elite (Last Title)


Joined: 04 Nov 2003
Posts: 8328

Posted: 02 May 2007 05:06:59 pm    Post subject:

It's clear that for some high denominator, all programs stop working, though how high it has to be varies. However, no one really cares about really large denominators, and learning that your fraction is really 911/113 won't make you happier or your calculations easier.
I therefore nominate the following routine, which is faster than almost any other, and uses no variables to accomplish its task:
int(367567200{Ans,1
Ans/gcd(Ans(2),abs(Ans(1


Last edited by Guest on 02 May 2007 07:41:29 pm; edited 1 time in total
Back to top
nitacku


Advanced Member


Joined: 23 Aug 2005
Posts: 408

Posted: 02 May 2007 06:59:24 pm    Post subject:

Hmm, I'm guessing that the constant is created by multiplying prime numbers... Ingenious!
Back to top
Weregoose
Authentic INTJ


Super Elite (Last Title)


Joined: 25 Nov 2004
Posts: 3976

Posted: 02 May 2007 11:12:44 pm    Post subject:

Well, somewhat: 367567200 = 25·33·52·7·11·13·17

[EDIT]

However, if you take the lowest common multiple of the first n nonprime numbers: Click

That would make more sense. Smile


Last edited by Guest on 03 May 2007 07:59:01 am; edited 1 time in total
Back to top
trigkid213


Member


Joined: 30 Mar 2006
Posts: 208

Posted: 03 May 2007 06:46:30 am    Post subject:

Sheesh, I've been busy. I thought I had Goose's solution for the reverse continued fraction teaser last night, but I just saw his solution and it's different. However, mine's also 50 bytes:
Spoiler wrote:
[font="courier new;font-size:9pt;line-height:100%;color:darkblue"]
augment({1},Ans->X
For(X,3,dim(LX
{Ans(2),Ans(1)+Ans(2)LX(X
End
Ans
Back to top
DarkerLine
ceci n'est pas une |


Super Elite (Last Title)


Joined: 04 Nov 2003
Posts: 8328

Posted: 03 May 2007 03:22:29 pm    Post subject:

That's the one I got (you can see it in some post on the other page). Make it [font="courier new;font-size:9pt;line-height:100%;color:darkblue"]dim(Ans though, that's one byte smaller.

Regarding the constant I chose: I don't really have any justification for choosing it over another. It has lots of factors and works well, and any good constant has to have lots of factors, but I have no clue if it's the best, or even how to judge what the best constant is.
Back to top
trigkid213


Member


Joined: 30 Mar 2006
Posts: 208

Posted: 03 May 2007 07:03:08 pm    Post subject:

Oh, I didn't see your post. [font="courier new;font-size:9pt;line-height:100%;color:darkblue"]dim(Ans doesn't work though - it equals 2 after the first iteration of the For loop.
Back to top
DarkerLine
ceci n'est pas une |


Super Elite (Last Title)


Joined: 04 Nov 2003
Posts: 8328

Posted: 03 May 2007 07:08:04 pm    Post subject:

That doesn't matter anymore - the For( loop evaluates the arguments once and never changes them, unlike a C++ for loop.
Back to top
trigkid213


Member


Joined: 30 Mar 2006
Posts: 208

Posted: 03 May 2007 07:38:12 pm    Post subject:

Wow, learn a little C++ and lose your TI-Basic. :hmpf:
Back to top
adriweb


Newbie


Joined: 28 Aug 2007
Posts: 22

Posted: 16 Oct 2007 06:30:16 am    Post subject:

"lose Ti-Basic" nooo, never !


@weregoose :
Well, somewhat: 367567200 = 25·33·52·7·11·13·17

:)))
Back to top
Weregoose
Authentic INTJ


Super Elite (Last Title)


Joined: 25 Nov 2004
Posts: 3976

Posted: 16 Oct 2007 06:58:54 am    Post subject:

adriweb wrote:
"lose Ti-Basic" nooo, never !


@weregoose :
Well, somewhat: 367567200 = 25·33·52·7·11·13·17

:)))
Please... Don't post to topics that haven't been posted to for five months! Not unless you have something extra useful for us. Basically, try to contribute something more than what's just off the top of your head. Above all, you're welcome here at United-TI, but we anticipate a little more than "ooh nice" comments or whatever else feels like the blubbering underneath a YouTube video. Make your posts matter!

By the way, you didn't preview your post long enough – the superscripts fell out of the factorization, making the statement false. I'm also not sure why you pasted that... Explain, please?


Last edited by Guest on 16 Oct 2007 07:05:29 am; edited 1 time in total
Back to top
Display posts from previous:   
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
    »
» View previous topic :: View next topic  
Page 1 of 1 » All times are UTC - 5 Hours

 

Advertisement