Advertisement
Guest User

Untitled

a guest
Dec 4th, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.24 KB | None | 0 0
  1. def day5():
  2.     if not os.path.isfile(OUTPUT_FNAME):
  3.         print("downloading " + INPUT_URL)
  4.         opener = urllib.request.build_opener()
  5.         opener.addheaders.append(('Cookie', 'session=' + COOKIE))
  6.         k = opener.open(INPUT_URL)
  7.         with open(OUTPUT_FNAME, "w") as f:
  8.             f.write(k.read().decode("utf-8"))
  9.    
  10.     with open(OUTPUT_FNAME) as f:
  11.         foo = f.read().replace('\n','')
  12.        
  13.         winchar = ''
  14.         scores = []
  15.        
  16.         def ex(foo,c):
  17.             print('beginning: c=' + str(c))
  18.             tw = testwithout(foo.replace(c,'').replace(c.upper(),''))
  19.             print('c=' + str(c) + ' tw=' + str(tw))
  20.             scores.append((c,tw))
  21.        
  22.         NUM_THREADS = 4
  23.         chrs = "qwertyuiopasdfghjklzxcvbnm"
  24.         for s in [chrs[j:(j+NUM_THREADS)] for j in range(0, len(chrs), NUM_THREADS)]:
  25.             threads = [threading.Thread(target=ex, args=(foo,c)) for c in s]
  26.             [t.start() for t in threads]
  27.             [t.join() for t in threads]
  28.        
  29.         lowest = 999999999
  30.         lowestc = ''
  31.         for s in scores:
  32.             if s[1] < lowest:
  33.                 lowest = s[1]
  34.                 lowestc = s[0]
  35.         print(lowestc)
  36.         print(str(lowest))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement