Skip to main content
added 22 characters in body
Source Link
Sp3000
  • 62.3k
  • 13
  • 117
  • 292

Python 2, 9486 bytes

from random import* L=inputdef S(L)  :i=len(L) while i:i;exec"i-=1;j=randint(0,i);L[i],L[j]=L[j],L[i] print LL[i];"*i 

AThis is a function which shuffles the array in place without returning it, using a straightforward implementation of the Fisher-Yates shuffle. Getting random numbers from Python is expensive...

Takes input as a Python list, e.g. [1, 2, 3]. Thanks to @xnor and @colevk for the helptips.

Python 2, 94 bytes

from random import* L=input()  i=len(L) while i:i-=1;j=randint(0,i);L[i],L[j]=L[j],L[i] print L 

A straightforward implementation of the Fisher-Yates shuffle. Getting random numbers from Python is expensive...

Takes input as a Python list, e.g. [1, 2, 3]. Thanks to @xnor and @colevk for the help.

Python 2, 86 bytes

from random import* def S(L):i=len(L);exec"i-=1;j=randint(0,i);L[i],L[j]=L[j],L[i];"*i 

This is a function which shuffles the array in place without returning it, using a straightforward implementation of the Fisher-Yates shuffle. Getting random numbers from Python is expensive...

Thanks to @xnor and @colevk for tips.

added 40 characters in body
Source Link
Sp3000
  • 62.3k
  • 13
  • 117
  • 292

Python 2, 9694 bytes

from random import* L=input() i=len(L)-1 while i:j=randinti-=1;j=randint(0,i);L[i],L[j]=L[j],L[i];i-=1L[i] print L 

A straightforward implementation of the Fisher-Yates shuffle. Getting random numbers from Python is expensive...

Takes input as a Python list, e.g. [1, 2, 3]. Thanks to @xnor and @colevk for the help.

Python 2, 96 bytes

from random import* L=input() i=len(L)-1 while i:j=randint(0,i);L[i],L[j]=L[j],L[i];i-=1 print L 

A straightforward implementation of the Fisher-Yates shuffle. Getting random numbers from Python is expensive...

Takes input as a Python list, e.g. [1, 2, 3].

Python 2, 94 bytes

from random import* L=input() i=len(L) while i:i-=1;j=randint(0,i);L[i],L[j]=L[j],L[i] print L 

A straightforward implementation of the Fisher-Yates shuffle. Getting random numbers from Python is expensive...

Takes input as a Python list, e.g. [1, 2, 3]. Thanks to @xnor and @colevk for the help.

deleted 2 characters in body
Source Link
Sp3000
  • 62.3k
  • 13
  • 117
  • 292

Python 2, 10296 bytes

from random import* L=input() for i in range(leni=len(L)-1,0,-1) while i:j=randint(0,i);L[i],L[j]=L[j],L[i]L[i];i-=1 print L 

A straightforward implementation of the Fisher-Yates shuffle. Getting random numbers from Python is expensive...

Takes input as a Python list, e.g. [1, 2, 3].

Python 2, 102 bytes

from random import* L=input() for i in range(len(L)-1,0,-1):j=randint(0,i);L[i],L[j]=L[j],L[i] print L 

A straightforward implementation of the Fisher-Yates shuffle. Getting random numbers from Python is expensive...

Takes input as a Python list, e.g. [1, 2, 3].

Python 2, 96 bytes

from random import* L=input() i=len(L)-1 while i:j=randint(0,i);L[i],L[j]=L[j],L[i];i-=1 print L 

A straightforward implementation of the Fisher-Yates shuffle. Getting random numbers from Python is expensive...

Takes input as a Python list, e.g. [1, 2, 3].

Source Link
Sp3000
  • 62.3k
  • 13
  • 117
  • 292
Loading