加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

【小学数学】NIM游戏相关

(2019-01-01 00:04:20)
标签:

nim游戏

策略

分类: 数学世界
在小学四年级数学作业中看到这样一道题:
有两堆火柴,一堆15根,一堆11根,甲乙两人轮流从中拿走1根或几根甚至一堆,但每次只能在某一堆中拿火柴,谁拿走最后一根谁获胜。甲如何才能获胜?

这道题比较简单,但是有着深刻的背景,源于NIM游戏。

Nim游戏具有悠久的历史,它是博弈论中最经典的模型之一,它又有着十分简单的规则和无比优美的结论

李新社编著2006版《离散数学》认为:Nim游戏,中国称之为“抓三堆”或“拧法”,国外称之为“Chinese Game of Nim”或者 Simple Game of Nim”。

(美)加德纳著2012《悖论与谬误》认为:所有二人数学游戏里,最古老、最有魅力的一种是现在叫做尼姆(Nim)的游戏;它可能发源于中国,有时候孩子们用纸片玩,而成人则在吧台上用硬币玩。美国布鲁迪著2012版《组合数学》则认为Nim游戏名称来自德语Nimm(意为拿取)。

檀越主编2009版《数学的秘密》认为:“关于NIM游戏源于中国的说法,见于国内多本介绍数学游戏的小册子。但迄今未发现我国古代文献中有关于它的记载。对此的解释是,按我国古代的传统,数学作为‘奇技淫巧’不足以登大雅之堂,难以在经史中占一席之地:在我国民间,确实流传着这种游戏,北方叫作‘抓三堆’,南方叫‘拧法’、‘翻摊’。”

        NIM这个游戏名称是美国哈佛大学数学教授Charles L. Bouton 1901年提出的,原文题名Nim, A Game with a Complete Mathematical Theory ,发表在The Annals of Mathematics, 2nd Ser., Vol. 3, No. 1/4. (1901 - 1902), pp. 35-39.

【小学数学】NIM游戏相关
哈佛Bouton在 1901发表有关NIM论文的截图

NIM信息

1.对于一堆轮流取子系列的NIM游戏

I 规定取最后的一个赢:比如取牌游戏或者爬台阶游戏

每次可取数目在1m之间时,

a)初始总数不是m+1)的倍数,先手第一步让剩下的数目为(m+1)*n,之后若对手取子k就取m+1-k,则先手必胜。

b)初始总数是m+1)的倍数,若对手取子k就取m+1-k,则后手必胜。


II规定取最后的一个输:比如下面的flash游戏

每次可取数目在1m之间时,

a)初始总数不是m+1*n+1先手第一步让剩下的数目为(m+1)*n+1,之后若对手取子k就取m+1-k,则先手必胜。

b)初始总数是m+1*n+1若对手取子k就取m+1-k,则后手必胜。





【小学数学】NIM游戏相关


【小学数学】NIM游戏相关

2.对于多堆系列的NIM游戏

I两堆比如开头给的例子,以最后取走的为赢。
先手将多的一堆取走部分使得两堆一样多,之后对手取走多少子,自己就在另外一堆取走同样数目的子。
II)三堆及以上
规定以最后取走的为赢时,解答步骤
(a)分解子集:将每个序列的数目表示为其二进制数(数的位数相等,不等时在前面补0);将每个序列分解为由数量为2n的各个子集组成。
(b)状态判断:如果每一种大小的子集的个数都是偶数,则称Nim取子游戏是平衡的;而对应位相加是奇数的状态为非平衡位。
(c)决策判断:遇非平衡位抢先手使其变成平衡状态;平衡位让先。
有关多序列NIM 游戏的flash例子
【小学数学】NIM游戏相关

【小学数学】NIM游戏相关

【小学数学】NIM游戏相关

【小学数学】NIM游戏相关


www.archimedes-lab.org上的解析例子
【小学数学】NIM游戏相关
 What is a “Nim sum”?

Count the matchsticks in each row... And convert them mentally in multiples of 4, 2 and 1. Then, CANCEL pairs of equal multiples, and add what is left. So, when starting, the “Nim sum” of the rows is:

Row1 = 1 = 1 x 1 = 1 =   1
Row2 = 3 = 1 x 2 + 1 x 1 = 2 1
Row3 = 5 = 1 x 4 + 1 x 1 = 4 1
Row4 = 7 = 1 x 4 + 1 x 2 + 1 x 1 = 4 2 1
Total of UNPAIRED multiples = 0 0 0

As you can see, there are currently TWO 4’s, TWO 2’s, and FOUR 1’s (= TWO + TWO + FOUR = 8). You have then an EVEN number of multiples, the remainder after dividing this number (8) by 2 gives 0.

To win at Nim-game, always make a move, whenever possible, that leaves a configuration with a ZERO “Nim sum”, that is with ZERO unpaired multiple(s) of 4, 2 or 1. Otherwise, your opponent has the advantage, and you have to depend on his/her committing an error in order to win.

How to leave a zero “Nim sum”:
Your opponent moves and leaves you the following configuration:

Row1 = 1 = 1 x 1 =   1
Row2 = 3 = 1 x 2 + 1 x 1 = 2 1
Row3 = 5 = 1 x 4 + 1 x 1 = 4 1
Row4 = 5 = 1 x 4 + 1 x 1 = 4 1
Total of unpaired multiples = 0 1 0

Get rid of ONE 2, by taking 2 matchsticks from the 2nd row. That leaves your opponent at 1, 1, 5, 5 which is, for him, a losing configuration...

Row1 = 1 = 1 x 1 =   1
Row2 = 1 = 1 x 1 =   1
Row3 = 5 = 1 x 4 + 1 x 1 = 4 1
Row4 = 5 = 1 x 4 + 1 x 1 = 4 1
Total of unpaired multiples = 0 0 0

Every time you leave your opponent a zero “Nim sum” configuration, you increase your chances to win! Here below are listed all the possible zero “Nim sum” configurations (sometimes, the order has no importance, for example: 3, 3, 1, 1 or 3, 1, 3, 1 has the same result). You can print the table and use it as a cheat sheet... But you can also improve your concentration skills by practicing “Nim sums” mentally!

Winning matchstick configurations
four rows three rows two rows
7, 4, 2, 1
6, 5, 2, 1
6, 4, 3, 1
5, 5, 1, 1
4, 4, 1, 1
3, 3, 1, 1
2, 2, 1, 1
7, 5, 2
7, 4, 3
6, 5, 3
6, 4, 2
5, 4, 1
3, 2, 1
1, 1, 1
5, 5
4, 4
3, 3
2, 2
Source: © G. Sarcone, www.archimedes-lab.org




0

阅读 收藏 喜欢 打印举报/Report
前一篇:词库mdx制作
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有