-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanaprime.py
47 lines (35 loc) · 1.17 KB
/
anaprime.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from prime import prime
from ROOT import *
digits = range(10)
strdigits = map( str, digits )
prime = prime.replace('\n','').replace('.','')
print 'CHECK:',all(map(str.isdigit,prime))
hdigit = TH1I('digit',';;# of ocurrences',10,0,10)
hlargest = TH1I('largest','Largest # consecutive digit;;Max',10,0,10)
hconsecutive = TH1I('consecutive','# consecutive digits;#Consecutives;',10,0,10)
hdigits = TH1I('digits',';;# of ocurrences',10,0,10)
[ hdigit.GetXaxis().SetBinLabel(d+1,str(d)) for d in digits ]
[ hlargest.GetXaxis().SetBinLabel(d+1,str(d)) for d in digits ]
last = None
counter = 0
maxs = [ 0 for d in digits ]
for d in prime:
dint = int(d)
hdigit.Fill( dint )
if dint != last:
hconsecutive.Fill( counter )
maxs[dint] = max( counter, maxs[dint] )
counter = 0
last = dint
counter += 1
for i,m in enumerate(maxs): hlargest.SetBinContent(i+1,m)
for d in digits: hdigits.SetBinContent(d+1,prime.count(''.join(strdigits[:d+1])))
for h in (hdigit,hlargest,hconsecutive):
h.SetLineWidth(2)
c = TCanvas()
c.Divide(2,2)
c.cd(1);hdigit.Draw()
c.cd(2);hlargest.Draw()
c.cd(3);hconsecutive.Draw()
c.cd(4);hdigits.Draw()
raw_input()