Skip to content

Instantly share code, notes, and snippets.

@oskarols
Last active August 29, 2015 14:00
Show Gist options
  • Save oskarols/497a73f2d3001f401f38 to your computer and use it in GitHub Desktop.
Save oskarols/497a73f2d3001f401f38 to your computer and use it in GitHub Desktop.
Chance of duplicates in deck — Python
import random as r
a=range
l=len
d=list(a(1,15))*4
t=[]
for i in a(1000000):r.shuffle(d);t.append(int(any(d[i]==d[i+1]for i in a(l((d)))if i<55)))
print(sum(t)/l(t))
@MyGGaN
Copy link

MyGGaN commented Apr 22, 2014

Python 2.6

from random import*
N=1e6
l=range(13)_4
sum([shuffle(l)or 0in[x-y for x,y in zip(l[1:],l)]for i in[1]_N])/N

@oskarols
Copy link
Author

Gillade shuffle(l) or 0 in samt användandet av zip. Snyggt!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment