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

Re: LOGO-L> Re: apl:deal porting to LOGO



Tom Lynn wrote:
Sorry to dig even further back in the list, but its taken me this long to
get an answer ready!  In case you've forgotten, the question was "How do
you select k items at random from a list?".

The attached files are:

pooldeal.lgo - a 'deal' which selects k items from a list without having to
               count all of the items in the list in advance.

heap.lgo     - a set of library routines which implement a heap
               datastructure and heapsort.  Used by pooldeal.lgo.

heap.txt     - an indepth description of heap.lgo.

heaplib      - a file to put in the library folder with heap.lgo to
               make the code in heap.lgo available in the library.

heaptest.lgo - example code for using the heap library in your own programs

I started by just coding an answer to the question of how to select items
at random from a list (pooldeal.lgo) and found that in order to make it
work more efficiently I needed a heap.

<snipped>
 

Hi Tom,

To select :k random letters from a word you can shuffle the given word and then extract its first :k letters. A possible program might be this:
 

to select :k :wrd :selection
if :k<1[op :selection]
op select :k-1 bf :wrd word :selection first :wrd
end

to shuffle :wrd
if 2>count :wrd [op :wrd]
repeat random count :wrd[
  make "wrd word bf :wrd first :wrd] ; NOT localmake
op word first :wrd shuffle bf :wrd
end

To select, for example, 7 random letters from chattahoocee you say:

    pr select 7 shuffle "chattahoochee "

Best Regards,
[[Yehuda]]
 

    _/    _/     _/ _/_/_/_/_/ _/_/_/_/
   _/   _/     _/_/    _/          _/
  _/_/_/     _/  _/   _/        _/
 _/   _/   _/_/_/_/  _/      _/
_/     _/_/      _/ _/     _/_/_/_/

http://www.geocities.com/CollegePark/lab/2276/
e-mail: yehuka@beitberl.ac.il
 



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