LEN trouble

Talk freely about the scene, the world of remixing, or anything off-topic unsuitable for the "Fun Forum".
Post Reply
User avatar
Commie_User
Forum God
Forum God
Posts: 1486
Joined: 14/07/2009 - 23:34
Location: England
Contact:

LEN trouble

Post by Commie_User »

I'm having a hell of a time with this bit of string.

What I'm trying to do is change letters in a word, randomly swapping consonents for consonents and vowels for vowels. Here's the BASIC idea:

10 INPUT A$ (for example, BEER)
20 FOR B=1 TO 3 (number of times to change all the letters in one the original word, giving 3 mixups)
30 FOR C=1 TO LEN(A$) (Starts the letter-change cycle from the start of the word to the end)
40 LET X=INT(RND(90)) : IF X<65 THEN 40
(Random number stored in X between 65 and 90, the capitalised alphabet ASCII numbers. Note the statement is a little different as its the BBC Micro convention)
50 < AREA I'M STUCK ON >
60 PRINT CHR$(X);
70 NEXT C
75 PRINT
80 NEXT B
90 END

Now I've got the subroutine down for swapping a vowel only with another vowel. I know about counting into the A$ variable and returning the letters asked for (MID$, etc.). But what I want to do is isolate individual letters in A$ and play with the ASCII number. MID$ and the others only let me return a sequence of letters which is no good.

So, for the second letter of BEER, I want the computer to pick out the ASCII number and send it to the vowel-changer subroutine, whilst B and R are changed for other consonants. Line 50 should be where if the program detects an number which is ASCII for a vowel, it changes the value of X so I can have another vowel. Unchanged from the original randomised, it could be anything.
User avatar
analoq
Forum Loony
Forum Loony
Posts: 110
Joined: 28/03/2005 - 19:35
Location: The O.C.
Contact:

Re: LEN trouble

Post by analoq »

I don't know Commodore BASIC, so I did a little research. If I understand what you're trying to accomplish I think section A.2 answers your question here:
http://www.commodore.ca/manuals/pdfs/Co ... Manual.pdf

I'd have copy-pasted it but the PDF is encrypted and won't let me :x
But effectively you have to make use of the LEFT and MID functions and reassign the string.

cheers.
Chris Abbott
Forum God
Forum God
Posts: 5307
Joined: 22/11/2002 - 12:21
Location: Dubai. No, not really.
Contact:

Re: LEN trouble

Post by Chris Abbott »

ASC is the analog of CHR$ isn't it? So you'd have pass the right MID$ character into ASC.
Won't somebody PLEASE think of the children?
User avatar
Commie_User
Forum God
Forum God
Posts: 1486
Joined: 14/07/2009 - 23:34
Location: England
Contact:

Re: LEN trouble

Post by Commie_User »

Phew, I've done it now.

It's still in its rough form, but here's the repaired section of the program:


1285 FOR B=1 TO M
1290 PRINT TAB(5);
1300 FOR C=1 TO LEN(W$)
1301 LET Z=INT(RND(90))
1302 IF Z<65 THEN 1301
1310 LET D=ASC(MID$(W$,C,1))
1350 IF D=65 THEN GOSUB1480
1360 IF D=69 THEN GOSUB 1480
1370 IF D=73 THEN GOSUB 1480
1380 IF D=79 THEN GOSUB 1480
1390 IF D=85 THEN GOSUB 1480
1395
1396
1400 PRINT CHR$(Z);
1430 NEXT C
1440 PRINT
1450 NEXT B
1460 PRINT
1470 PRINT "Another run of words mate? (Y/N)"


I say repaired because I've been trying to follow a type-in listing excercise from the early 80s which doesn't work. Yes, I know I should expect that but I'm a fool to myself. The key is line 1310, which was right in the book but the original exercise screwed up what the program should have done with each number in the string. I then went out to check if that line actually worked in my BASIC. It also neglected to mention that the input string should be capitalised.

Still, all done now and thanks to those who tried to help.
Last edited by Commie_User on 08/09/2010 - 21:37, edited 1 time in total.
User avatar
beyond
Forum God
Forum God
Posts: 1312
Joined: 22/11/2002 - 19:57
Location: 2nd star to the left
Contact:

Re: LEN trouble

Post by beyond »

From the top of my head I would do something like this:

Code: Select all

10 v$="AEIOUY"
20 c$="BCDFGHJKLMNPQRSTVWXZ"
30 print"word"; input a$
40 print"reps"; input n
50 for k=1 to n
60 for i=1 to len(a$)
70 j=asc(mid$(a$,i,1)
80 w=0 : if j=65 or j=69 or j=73 or j=79 or j=85 then w=1
90 if w=0 then r$=mid$(c$,1+int(rnd(0)*len(c$)),1)
100 if w=1 then r$=mid$(v$,1+int(rnd(0)*len(v$)),1)
110 print r$;
120 next : print : next
Basically, it's "find out if the next character in the string is a vowel or not. Then pick a random character from the vowels or consonants based on that."

Might work, might not... there is most likely an off by one error in that rnd, can't remember if RND(0) returns [0...1] or [0...1[
User avatar
Commie_User
Forum God
Forum God
Posts: 1486
Joined: 14/07/2009 - 23:34
Location: England
Contact:

Re: LEN trouble

Post by Commie_User »

Thanks.

After re-typing your program, because my interpreter doesn't accept lowercase letters (?), I got this:

word? DELAYED
reps? 3
NNNNN
NNNNN
NNNNN


10 V$="AEIOUY"
20 C$="BCDFGHJKLMNPQRSTVWXZ"
30 PRINT "word"; : INPUT A$
40 PRINT "reps"; : INPUT N
50 FOR K=1 TO N
60 FOR I=1 TO LEN(A$)
70 J=ASC(MID$(A$,I,1))
80 W=0 : IF J=65 OR J=69 OR J=73 OR J=79 OR J=85 THEN W=1
90 IF W=0 THEN R$=MID$(C$,1+INT(RND(0)*LEN(C$)),1)
100 IF W=1 THEN R$=MID$(V$,1+INT(RND(0)*LEN(C$)),1)
110 PRINT R$;
120 NEXT : PRINT : NEXT


Still, never mind. The proggy's all done anyway and in a nice Windows-compatible form. I'll link to it once it's all safe and tucked up online.
User avatar
beyond
Forum God
Forum God
Posts: 1312
Joined: 22/11/2002 - 19:57
Location: 2nd star to the left
Contact:

Re: LEN trouble

Post by beyond »

Your line 100 has a reference to c$ where it should be v$.

If you're not running it in Commodore Basic, then you probably need to seed the RND function by calling something like RANDOMIZE, but then again RND-functions do behave quite differently depending on what kind of basic you're running.
User avatar
Commie_User
Forum God
Forum God
Posts: 1486
Joined: 14/07/2009 - 23:34
Location: England
Contact:

Re: LEN trouble

Post by Commie_User »

100 IF W=1 THEN R$=MID$(V$,1+INT(RND(0)*LEN(V$)),1)

RUNNING ON BBC:

word? VISIT
reps? 3
ROROR
ROROR
ROROR

word? KIPLING
reps? 3
TUTTUIT
TUTTUIT
TUTTUIT


RUNNING ON COMMODORE:

word? LIPS
reps? 3
FODD
SOKP
HUXC
ROHM

Lovely stuff. Though I wonder why the words aren't re-made for each cycle on the BBC. There's no Randomise function and mine worked alright.
User avatar
beyond
Forum God
Forum God
Posts: 1312
Joined: 22/11/2002 - 19:57
Location: 2nd star to the left
Contact:

Re: LEN trouble

Post by beyond »

Got this from the BBC BASIC ref manual:

RND
A function which returns a random number. The type and range of the number returned depends upon the optional parameter.

RND returns a random integer 0 - &FFFFFFFF.
RND(n) returns an integer in the range 1 to n (n>1).
RND(1) returns a real number in the range 0.0 to .99999999.

If n is negative the pseudo random sequence generator is set to a number based on n and n is returned.

If n is 0 the last random number is returned in RND(1) format.

X=RND(1)
X%=RND
N=RND(6)

-- so replace RND(0) with RND(1) and then you should be all good... or even better:

Code: Select all

90 IF W=0 THEN R$=MID$(C$,RND(LEN(C$)),1) 
and line 100 the same way...
User avatar
Commie_User
Forum God
Forum God
Posts: 1486
Joined: 14/07/2009 - 23:34
Location: England
Contact:

Re: LEN trouble

Post by Commie_User »

Eee, how splendid! Thanks very much.

10 V$="AEIOU"
20 C$="BCDFGHJKLMNPQRSTVWXYZ"
30 PRINT "word"; : INPUT A$
40 PRINT "reps"; : INPUT N
50 FOR K=1 TO N
60 FOR I=1 TO LEN(A$)
70 J=ASC(MID$(A$,I,1))
80 W=0 : IF J=65 OR J=69 OR J=73 OR J=79 OR J=85 THEN W=1
90 IF W=0 THEN R$=MID$(C$,1+INT(RND(1)*LEN(C$)),1)
100 IF W=1 THEN R$=MID$(V$,1+INT(RND(1)*LEN(V$)),1)
110 PRINT R$;
120 NEXT : PRINT : NEXT


RUN
word? BUMS
rep? 3
FAHW
GOTL
XEHL


That's a treat is that! Though I still like my one better because it can swap consonants for other vowels too if it wants.


And no more talking about it, here it is: http://www.dustybin.org.uk/Red_Arsery.zip . I politicised it as part of the project, so ignore the satire if you please.

And here's the video to go with it (because proper session recordings were made of the game's music): http://www.youtube.com/watch?v=E0CgRKX0gcc .

Other music from the same sessions: http://www.youtube.com/watch?v=N3y1PjGRjVU ,
http://www.youtube.com/watch?v=xvN2ZpUBNUs .

_______________________________________________

And as a side thought, coming off the back of that, wouldn't it have been nice had game publishers truly realised the popularity of computer music in the 80s? Just imagine Rob Hubbard going to some of the small studios dotted 'round London to record proper rock or electro' versions of some of his best selling C64 tracks. Proper contemporary sounds from the synths and rock bands of the time....
User avatar
beyond
Forum God
Forum God
Posts: 1312
Joined: 22/11/2002 - 19:57
Location: 2nd star to the left
Contact:

Re: LEN trouble

Post by beyond »

Ehm... the 'Y' is missing in the vowel string and should be removed from the consonants :)

Heh, and that actually made me realize that there is an error in the program. The line that sets w does not recognize 'Y' as a vowel. An OR J=XX is missing. My mistake, clearly!
User avatar
Commie_User
Forum God
Forum God
Posts: 1486
Joined: 14/07/2009 - 23:34
Location: England
Contact:

Re: LEN trouble

Post by Commie_User »

I think you'll find the 'Y' mistake was actually mine. I assumed the mistake was yours and 'fixed' it.

But as I say, it works now anyway!

Where does the OR J=XX go then?
User avatar
beyond
Forum God
Forum God
Posts: 1312
Joined: 22/11/2002 - 19:57
Location: 2nd star to the left
Contact:

Re: LEN trouble

Post by beyond »

In line 80 along with the others.
Post Reply