-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpythontest30.py
More file actions
53 lines (42 loc) · 1.18 KB
/
Copy pathpythontest30.py
File metadata and controls
53 lines (42 loc) · 1.18 KB
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
48
49
50
51
52
53
import urllib
import operator
import bz2
from math import sqrt
import Image
def factorize(n):
def isPrime(n):
return not [x for x in xrange(2,int(sqrt(n))+1)
if n%x == 0]
primes = []
candidates = xrange(2,n+1)
candidate = 2
while not primes and candidate in candidates:
if n%candidate == 0 and isPrime(candidate):
primes = primes + [candidate] + factorize(n/candidate)
candidate += 1
return primes
def myHex(h):
ii = hex(h)[2:]
if len(ii) < 2:
ii = '0' + ii
return ii
nexturl = 'http://repeat:switch@www.pythonchallenge.com/pc/ring/yankeedoodle.csv'
myFile = urllib.urlopen(nexturl)
headers = myFile.info()
#print headers
LongString = myFile.read()
#print LongString
print len(LongString)
myFile.close()
#myFile = open("yankeedoodle.csv","w")
#myFile.write(LongString)
#myFile.close()
s = LongString.replace('\n','').replace(' ','').split(',')
print len(s)
print factorize(len(s))
im = Image.new("RGB",(53,139))
for y in range(139):
for x in range(53):
p = int(float(s[x+(y*53)])*256)
im.putpixel((x,y),(p,p,p))
im.save("yankeedoodle.bmp")