# -*- coding: utf-8 -*-
#
# Script to generate in English and French, graphs for the
# birthday problem.
#
# **************************************************************
# http://en.wikipedia.org/wiki/Polydivisible_number
# From Wikipedia, the free encyclopedia:
# In mathematics a polydivisible number is a number with digits
# abcde... that has the following properties :
#
# Its first digit a is not 0.
# The number formed by its first two digits ab is a multiple of 2.
# The number formed by its first three digits abc is a multiple of 3.
# The number formed by its first four digits abcd is a multiple of 4.
# etc.
#
# Text under the
# Creative Commons Attribution-ShareAlike License
# **************************************************************
#
# Guillaume Jacquenot
# 2013/05/01
from pylab import *
import numpy as np
def getData():
r=np.array(
[[ 1, 9, 9],
[ 2, 45, 45],
[ 3, 150, 150],
[ 4, 375, 375],
[ 5, 750, 750],
[ 6, 1200, 1250],
[ 7, 1713, 1786],
[ 8, 2227, 2232],
[ 9, 2492, 2480],
[10, 2492, 2480],
[11, 2225, 2255],
[12, 2041, 1879],
[13, 1575, 1445],
[14, 1132, 1032],
[15, 770, 688],
[16, 571, 430],
[17, 335, 253],
[18, 180, 141],
[19, 90, 74],
[20, 44, 37],
[21, 18, 17],
[22, 12, 8],
[23, 6, 3],
[24, 3, 1],
[25, 1, 1]])
return r
def makePlot(\
generateEnglishPlot = True,\
outputFilename = 'Graph_of_polydivisible_number.svg'):
if generateEnglishPlot:
xlabel_ = 'n Number of digits'
ylabel_ = 'Number of polydivisible numbers'
leg1 = 'F(n)'
leg2 = 'Estimate of F(n)'
else:
xlabel_ = 'n Nombre de digits'
ylabel_ = 'Nombre de nombres polydivisibles'
leg1 = 'F(n)'
leg2 = 'Estimée de F(n)'
r=getData()
plot(r[:,0], r[:,1], marker = 'o', label = unicode(leg1, 'utf8'))
plot(r[:,0], r[:,2], marker = '^', label = unicode(leg2, 'utf8'))
grid(True, ls='-', c='#a0a0a0')
legend(loc='right')
xlabel(xlabel_)
ylabel(ylabel_)
savefig(outputFilename)
show()
makePlot(generateEnglishPlot = True, outputFilename = 'Graph_of_polydivisible_number.svg')
makePlot(generateEnglishPlot = False, outputFilename = 'Graphe_des_nombres_polydivisibles.svg')