Rubykuby

Benford's law applied to square numbers

May 27th, 2013
467
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.46 KB | None | 0 0
  1. maxvalue = 10**4
  2. sqList = []
  3. benfordList = [[], [], [], [], [], [], [], [], []]
  4.  
  5. for i in range(maxvalue):
  6.     sqList.append(str((i+1)**2))
  7.     print(sqList[i])
  8.  
  9.     for first in range(1, 10):
  10.         if sqList[i].startswith(str(first)):
  11.             benfordList[first-1].append(sqList[i])
  12.  
  13. for i in range(len(benfordList)):
  14.     print("Numbers starting with ", i+1, ": ", len(benfordList[i]), sep='')
  15.     print("Percentage of total:     ", len(benfordList[i]) / maxvalue * 100, " %", sep='')
Advertisement
Add Comment
Please, Sign In to add comment