Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #9427
| From | Steve Graham <jsgrahamus@yahoo.com> |
|---|---|
| Newsgroups | comp.lang.forth |
| Subject | Sets in Forth |
| Date | 2012-02-07 08:25 -0700 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <jgrfp0$m45$1@speranza.aioe.org> (permalink) |
Part of a recent project was to generate the numbers 1-24 in random
order. One tack is to:
1) Initialize an "array" of 24 bytes to 0
2) For each of 24 times
a) Get a random number between 0 and
(the number of possible numbers - 1)
b) Look at the array of available numbers using this position number
c) If the number in that position is already chosen, go back to a)
d) Otherwise,
i) Mark the number as chosen
ii) Move it to an array of chosen numbers
In my workday language, instead of searching among an array of available
numbers until I found one, which had not already been chosen, I would
use a set of available numbers and when one was chosen, I would simply
delete it from the set. Thus I would not go over the chosen numbers
more than once.
Is there a way to create a set in Forth? Of course, there is. I could
do it with a linked list and when a number is chosen, simply reorient
the links to/from it, essentially removing it from the list.
Is there another or better way?
Thanks, Steve
Back to comp.lang.forth | Previous | Next — Next in thread | Find similar | Unroll thread
Sets in Forth Steve Graham <jsgrahamus@yahoo.com> - 2012-02-07 08:25 -0700
Re: Sets in Forth anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-02-07 15:44 +0000
Re: Sets in Forth Steve Graham <jsgrahamus@yahoo.com> - 2012-02-07 09:49 -0700
Re: Sets in Forth Paul Rubin <no.email@nospam.invalid> - 2012-02-07 19:24 -0800
Re: Sets in Forth mhx@iae.nl (Marcel Hendrix) - 2012-02-07 22:12 +0200
csiph-web