Chronology Current Month Current Thread Current Date
[Year List] [Month List (current year)] [Date Index] [Thread Index] [Thread Prev] [Thread Next] [Date Prev] [Date Next]

Re: [Phys-L] From a Math Prof (physics BS major) at my institution ( math challenge)



-----Original Message-----
From: Phys-l [mailto:phys-l-bounces@phys-l.org] On Behalf Of brian
whatcott
That looks comparable to my box - what is your code, and what are your
results?

Brian Whatcott Altus OK

I'm (supposed to be) generating 1 million sets of 21 quintets of numbers between 1 and 35, inclusive without replacement. I've tested that pretty extensively (but there's ALWAYS 1 more bug, right?). I think my counting algorithm is pretty clean now, too. I'm counting three things:
1) How many quintets in each set have at least one mod 10 number (round number??) and histogramming that.
2) How many quintets in each set have at least one sequential couplet and histogramming that.
3) How many quintets in each set have at least one sequential triplet and histogramming that.

I'll put the results in the a follow-on email.

Please report bugs. Here's the python code:
import matplotlib.pyplot as plt
import numpy.random as rnd
from time import *

atime=clock()
tendata=[]
ordered2data=[]
ordered3data=[]
thirtyfive=[]
for i in range(1,36):
thirtyfive.append(i)

for l in range(1000000):
loops=21
tens=0
ordered2=0
ordered3=0
for k in range(loops):
a=list(thirtyfive)
b=[]
j=35
flag=False
for i in range(5):
select=rnd.randint(0,j)
b.append(a[select])
flag=flag or (a[select]%10==0)
a[select:select+1]=[]
j=j-1

if flag:
tens+=1
c=sorted(b)
flag2=False
flag3=False
j=0
while not flag3 and j<4:
diff=c[j+1]-c[j]
flag2=diff==1 or flag2
if j<3:
flag3 = diff==1 and c[j+2]-c[j]==2
j+=1
if flag2:
ordered2+=1
if flag3:
ordered3+=1
#print c
tendata.append(tens)
ordered2data.append(ordered2)
ordered3data.append(ordered3)
print min(tendata),mean(tendata),max(tendata)

plt.figure(1)
#plt.subplot(121)
n, bins, patches = plt.hist(tendata,normed=False, range=(0,20),bins=21,log=True)#, normed=1, facecolor='g')
print 'Bins and Counts of Even Tens'
print bins
print n

plt.xlabel('Tens')
plt.ylabel('Count')
plt.title('Histogram of Even Tens')
#plt.text(60, .025, r'$\mu='mean(tendata),'\ \sigma=??$')
#plt.axis([0, 20])
plt.grid(True)

print min(ordered2data),mean(ordered2data),max(ordered2data)
plt.figure(2)
#plt.subplot(122)
n, bins, patches = plt.hist(ordered2data,normed=False, range=(0,20),bins=21,log=True)#, normed=1, facecolor='g')
print 'Bins and Counts of Consecutives in a Set'
print bins
print n


plt.xlabel('Sequences')
plt.ylabel('Count')
plt.title('Histogram of At Least One Sequence')
#plt.text(60, .025, r'$\mu='mean(tendata),'\ \sigma=??$')
#plt.axis([0, 20])
plt.grid(True)


print min(ordered3data),mean(ordered3data),max(ordered3data)
plt.figure(3)
#plt.subplot(122)
n, bins, patches = plt.hist(ordered3data,normed=False, range=(0,20),bins=21,log=True)#, normed=1, facecolor='g')
print 'Bins and Counts of Triple Consecutives in a Set'
print bins
print n


plt.xlabel('Sequences')
plt.ylabel('Count')
plt.title('Histogram of At Least Triple One Sequence')
#plt.text(60, .025, r'$\mu='mean(tendata),'\ \sigma=??$')
#plt.axis([0, 20])
plt.grid(True)

print(clock()-atime, " seconds")
plt.show()