Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Mar 16th, 2013  |  syntax: Python  |  size: 0.76 KB  |  views: 51  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. import itertools
  2. import numpy as np
  3.  
  4. def find_number_of_divisiors(n_vals):
  5.     col = np.asmatrix(n_vals, dtype='int32').T
  6.     row = np.arange(2, n_vals[-1]/2+1, dtype='int32')
  7.     mods = col % row
  8.     return 2 + np.sum(mods == 0, axis=1)
  9.  
  10. def tri_nums():
  11.     n = 1
  12.     t = 1
  13.     while 1:
  14.         yield t
  15.         n += 1
  16.         t += n
  17.  
  18. t = tri_nums()
  19.  
  20. print 1, ' has ', 1, ' divisors.'
  21. m = 1
  22. next(t)
  23.  
  24. chunksize = 500
  25. while True:
  26.     nchunk = list(itertools.islice(t, chunksize))
  27.     dchunk = find_number_of_divisiors(nchunk)
  28.     for i, d in enumerate(dchunk):
  29.         if m < d:
  30.             print nchunk[i], ' has ', d, ' divisors.'
  31.             m = d
  32.             if m == 320:
  33.                 exit(0)
  34.     chunksize = 10000000 // nchunk[-1] + 2