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
ztrumpet


Active Member


Joined: 06 May 2009
Posts: 555

Posted: 06 May 2009 03:30:16 pm    Post subject:

Make the smallest program you can that asks for a string, replaces all the vowels (A, E, I, O, and U) with an asterisk (*), and displays the finished string (Can be in Ans).
Mine is 103 in the Memory Management Menu with a one character name.
Back to top
Graphmastur


Advanced Member


Joined: 25 Mar 2009
Posts: 360

Posted: 06 May 2009 07:25:01 pm    Post subject:

You could do:


Code:
input "Str num:",A
":"+Expr(sub("Str0Str1Str2Str3Str4Str5Str6Str7Str8Str9",A-1,1)+":"
For(A,1,length(ans))
IF InString("AEIOU",sub(ans,A,1))≠0
sub(ans,1,A-1)+"*"+sub(ans,A+1,length(ans))
End
sub(ans,2,length(ans)-2)
Back to top
ztrumpet


Active Member


Joined: 06 May 2009
Posts: 555

Posted: 06 May 2009 07:28:52 pm    Post subject:

Instead of:

input "Str num:",A
":"+Expr(sub("Str0Str1Str2Str3Str4Str5Str6Str7Str8Str9",A-1,1)+":"

I just ment:
Input Str1

I could have been more clear

Cool code though...

edit:
Your code dosn't even work :\
IF InString("AEIOU",sub(ans,A,1))≠0
This would return if the string "AEIOU" was in the string
sub(ans,1,A-1)+"*"+sub(ans,A+1,length(ans))
This dosn't work if a vowel is in the first or last spot


Last edited by Guest on 06 May 2009 07:34:38 pm; edited 1 time in total
Back to top
ticalcnoah


Member


Joined: 28 Oct 2007
Posts: 153

Posted: 06 May 2009 07:33:13 pm    Post subject:

Already been done http://www.unitedti.org/index.php?showtopic=8551 could be easily modified to meet your challenge.
Back to top
ztrumpet


Active Member


Joined: 06 May 2009
Posts: 555

Posted: 06 May 2009 07:35:40 pm    Post subject:

I thought this was different.
That deals with taking out non-letters and this deals with replacing vowels.

Can anyone do better than 103 bytes? edit: 89

Mine (old solution) is:
spoiler
[whiteout]Input Str1
" ->Str2 /1 space
For(A,1,length(Str1
sub(Str1,A,1
If Ans="A" or Ans="E" or Ans="I" or Ans="O" or Ans="U
Then
Str2+"*
Else
Str2+Ans
End
Ans->Str2
End
sub(Ans,2,length(Str1[/whiteout]
/spoiler


Last edited by Guest on 12 Jul 2010 01:13:40 am; edited 1 time in total
Back to top
bfr


Member


Joined: 13 Feb 2006
Posts: 108

Posted: 07 May 2009 10:53:43 pm    Post subject:

"Can anyone do better than 103 bytes?" I'm guessing others like Weregoose, DarkerLine, many of the frequenters of the TI-BASIC board etc. probably could but don't feel like it :P

Quote:
IF InString("AEIOU",sub(ans,A,1))≠0
This would return if the string "AEIOU" was in the string"

I think the condition would evaluate as true if a character in the prompted string (given by sub(ans,A,1)) is inside "AEIOU", which is what is wanted

Anyway, I made one and it's 74 bytes, or 75 bytes if you include the one-character name

And welcome to UnitedTI, by the way Smile
Back to top
ztrumpet


Active Member


Joined: 06 May 2009
Posts: 555

Posted: 10 May 2009 06:36:42 pm    Post subject:

bfr wrote:
Quote:
IF InString("AEIOU",sub(ans,A,1))≠0
This would return if the string "AEIOU" was in the string"

I think the condition would evaluate as true if a character in the prompted string (given by sub(ans,A,1)) is inside "AEIOU", which is what is wanted

Edit- False: No, it would (I'm 100% sure- I just tested) evaluate for the string "AEIOU". Since the one letter given by the sub( is one character long and "AEIOU" is 5 characters long it will always be false.


Thank's for the welcome!
How did you get it in the 70s; I got it down to 89 (one letter name so code is 79).
I want to see your code.

My code:

Code:
Input Str1
"+
For(A,1,length(Str1
Ans+sub(Str1,A,1
For(B,1,5
If inString(Ans,sub"AEIOU",B,1
sub(Ans,1,A)+"*
End
End
sub(Ans,2,A-1


Last edited by Guest on 10 May 2009 07:08:37 pm; edited 1 time in total
Back to top
bfr


Member


Joined: 13 Feb 2006
Posts: 108

Posted: 10 May 2009 06:50:12 pm    Post subject:

"No, it would (I'm 99% sure) evaluate for the string "AEIOU". Since the one letter given by the sub( is one character long and "AEIOU" is 5 characters long it will always be false." I think you're thinking of inString(sub(ans,A,1),"AEIOU"). Note that the syntax is inString(string,substring that is looked for in the string,(optional parameter for where to start) , as you correctly did in your code, so by doing InString("AEIOU",sub(ans,A,1)), it looks to see if the current character is inside a string of vowels, which consequently tests to see if it is a vowel. For example, you can try entering InString("AEIOU","A" on the homescreen, and it'll return 1.

My code (highlight to view):
Quote:

Prompt Str1
" ->Str2
For(A,1,length(Str1
sub(Str1,A,1
If inString("AEIOU",Ans
"*
Str2+Ans->Str2
End
sub(Ans,2,A-1



EDIT: I changed the last line of my code because it turns out what you did saves a byte Razz

Last edited by Guest on 10 May 2009 06:58:42 pm; edited 1 time in total
Back to top
ztrumpet


Active Member


Joined: 06 May 2009
Posts: 555

Posted: 10 May 2009 06:59:21 pm    Post subject:

I got pwned!
That's amazing
I didn't know you could use inString like that (reversed from how I've used it)- You're right
That's cool!
Wow... 74 bytes

edit:
I optimized yours to 73 bytes!

Code:
Input Str1
"+
For(A,1,length(Str1
Ans->Str2
sub(Str1,A,1
If inString("AEIOU",Ans
"*
Str2+Ans
End
sub(Ans,2,A-1


I wonder if it's possible to do it in under 73 bytes...


Last edited by Guest on 12 May 2009 08:09:50 pm; edited 1 time in total
Back to top
ztrumpet


Active Member


Joined: 06 May 2009
Posts: 555

Posted: 12 May 2009 08:09:33 pm    Post subject:

I think 73 bytes is as good as it's going to get.
Great job bfr!

If anyone can beat 73 bytes, feel free to post.
Back to top
Weregoose
Authentic INTJ


Super Elite (Last Title)


Joined: 25 Nov 2004
Posts: 3976

Posted: 12 May 2009 09:50:14 pm    Post subject:

To purvey a little trick that DarkerLine had used in another challenge:

Input Str1
For(A,1,length(Str1
sub(Str1,A,1
If inString("AEIOU",Ans
"*
Str1+Ans→Str1
End
sub(Ans,A,A-1

Five bytes less.


Last edited by Guest on 11 Jul 2010 05:37:23 pm; edited 1 time in total
Back to top
ztrumpet


Active Member


Joined: 06 May 2009
Posts: 555

Posted: 13 May 2009 08:17:59 am    Post subject:

No way!

That's awesome!

Again, I wonder if this is unbeatable.


Last edited by Guest on 13 May 2009 02:57:24 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 GMT - 5 Hours

 

Advertisement