Skip to content

Instantly share code, notes, and snippets.

@billyoverton
Created January 4, 2020 22:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save billyoverton/ee67d13e761438b6ed38eb3a04a70032 to your computer and use it in GitHub Desktop.
Save billyoverton/ee67d13e761438b6ed38eb3a04a70032 to your computer and use it in GitHub Desktop.
Small python script to find all valid phone numbers in the first 3000 digits of py. I got bored watching Person of Interest.
pi3000 = """3
141592653589793238462643383279502884197169399375105
82097494459230781640628620899862803482534211706798
21480865132823066470938446095505822317253594081284
81117450284102701938521105559644622948954930381964
42881097566593344612847564823378678316527120190914
56485669234603486104543266482133936072602491412737
24587006606315588174881520920962829254091715364367
89259036001133053054882046652138414695194151160943
30572703657595919530921861173819326117931051185480
74462379962749567351885752724891227938183011949129
83367336244065664308602139494639522473719070217986
09437027705392171762931767523846748184676694051320
00568127145263560827785771342757789609173637178721
46844090122495343014654958537105079227968925892354
20199561121290219608640344181598136297747713099605
18707211349999998372978049951059731732816096318595
02445945534690830264252230825334468503526193118817
10100031378387528865875332083814206171776691473035
98253490428755468731159562863882353787593751957781
85778053217122680661300192787661119590921642019893
80952572010654858632788659361533818279682303019520
35301852968995773622599413891249721775283479131515
57485724245415069595082953311686172785588907509838
17546374649393192550604009277016711390098488240128
58361603563707660104710181942955596198946767837449
44825537977472684710404753464620804668425906949129
33136770289891521047521620569660240580381501935112
53382430035587640247496473263914199272604269922796
78235478163600934172164121992458631503028618297455
57067498385054945885869269956909272107975093029553
21165344987202755960236480665499119881834797753566
36980742654252786255181841757467289097777279380008
16470600161452491921732172147723501414419735685481
61361157352552133475741849468438523323907394143334
54776241686251898356948556209921922218427255025425
68876717904946016534668049886272327917860857843838
27967976681454100953883786360950680064225125205117
39298489608412848862694560424196528502221066118630
67442786220391949450471237137869609563643719172874
67764657573962413890865832645995813390478027590099
46576407895126946839835259570982582262052248940772
67194782684826014769909026401363944374553050682034
96252451749399651431429809190659250937221696461515
70985838741059788595977297549893016175392846813826
86838689427741559918559252459539594310499725246808
45987273644695848653836736222626099124608051243884
39045124413654976278079771569143599770012961608944
16948685558484063534220722258284886481584560285060
16842739452267467678895252138522549954666727823986
45659611635488623057745649803559363456817432411251
50760694794510965960940252288797108931456691368672
28748940560101503308617928680920874760917824938589
00971490967598526136554978189312978482168299894872
26588048575640142704775551323796414515237462343645
42858444795265867821051141354735739523113427166102
13596953623144295248493718711014576540359027993440
37420073105785390621983874478084784896833214457138
68751943506430218453191048481005370614680674919278
19119793995206141966342875444064374512371819217999
8391015919561814675142691239748940907186494231961"""
pi3000 = pi3000.replace('\n', '').replace('\r', '')
def validNumber(number):
# Can not start with 0 or 1 (or reserved 9)
if number[0] in ['0','1','9']:
return False
# Removed reserved expansion numbers (9 in second digit)
if number[1] in ['9']:
return False
# Can not have two of the same for digit 2 and 3
if number[1] == number[2]:
return False
# Central Office Code can't start with 1
if number[3] == '1':
return False
# Geographic codes can't have 1 in both 2nd or 3rd slot
if number[4] == '1' and number[5] == '1':
return False
return True
begin = 0
length = 10
count = 0
while begin <= len(pi3000)-10:
end = begin + length
possible = pi3000[begin:end]
if(validNumber(possible)):
count+=1
if possible[0:3] == '423':
print(possible)
begin+=1
print ("Count: {0}".format(count))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment