[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

LOGO-L> More word-shuffling



I'd like to get some opinions about the following versions of yet another
word-scrambling procedure. All of this has come about from exploring the
recently-posted "shuffling words" procedures and comments.
(The "remove_item" and "remove_pick" procedures are shown following the
"jumble" procedures.)

----------------------------------------
; Version A
; this version of jumble sets things up for the 'helper' function
; that does the real work

to jumble :w
if (count :w) < 2 [output :w]
output jumble1 :w (1 + random count :w)
end

to jumble1 :w :n
if (count :w) < 2 [output :w]
output word (item :n :w)
            (jumble1 (remove_item :n :w) (1 + random ((count :w) - 1)))
end

----------------------------------------
; Version B
; this version of jumble does not need a 'helper' function but
; does need a local variable for the randomly chosen position

to jumble :w
if (count :w) < 2 [output :w]
local "n
make "n (1 + random count :w)
output word (item :n :w) (jumble (remove_item :n :w))
end

----------------------------------------
; Version C
; this version of jumble does not use recursive calls;
; it selects a random position from the full word each time
; instead of from a recursively smaller word

to jumble :w
local "n
repeat (count :w)
  [make "n (1 + random count :w)
   make "w word (item :n :w) (remove_item :n :w)]
output :w
end
----------------------------------------

; Version A-pick
; similar to Version A but I used a local variable;
; could have put (remove_pick :p :w) in place of :nextw

to jumble :w
output jumble1 :w pick :w
end

to jumble1 :w :p
if (count :w) < 2 [output :w]
local "nextw
make "nextw (remove_pick :p :w)
output word :p (jumble1 :nextw pick :nextw)
end

----------------------------------------
; Version B-pick

to jumble :w
if (count :w) < 2 [output :w]
local "p
make "p pick :w
output word :p (jumble (remove_pick :p :w))
end

----------------------------------------

; I copied the "butn" procedure that was recently posted to the
; listserv but named it "remove_item" since it is being used
; with "item" and switched the inputs to match "item" inputs.

to remove_item :n :w
if :n < 2 [output butfirst :w]
output word (first :w) (remove_item (:n - 1) (butfirst :w))
end

; remove_pick is very similar to remove_item but it is
; removing a specific character instead of the character
; at a specified position

to remove_pick :p :w
if empty? :w [output " ]
if :p = first :w [output butfirst :w]
output word (first :w) (remove_pick :p (butfirst :w))
end

----------------------------------------

Just some other comments:

1.  Microworlds returns an error for "random 0" (minimum value for random
    is 1). This makes sense since the definition of random is to report a
    random non-negative integer less than the input; so, if the input is 0
    there is nothing possible to return that fits the definition.  The
    following procedure could be defined in Microworlds to allow for the 0
    input:

	to random0 :n
	   if :n = 0 [output 0]
	   output random :n
	end
 
2.  Since the statement "1 + random :something" seems to get used a lot, the 
    following procedure could be defined:

	to random1 :n
	  output 1 + random0 :n
	end

3.  In the JUMBLE procedures, the need to get a random character position might
    better be a procedure such as:

	to random_pos :w
	  output random1 count :w
	end

All of these could be defined in the special startup file called -tools-.txt
for Microworlds. If you are not familiar with this file, their web site has
an example file but they are not willing to share very much information about
its use (unfortunately).


---------------------------------------------------------------
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