> Date: Wed, 11 Jun 1997 11:49:56 +0300 > From: Yehuda Katz <yehuka@beitberl.beitberl.ac.il> > To: Logo-L <Logo-L@gsn.org> > Subject: LOGO-L> Shuffling words > Reply-to: Yehuda Katz <yehuka@beitberl.beitberl.ac.il> > Hello fellows, > > The following program PICKs a word from WORDS and prints it on the > screen with its letters mixed (shuffled) [.....] Hello, I hope I may put my nose again in your fellows' business. Besides all, I can't stay aside since my native KGB was mentioned. :-) But again, I tried to compose proposals suitable for the school children. May be, my brains are constructed in a wrong way, but recursion is more hard for me to understand and explain than arrays. So again, sorry Yehuda, I use arrays. The proposals are as follows. Let'shuffle not a word, but ASCII table and then let's code every character of the word according to a new table. I think it'd be useful exercise for students to work with the words, arrays and ASCII codes this way. In the program below I use only part of the ASCII table, which includes numbers and letters, that's why the array contains only 75 elements, from the 48th through 122d of ASCII table. ---------------------------------------- to coding.main ct pr [==> input a message as one word] make "wrd rw make "arr array 75 ; forms initial table coding.array.form :arr ; shuffles randomly the table coding.array.shuffle :arr (count :arr) ; coding the word according to the new table coding.word :wrd " end to coding.array.form :arr ; filling the array with the character numbers ; according to the ASCII table for [i 48 122][setitem :i-47 :arr :i] end to coding.array.shuffle :arr :n ; random shuffle of the array ; procedure coding.array.swap just swaps two elements for [j 1 100] [coding.array.swap 1+random :n 1+random :n] end to coding.array.swap :k :m ; swaps two elements localmake "spare item :k :arr setitem :k :arr item :m :arr setitem :m :arr :spare end to coding.word :wrd :new.word ; the core of this is the procedure coding.word.search ; which finds a new value for each character of the word. if emptyp :wrd [pr :new.word stop] make "new.word word :new.word (coding.word.search first :wrd) coding.word bf :wrd :new.word end to coding.word.search :ch for [i 48 122] [if (ascii :ch)=item :i-47 :arr [output char :i]] end -------------------------------- You may decode the message with the procedures decoding.word and decoding.word.search, which are similiar to coding.word and coding.word.search. to decoding.word :wrd :new.word if emptyp :wrd [pr :new.word stop] make "new.word word :new.word (decoding.word.search first :wrd) decoding.word bf :wrd :new.word end to decoding.word.search :ch for [j 1 75][if (ascii :ch)=:j+47 [output char item :j :arr]] end ------------------------------------ ------------------------------------ I'd like to hear your opinion. I feel a little bit uncomfortable trying to take you from the mountain top down to the flat and dull ground :-) And if all this is worth nothing, I'd like to hear this also. Negative result is also a result. :-) Thank you. Olga. --------------------------------------------------------------- Please post messages to the Logo forum to logo-l@gsn.org. Mail questions about the list administration to logofdn@gsn.org. To unsubscribe send unsubscribe logo-l to majordomo@gsn.org.
Global SchoolNet Foundation -
Linking Kids Around the World!
Copyright GSN - All Rights Reserved
- Comments
& Questions
Visit GSN's
Global
Schoolhouse for more exciting learning resources!
Search our Site
-
Home