Created
June 22, 2015 16:48
-
-
Save kusano/09256df10d2d5d4870e4 to your computer and use it in GitHub Desktop.
マイナンバーの最下位桁の出現頻度を調べる
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#coding: utf-8 | |
# マイナンバーの最下位桁の出現頻度を調べる | |
# http://law.e-gov.go.jp/announce/H26F11001000085.html | |
import random | |
def check(number): | |
P = map(int, ("%011d"%number)[::-1]) | |
Q = [n+1 if n<=6 else n-5 for n in range(1,12)] | |
r = sum(p*q for p,q in zip(P,Q)) % 11 | |
return 11-r if r>=2 else 0 | |
N = 1000000 | |
random.seed(1234) | |
c = [0]*10 | |
for i in range(N): | |
number = random.randint(0,10**11-1) | |
c[check(number)] += 1 | |
for i in range(10): | |
print "%d %8d %8.2f%%"%(i, c[i], float(c[i])/N*100) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
0 181544 18.15% | |
1 90727 9.07% | |
2 91210 9.12% | |
3 90816 9.08% | |
4 91469 9.15% | |
5 90942 9.09% | |
6 90758 9.08% | |
7 90397 9.04% | |
8 91306 9.13% | |
9 90831 9.08% |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment