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
hotdog1234


Advanced Member


Joined: 14 Aug 2009
Posts: 291

Posted: 04 Jan 2010 11:48:24 am    Post subject:

What is the most optimized program that will count ALL instances of a string inside a string? (You can go for either size or speed) For instance, "ABCDAEGAALEKSAA" has the string "AA" 2 times.

Last edited by Guest on 04 Jan 2010 11:54:33 am; edited 1 time in total
Back to top
GloryMXE7
Puzzleman 3000


Active Member


Joined: 02 Nov 2008
Posts: 604

Posted: 04 Jan 2010 04:00:44 pm    Post subject:

i got a program of a size 88 assuming the outer string and inside string were defined outside the program
Back to top
calc84maniac


Elite


Joined: 22 Jan 2007
Posts: 770

Posted: 04 Jan 2010 04:11:29 pm    Post subject:

46 bytes, assuming the strings are in Str1 and Str2.
Back to top
calcdude84se


Member


Joined: 09 Aug 2009
Posts: 207

Posted: 04 Jan 2010 04:57:11 pm    Post subject:

In the string "BAAAC", would "AA" be counted twice? (that is, should we count overlaps?)
Back to top
Ed H


Member


Joined: 30 Nov 2007
Posts: 138

Posted: 04 Jan 2010 05:11:22 pm    Post subject:

It seems there are a lot of approaches to this puzzle that are all effective. I've found two different methods that take 40 and 41 bytes.

Last edited by Guest on 04 Jan 2010 05:15:43 pm; edited 1 time in total
Back to top
Weregoose
Authentic INTJ


Super Elite (Last Title)


Joined: 25 Nov 2004
Posts: 3976

Posted: 04 Jan 2010 05:12:22 pm    Post subject:

40, then 37 with a one-time memory leak.
Back to top
hotdog1234


Advanced Member


Joined: 14 Aug 2009
Posts: 291

Posted: 04 Jan 2010 05:36:21 pm    Post subject:

calcdude84se wrote:
In the string "BAAAC", would "AA" be counted twice? (that is, should we count overlaps?)


Yes.
Back to top
calc84maniac


Elite


Joined: 22 Jan 2007
Posts: 770

Posted: 04 Jan 2010 06:13:25 pm    Post subject:

I got 37 now also, with no memory leak (but at the cost of speed)

Edit:
Now I have 32.


Last edited by Guest on 04 Jan 2010 06:16:05 pm; edited 1 time in total
Back to top
GloryMXE7
Puzzleman 3000


Active Member


Joined: 02 Nov 2008
Posts: 604

Posted: 04 Jan 2010 10:07:14 pm    Post subject:

what are you guys doing that I'm not getting
Back to top
Weregoose
Authentic INTJ


Super Elite (Last Title)


Joined: 25 Nov 2004
Posts: 3976

Posted: 05 Jan 2010 12:46:56 am    Post subject:

If you're really that stuck on coming up with a good algorithm, here is a basic one of 48 bytes:

Spoiler wrote:
0→A:0→B
Repeat A=0
inString(Str1,Str2,A+1)→A
B+1→B
End
Ans-1

I now have a 34-byte program (using a different approach than the one given above), and it becomes 32 if the main string is in Ans.


Last edited by Guest on 01 Jul 2010 09:56:46 am; edited 1 time in total
Back to top
calc84maniac


Elite


Joined: 22 Jan 2007
Posts: 770

Posted: 05 Jan 2010 09:28:32 am    Post subject:

Ah yes, if the main string is in Ans, mine becomes 30 Smile
Back to top
hotdog1234


Advanced Member


Joined: 14 Aug 2009
Posts: 291

Posted: 05 Jan 2010 11:31:20 am    Post subject:

Opps, I forgot that instring( could look in various starting locations
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