Login [Register]
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.

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


Member


Joined: 30 Nov 2007
Posts: 138

Posted: 19 May 2008 11:23:10 pm    Post subject:

Well, here's the rules: make the smallest program that returns the GCD of a set of positive integers. The input list is from either Ans or L1, and the output must be a number, not a list.

I've got it down to 46 but I know there must be a better solution.
Back to top
Weregoose
Authentic INTJ


Super Elite (Last Title)


Joined: 25 Nov 2004
Posts: 3976

Posted: 19 May 2008 11:48:21 pm    Post subject:

Sixteen bytes:
Spoiler wrote:
min(gcd(Ans,min(Ans


Last edited by Guest on 02 Aug 2010 02:04:14 am; edited 1 time in total
Back to top
Ed H


Member


Joined: 30 Nov 2007
Posts: 138

Posted: 19 May 2008 11:51:27 pm    Post subject:

Weregoose wrote:
Sixteen bytes:
Spoiler wrote:
min(gcd(Ans,min(Ans

Oh a, I was looking too much into the programming aspect and ignoring the math.


Last edited by Guest on 02 Aug 2010 02:04:34 am; 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: 20 May 2008 11:12:24 am    Post subject:

Weregoose wrote:
Sixteen bytes:
Spoiler wrote:
min(gcd(Ans,min(Ans

[post="123859"]<{POST_SNAPBACK}>[/post]

That doesn't work: try that on {6,10,15}. The GCD should be 1, but your code returns 2.

Instead, this works (25 bytes):
Spoiler wrote:
While stdDev(Ans
gcd(Ans,min(Ans
End
min(Ans


It's by no means the fastest, though, but GCD is thankfully a fairly fast operation, so even doing it O(n2) times is not a problem. Also, it doesn't work for 1-element lists. Anyway, the next routine, only at 34 bytes, should be close to optimal in the number of times it calls GCD as well:
Spoiler wrote:
min(L1
For(I,1,dim(L1
gcd(Ans,L1(I
End
Ans


Last edited by Guest on 02 Aug 2010 02:03:58 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 GMT - 5 Hours

 

Advertisement