Created
August 30, 2011 07:26
-
-
Save jacobk/1180381 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random as r;_,N=range,1e6;l=_(13)*4 | |
print sum([r.shuffle(l)or 0in[x-y for x,y in zip(l[1:],l)]for i in _(N)])/N |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def n(l,p=51): | |
if p: return l[p-1]==l[p] or n(l,p-1) | |
import random as r | |
S,N=range(13)*4,1e6 | |
a=[0]*int(N) | |
print map(n,map(lambda a:r.sample(S,52),a)).count(1)/N |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n=1e6;i=__import__;l=list("abcdefghijklm"*4); | |
print len([_ for _ in(i("random").shuffle(l)for _ in range(int(n)))if i("re").search(r"(.)\1","".join(l))])/n |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
main(){int N=52,m=1e6,n=0,c=0,x[N],d[N],i,j,k; | |
while(n++<m){for(i=0;i<N;i++)d[i] = i;for(i=0,j=N;i<N;i++,j--){k=rand()%j;x[i]=d[k];if(i>0&&x[i]%13==x[i-1]%13){c++;break;}else memmove(d+k,d+k+1,4*(j-k-1));}} | |
printf("%f", 1.* c / m);} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
l=range(1,14)*4;n=1000000.0 | |
print sum([random.shuffle(l)or 0 in[x-y for x,y in zip(l[1:],l)]and 1or 0for i in range(n)])/n |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment