shuffle function

  • Follow


Hi.

I would like to make a shuffle function to shuffle a list.
I know basic idea behind shuffling algorithm,
pull a random element out and repeat that until the list is empty.
I can make a new list every time when I pull one element out
from which I pull out a random element again and repeat that until get the 
empty list
or I could make a two dimensional array where each element has
a field which indicates whether that element was pulled out or no.
Any other suggestions ?
Can recursion help here ?
What is the simplest way to shuffle a list ?

Thanks 

0
Reply iso 10/9/2010 8:11:47 PM

 HB> I would like to make a shuffle function to shuffle a list.
 HB> I know basic idea behind shuffling algorithm,
 HB> pull a random element out and repeat that until the list is empty.
 HB> I can make a new list every time when I pull one element out
 HB> from which I pull out a random element again and repeat that until get
 HB> the empty list
 HB> or I could make a two dimensional array where each element has
 HB> a field which indicates whether that element was pulled out or no.
 HB> Any other suggestions ?

You can delete element from the list without creating new one.
 You can make one-dimensional array and write NIL on place of removed 
elements.

 HB> Can recursion help here ?

Probably.

 HB> What is the simplest way to shuffle a list ?

Use google to find function implemented by others.

Note that some algorithms might produce shuffling which is not perfect. 

0
Reply Captain 10/9/2010 9:01:18 PM


On Oct 9, 4:11=A0pm, Haris Bogdanovi=E6 <fbogdano...@xnet.hr> wrote:
> Hi.
>
> I would like to make a shuffle function to shuffle a list.
> I know basic idea behind shuffling algorithm,
> pull a random element out and repeat that until the list is empty.
> I can make a new list every time when I pull one element out
> from which I pull out a random element again and repeat that until get th=
e
> empty list
> or I could make a two dimensional array where each element has
> a field which indicates whether that element was pulled out or no.
> Any other suggestions ?
> Can recursion help here ?
> What is the simplest way to shuffle a list ?
>
> Thanks

We talked about this recently.

http://groups.google.com/group/comp.lang.lisp/msg/9a2dbe0bacf4a1f5

0
Reply Gene 10/9/2010 10:44:03 PM

How odd, that pretty much this very question seems to have been asked in
this group within the last week or two.  Let's see ... is it the season
of Fall again?  Did school just start?

Or is there some other reason that you happen to be asking a generic toy
programming example, that doesn't once mention Lisp, on a group devoted
to Lisp?

P.S. Are you sure you're allowed to use an array?  The last poster said
that arrays weren't permitted.  Perhaps you should double-check the
original assignment...

P.P.S. For a real answer, use an array, and shuffle in place, rather
than copying to a new location.  Also, for inspiration you can look into
sorting with a random comparison function, although be careful: most
naive implementations of such sorts don't produce all permutations with
equal probability.
_______________________________________________________________________________
Don Geddis                  http://don.geddis.org/               don@geddis.org

Haris Bogdanovi� <fbogdanovic@xnet.hr> wrote on Sat, 9 Oct 2010 :
> Hi.
>
> I would like to make a shuffle function to shuffle a list.
> I know basic idea behind shuffling algorithm,
> pull a random element out and repeat that until the list is empty.
> I can make a new list every time when I pull one element out
> from which I pull out a random element again and repeat that until get the
> empty list
> or I could make a two dimensional array where each element has
> a field which indicates whether that element was pulled out or no.
> Any other suggestions ?
> Can recursion help here ?
> What is the simplest way to shuffle a list ?
>
> Thanks
0
Reply Don 10/9/2010 11:28:01 PM

It seems that you are halucinating again. Too much of lsd ?
I'm asking this because it has to be translated to Javascript
by Parenscript and it doesn't translate car, cdr and some other.
Get off of those drugs. Drugs are bad, mkey.
Speaking of drugs, I can't find lispworks crack anywhere ?
0
Reply iso 10/11/2010 11:49:51 AM

 HB> It seems that you are halucinating again. Too much of lsd ?
 HB> I'm asking this because it has to be translated to Javascript
 HB> by Parenscript and it doesn't translate car, cdr and some other.
 HB> Get off of those drugs. Drugs are bad, mkey.
 HB> Speaking of drugs, I can't find lispworks crack anywhere ?

JavaScript has different data structures. If you're working with associative 
arrays you can directly remove elements from them, no need for mumbo-jumbo 
with lists, recursion, 2d arrays etc. 

0
Reply Captain 10/11/2010 1:56:30 PM

On 10/11/2010 7:49 AM, Haris Bogdanovi� wrote:
> It seems that you are halucinating again. Too much of lsd ?

Oh, wow, that is /so/ original. Well, as long as you do not run it into 
the ground....

> Get off of those drugs. Drugs are bad, mkey.
> Speaking of drugs, I can't find lispworks crack anywhere ?

See horse. See dead horse. See Haris beat dead horse.

And it's 'mkay, 'mkay?

hth, kenzo


-- 
http://www.stuckonalgebra.com
"The best Algebra tutorial program I have seen... in a class by itself." 
Macworld
0
Reply Kenneth 10/11/2010 2:27:30 PM

On 2010-10-11 12:49:51 +0100, Haris Bogdanović said:
> 
> I'm asking this because it has to be translated to Javascript
> by Parenscript and it doesn't translate car, cdr and some other.

OK, so what you're after is a shuffle function for a language which is 
really very different than Lisp.  Why are you asking in a Lisp 
newsgroup?

0
Reply Tim 10/11/2010 2:50:25 PM

7 Replies
170 Views

(page loaded in 0.095 seconds)

Similiar Articles:













7/8/2012 2:13:58 PM


Reply: