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
Harrierfalcon
The Raptor of Calcs


Super Elite (Last Title)


Joined: 25 Oct 2006
Posts: 2535

Posted: 16 Oct 2007 08:15:42 pm    Post subject:

One guess as to where I got this challenge.

If A<0, then return the number of occurrence of Ans in Str1.
If A>-1, then return the location of Xth occurrence in Str1 (The first occurrence is 0).

We're going for most compact, not for the fastest.

I haven't really scanned the teaser numbers thoroughly, so correct me if this isn't #33.

My solution stands at 73 bytes (With the usual measurement method):

[solution]
:If A<0
:Then
:sum(seq(1=inString(Str1,Str2,Z)-Z,Z,1,length(Str1
:Else
:Ans→Str2
:0
:For(B,0,X
:inString(Str1,Str2,Ans+1
:End
:End

[/solution]


Last edited by Guest on 10 Sep 2010 04:31:12 am; edited 1 time in total
Back to top
Weregoose
Authentic INTJ


Super Elite (Last Title)


Joined: 25 Nov 2004
Posts: 3976

Posted: 18 Oct 2007 02:43:47 am    Post subject:

It might be good practice to not post the solution along with the challenge—others might be deterred from working on their own versions if they see one that already works.

Anyway, I have a routine in 65 bytes:
Spoiler wrote:
seq(inString(Str1,Ans,X),X,1,length(Str1
Ansaugment({1},not(not([font="times new roman"]
List(Ans→X
sum(not(not(Ans
SortD(LX
If A≥0
LX(Ans-X
Ans


Last edited by Guest on 10 Sep 2010 04:30:40 am; 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: 18 Oct 2007 04:15:54 pm    Post subject:

I can get the first one in 11 bytes. I'm a little stuck on the second bit though
spoiler wrote:
Back to top
DarkerLine
ceci n'est pas une |


Super Elite (Last Title)


Joined: 04 Nov 2003
Posts: 8328

Posted: 18 Oct 2007 05:27:16 pm    Post subject:

I got it in 52 bytes:
Quote:
Ans→Str2
inString(Str1,Ans
While AnsA
DS<(A,A

inString(Str1,Str2,Ans+1
End
max(-1-A,Ans

It depends on A being exactly -1 in the first case, though. Unless you fix it (at a cost of 4 more bytes):
Quote:
Ans→Str2
A→B
inString(Str1,Str2
While AnsA
DS<(A,A

inString(Str1,Str2,Ans+1
End
max(B-A,Ans


Last edited by Guest on 18 Oct 2007 07:14:23 pm; 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