最近拼了一个日历,是这样子的
其中
蓝色块2个 0 1 2 3 5 7
红色块2个 0 1 2 4 6 8
他们是怎么拼出一年中所有的天数的呢
python程序解析
# 遍历新历,即阳历闰年所有天数
dayofMonth=[31,29,31,30,31,30,31,31,30,31,30,31] #润年天数
assert sum(dayofMonth)==366 #共366天
# 生成所有天数
daylist=[ "{:0>2d}{:0>2d}".format(month+1,day) for month,maxnum in enumerate(dayofMonth) for day in range(1,maxnum+1)]
assert len(daylist)==366
# 统计所有数字的最大出现次数
import collections
max={}
# init max
for i in range(0,10):
i=str(i)
max[i]={}
max[i]['num']=0
for day in daylist:
for i,num in collections.Counter(day).items():
if max[i]['num']<num:
max[i]['num']=num
max[i]['list']=[day]
elif max[i]['num']==num:
max[i]['list'].append(day)
max
输出
{
'0': {'num': 2,'list': ['0101','0102','0103','0104','0105','0106','0107','0108','0109','0110','0120','0130','0201','0202','0203','0204','0205','0206','0207','0208','0209','0210','0220','0301','0302','0303','0304','0305','0306','0307','0308','0309','0310','0320','0330','0401','0402','0403','0404','0405','0406','0407','0408','0409','0410','0420','0430','0501','0502','0503','0504','0505','0506','0507','0508','0509','0510','0520','0530','0601','0602','0603','0604','0605','0606','0607','0608','0609','0610','0620','0630','0701','0702','0703','0704','0705','0706','0707','0708','0709','0710','0720','0730','0801','0802','0803','0804','0805','0806','0807','0808','0809','0810','0820','0830','0901','0902','0903','0904','0905','0906','0907','0908','0909','0910','0920','0930','1001','1002','1003','1004','1005','1006','1007','1008','1009','1010','1020','1030']},
'1': {'num': 4, 'list': ['1111']},
'2': {'num': 3, 'list': ['0222', '1222']},
'3': {'num': 2, 'list': ['0303', '0313', '0323', '0330', '0331']},
'4': {'num': 2, 'list': ['0404', '0414', '0424']},
'5': {'num': 2, 'list': ['0505', '0515', '0525']},
'6': {'num': 2, 'list': ['0606', '0616', '0626']},
'7': {'num': 2, 'list': ['0707', '0717', '0727']},
'8': {'num': 2, 'list': ['0808', '0818', '0828']},
'9': {'num': 2, 'list': ['0909', '0919', '0929']}
}
可以看到1最多出现4次,2最多出现3次,于是建立约束1必须4个立方体都有,2必须3个立方体以上有,其他必须要两个
结果反推
012357
012468
这两个骰子可以摆出01-31(天数),自然也可摆出01-12(月份)
其根本原因在于两个骰子表示01-31时,十位数的1-2不可替代性(11,22),必须两个骰子都有;
而0是因为立方体只有6个面所以357、468被分割所以需要候补,也需要两个(03,04);
而9和6可以平面相似;其实2和5也可以镜面相似,但是需要翻转,这在已经固定平面的骰子面上是难实现的。