dbTalk Databases Forums  

BASIC programming challenge. Vowels and Consonants

comp.databases.pick comp.databases.pick


Discuss BASIC programming challenge. Vowels and Consonants in the comp.databases.pick forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Douglas Tatelman
 
Posts: n/a

Default BASIC programming challenge. Vowels and Consonants - 07-21-2010 , 05:03 PM






I figured I would interrupt all these messages about free money from
Paypal and cheap jeans from China.

I love the string manipulation you can do in Pick BASIC. One of my
clients is a magazine, and I often have some interesting assignments.

I'm writing a subroutine that you send a string and it will return a 1
if the string is all consonants or if it is all vowels. And a zero if
not.

There are probably a half dozen ways to do this, but I'm trying to
figure the neatest, quickest solution.

Any takers? The winner will get $2K from Paypal after confirmation of
their credit card number.

I'll report back with my code later.

Cheers

Douglas

Reply With Quote
  #2  
Old   
Ross Ferris
 
Posts: n/a

Default Re: BASIC programming challenge. Vowels and Consonants - 07-21-2010 , 05:33 PM






WHY?? Sounds like a useless routine exercise to me in a multi-cultural
world (eg: Asian name of AI, Eastern European of TSYLYNX)


SUBROUTINE USELESS(ASTRING,FLAG)
FLAG = 0
IF NOT(ASSIGNED(ASTRING)) THEN RETURN ;*
logic error in calling routine
IF ASTRING # OCONV(ASTRING,"MCA") THEN RETURN ;* get out if
non alpha characters
BSTRING = CONVERT "AEIOU" TO "" IN BSTRING
IF BSTRING = ASTRING
THEN ;* all constanants
FLAG = 1
END ELSE
IF BSTRING = ""
THEN ;* all
vowels
FLAG = 1
END
END
RETURN

Reply With Quote
  #3  
Old   
Douglas Tatelman
 
Posts: n/a

Default Re: BASIC programming challenge. Vowels and Consonants - 07-21-2010 , 06:13 PM



Actually I am properly casing names of horses! They all start in
uppercase, but will sometimes have things like MJR Myhorse - where MJR
are initials of the breeder.

I have a list of exceptions, but am also staring at the raw data and
trying to come up with rules.

Reply With Quote
  #4  
Old   
Douglas Tatelman
 
Posts: n/a

Default Re: BASIC programming challenge. Vowels and Consonants - 07-21-2010 , 06:15 PM



You (Ross) and Keith Johnson both came through with the use of the
multi character option of convert.

To be truthful, I had never seen a use for converting more than one
character at a time.

I like how we all assume that Y is not a vowel.

Reply With Quote
  #5  
Old   
Pickie
 
Posts: n/a

Default Re: BASIC programming challenge. Vowels and Consonants - 07-21-2010 , 06:23 PM



Here's my version of the program challenge from CDP. Six lines (ten
to fifteen) are the nub of the matter.

001: LOOP
002: INPUT STRING
003: UNTIL STRING EQ '' DO
004: GOSUB CHECK.STRING
005: CRT FLAG
006: REPEAT
007: STOP
008:
009: CHECK.STRING:
010: UC.STRING = UPCASE(STRING)
011: VOWELS =
LEN(CONVERT('BCDFGHJKLMNPQRSTUVWXYZ','',UC.STRING) )
012: CONSONANTS = LEN(CONVERT('AEIOU','',UC.STRING))
013: FLAG = @FALSE
014: IF VOWELS AND NOT(CONSONANTS) THEN FLAG = @TRUE
015: IF CONSONANTS AND NOT(VOWELS) THEN FLAG = @TRUE
016: RETURN

Lines eleven and twelve could convert a space as well if you wanted to
do multi-word strings.

Regards,

Keith Johnson

Reply With Quote
  #6  
Old   
Ross Ferris
 
Posts: n/a

Default Re: BASIC programming challenge. Vowels and Consonants - 07-21-2010 , 07:07 PM



On Jul 22, 9:15*am, Douglas Tatelman <doug... (AT) pickteam (DOT) com> wrote:
Quote:
You (Ross) and Keith Johnson both came through with the use of the
multi character option of convert.

To be truthful, I had never seen a use for converting more than one
character at a time.

I like how we all assume that Y is not a vowel.
Hmmmm .... horse names? Perhaps we should talk. We have a system that
is used by the Australia Stock Horse Society (bloodstock management
can be applied to any "breeding" situation, though DNA testing would
probably vary). Assume you are using Soundex for horse registrations?
(Bigger assumption I suppose is that this is a registration style
system you are talking about!) If so, you may also want to do some
reading on Metaphone if you don't do this already

Reply With Quote
  #7  
Old   
Douglas Tatelman
 
Posts: n/a

Default Re: BASIC programming challenge. Vowels and Consonants - 07-21-2010 , 09:59 PM



Hmmm, I'll get back to horse later.

How 'bout assuming that if it's not a vowel it is a consonant?

like this


* ASSUME UPPER CASE OR CASE INSENSITIVE
* ASSUME ALL ALPHA
EQU vowles to "E":@AM:"A":@AM"O":@AM:"I":@AM:"U":@AM:"Y" ;* in order
of frequency
WORD = "TEST"
GOSUB CHECK.VC
IF SAME THEN CRT "ALL VOWELS OR CONSONANTS" ELSE CRT "MIXED"
STOP
*
SAME = 1
NUM.VOWELS = 0 ; NUM.CONS = 0
DONE = 0 ; L = 1
LOOP UNTIL DONE DO
THIS.LETTER = WORD[D,1]
IF THIS.LETTER = "" THEN
DONE = 1
END ELSE
LOCATE(WORD[D,1],vowles;JUNK) THEN
IF NUM.CONS THEN SAME = 0 ; DONE = 1
NUM.VOWELS += 1
END ELSE
IF NUM.VOWELS THEN SAME = 0 ; DONE = 1
NUM.CONS += 1
END
END
L += 1
REPEAT
RETURN

Reply With Quote
  #8  
Old   
Douglas Tatelman
 
Posts: n/a

Default Re: BASIC programming challenge. Vowels and Consonants - 07-21-2010 , 10:34 PM



Please excuse the sloppiness in the above code...sort of just a napkin
sketch to show some thoughts.

Reply With Quote
  #9  
Old   
helios
 
Posts: n/a

Default Re: BASIC programming challenge. Vowels and Consonants - 07-22-2010 , 12:58 AM



001: LOOP
002: INPUT STRING
003: UNTIL STRING EQ '' DO
004: GOSUB CHECK.STRING
005: CRT FLAG
006: REPEAT
007: STOP
008: CHECK.STRING:
009: FLAG =
BITXOR(LEN(CONVERT('BCDFGHJKLMNPQRSTUVWXYZ','',UPC ASE(STRING)))>"",
LEN(CONVERT('AEIOU','',UPCASE(STRING)))>"")
010: RETURN

Reply With Quote
  #10  
Old   
Douglas Tatelman
 
Posts: n/a

Default Re: BASIC programming challenge. Vowels and Consonants - 07-22-2010 , 10:09 AM



Great line of code, I'll have to parse it out and learn something..
Again, I've never used the BITXOR. thanks

FLAG =
BITXOR(LEN(CONVERT('BCDFGHJKLMNPQRSTUVWXYZ','',UPC ASE(STRING)))>"", *
LEN(CONVERT('AEIOU','',UPCASE(STRING)))>"")

I know I'm going to open a can of worms when I test each approach on a
million items and time it.

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.