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

LOGO-L> (No Subject)



Here is a solution based of the circular shift of the list.

Make a wheel with your list then turn the wheel an
pick the element at the head.


to  turn :l
repeat  1 + random count :l [make "l lput first :l bf :l ]
op :l
end

turn uses only repeat and make which should be in any logo.

Turn just return the list with random circular permutation.
pick the first element for use and continue with the rest (bf ) of the list.


; So build poprandom (If you have pop in library)

to poprandom :nameoflist
make :nameoflist turn thing :nameoflist
op pop :nameoflist
end

; Or the same with basic primitives.

to pick&remove  :nameoflist
make :nameoflist turn thing :nameoflist
localmake "picked first thing :nameoflist
make  :nameoflist bf thing :nameoflist
op :picked
end


You can work with first and butfirs.
As in this example.


to printrandom :l
if emptyp :l [stop]
make "l  turn :l
print first :l
printrandom bf :l
end

And now your dream :

to shuffle :l [:l2 []]
if emptyp :l [op :l2]
make "l turn :l
op (shuffle bf  :l  fput first :l  :l2)
end

Shuffle returns a list with the elements randomly shuffled.

butitem is a good tool to put in the library

If you like turn you can find a better name for it,
I don't speak english very well.

Regards

P-A Dreyfuss.



>I hope there is an easy explanation, but I can't find it!  I have tried

>every combination of likely commands I can think of, to no avail.
>
>I have a list with 11 words in it; each is the name of a procedure.  I am

>trying to pick one of these words at random and then eliminate it from the

>list.  (At a certain button click, all of the words can be restored to the

>list.)  But all I can manage to do is either run through the list in the

>same order as originally entered, eliminating the first (or last) each time

>(using butfirst or butlast), or select randomly without eliminating any

>words and sometimes have the same word get chosen repeatedly.  How can I

>select a word randomly and then place that word at the beginning or end
of
>the list so it can be eliminated?  Or if this is not possible, is there

>some handy way of entering the list in a newly scrambled order each time
a
>button is clicked?  Does it help to put the list into a text box?
>
>Thanks in advance,
>Wendy Petti
>Washington International School
>wap3@cornell.edu  or comp3@wis.edu

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

>




Free web-based email, Forever, From anywhere!
http://www.mailexcite.com

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