Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def day5():
- if not os.path.isfile(OUTPUT_FNAME):
- print("downloading " + INPUT_URL)
- opener = urllib.request.build_opener()
- opener.addheaders.append(('Cookie', 'session=' + COOKIE))
- k = opener.open(INPUT_URL)
- with open(OUTPUT_FNAME, "w") as f:
- f.write(k.read().decode("utf-8"))
- with open(OUTPUT_FNAME) as f:
- foo = f.read().replace('\n','')
- winchar = ''
- scores = []
- def ex(foo,c):
- print('beginning: c=' + str(c))
- tw = testwithout(foo.replace(c,'').replace(c.upper(),''))
- print('c=' + str(c) + ' tw=' + str(tw))
- scores.append((c,tw))
- NUM_THREADS = 4
- chrs = "qwertyuiopasdfghjklzxcvbnm"
- for s in [chrs[j:(j+NUM_THREADS)] for j in range(0, len(chrs), NUM_THREADS)]:
- threads = [threading.Thread(target=ex, args=(foo,c)) for c in s]
- [t.start() for t in threads]
- [t.join() for t in threads]
- lowest = 999999999
- lowestc = ''
- for s in scores:
- if s[1] < lowest:
- lowest = s[1]
- lowestc = s[0]
- print(lowestc)
- print(str(lowest))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement