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
nitacku


Advanced Member


Joined: 23 Aug 2005
Posts: 408

Posted: 23 Mar 2008 07:22:42 pm    Post subject:

Given a list of random length in Ans, create a routine that will return 0 if the list has no duplicate elements, or if in the case that duplicate elements are found, return the value of the duplicate element nearest to the beginning of the list.

For you gurus out there, construct the entire routine without storing to a list.

Things to keep in mind:
The routine must work on any size list.
The routine must work on lists containing negative values and decimal values.

Here's an example of what is expected:
1.) {4, 5.7, 8.2, 11.56, -33.9, 16.45, 0, 23, 16.45, 99 is stored in Ans
2.) the routine is executed
3.) 6 is returned in Ans because element 6 is the first duplicate value from the beginning of the list

The goal to shoot for is 35 bytes (after the length of the title is subtracted from the size of the program)
Back to top
Zaphod Beeblebrox


Member


Joined: 02 Jul 2007
Posts: 119

Posted: 23 Mar 2008 08:10:06 pm    Post subject:

I assume the list has no imaginary numbers?
Back to top
nitacku


Advanced Member


Joined: 23 Aug 2005
Posts: 408

Posted: 23 Mar 2008 08:17:38 pm    Post subject:

Actually I didn't think of imaginary numbers, but consider it a bonus if your routine can handle those as well.
Back to top
Zaphod Beeblebrox


Member


Joined: 02 Jul 2007
Posts: 119

Posted: 23 Mar 2008 08:33:47 pm    Post subject:

How do you do a spoiler?

[color=#000000background#000000] -- [/color] doesn't seem to work.


Last edited by Guest on 23 Mar 2008 08:35:10 pm; edited 1 time in total
Back to top
nitacku


Advanced Member


Joined: 23 Aug 2005
Posts: 408

Posted: 23 Mar 2008 08:36:11 pm    Post subject:

make the text color white and put it all in a quote box
Back to top
Zaphod Beeblebrox


Member


Joined: 02 Jul 2007
Posts: 119

Posted: 23 Mar 2008 08:42:49 pm    Post subject:

I told this to my brother. He did it in about 41 bytes and then I optimized it down to 30. And it doesn't store to a list.

Quote:
:For(X,1,dim(Ans
:If 1<sum(not(Ans-Ans(X
:Then
:X
:Stop
:End
:End
:0


Last edited by Guest on 23 Mar 2008 08:44:46 pm; edited 1 time in total
Back to top
nitacku


Advanced Member


Joined: 23 Aug 2005
Posts: 408

Posted: 23 Mar 2008 08:46:50 pm    Post subject:

Nice! Although yours is at 39 bytes, but definitely a job well done.
Back to top
Zaphod Beeblebrox


Member


Joined: 02 Jul 2007
Posts: 119

Posted: 23 Mar 2008 08:48:06 pm    Post subject:

Thanks, but It's 30 bytes in actual code. Those 9 bytes are just for the creation of the program.
Back to top
nitacku


Advanced Member


Joined: 23 Aug 2005
Posts: 408

Posted: 23 Mar 2008 08:50:39 pm    Post subject:

Using that method to measure the size of the program, mine would be at 26 bytes.
Back to top
Weregoose
Authentic INTJ


Super Elite (Last Title)


Joined: 25 Nov 2004
Posts: 3976

Posted: 23 Mar 2008 11:49:18 pm    Post subject:

Spoiler wrote:
For(X,1,dim(Ans
If 1=sum(Ans=Ans(X
End
X(X<dim(Ans


Last edited by Guest on 02 Aug 2010 02:53:50 am; edited 1 time in total
Back to top
nitacku


Advanced Member


Joined: 23 Aug 2005
Posts: 408

Posted: 24 Mar 2008 11:34:05 am    Post subject:

I tied with Weregoose! Very Happy
Needless to say, I came up with the exact same thing.
I feel special now Laughing
Back to top
DarkerLine
ceci n'est pas une |


Super Elite (Last Title)


Joined: 04 Nov 2003
Posts: 8328

Posted: 24 Mar 2008 11:38:41 am    Post subject:

A tiny optimization:
Quote:
For(X,1,dim(Ans
If log(sum(Ans=Ans(X
End
X(X<dim(Ans


Edit: darn, that doesn't work, it gives the exact opposite answer. Erm, give me a moment.


Last edited by Guest on 24 Mar 2008 01:30:38 pm; edited 1 time in total
Back to top
TheStorm


Calc Guru


Joined: 17 Apr 2007
Posts: 1233

Posted: 24 Mar 2008 04:35:59 pm    Post subject:

ok my routine outputs the value in x but if a few bytes smaller and can only be used as a subprogram.
Quote:
For(X,1,dim(Ans
If log(sum(Ans=Ans(X
Return
End
0
Back to top
calc84maniac


Elite


Joined: 22 Jan 2007
Posts: 770

Posted: 24 Mar 2008 10:06:03 pm    Post subject:

TheStorm: Yours only outputs it in X if there are duplicate values, otherwise 0 in Ans. Razz
Back to top
TheStorm


Calc Guru


Joined: 17 Apr 2007
Posts: 1233

Posted: 24 Mar 2008 10:52:09 pm    Post subject:

oh yeah opps I should fix that.
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