The four number game

82 篇文章 0 订阅
49 篇文章 0 订阅

The Four Numbers Game is a mathematical game, as taught by Dr. Paul Sally, Prof. of Mathematics at the University of Chicago. To play this game, draw a square and put a number at each corner, thus:

5___9
|   |
|   |
|   |
7___13

Now form a new square based on the difference between each the values at the ends of each side. Example:

5_4_9
|   |
2   4
|   |
7_6_13

This gives a new square, which I'll rotate anticlockwise 45 degrees.

4___4
|   |
|   |
|   |
2___6

This in turn gives

0___2
|   |
|   |
|   |
2___4

Then

2___2
|   |
|   |
|   |
2___2

Then

0___0
|   |
|   |
|   |
0___0

At this point, the game is over.

 

 

Codes for geting any four given numbers:

 

 

  1. Sub FourNumbers(ByRef steps As StringByRef count As LongParamArray s())
  2. Dim temp As String, tempcount As Long
  3. count = 1
  4. If s(0) & s(1) & s(2) & s(3) = "0000" Then steps = Join(s, ","): Exit Sub
  5. FourNumbers temp, tempcount, Abs(s(0) - s(1)), Abs(s(1) - s(2)), Abs(s(2) - s(3)), Abs(s(3) - s(0))
  6. steps = Join(s, ",") & vbCrLf & temp
  7. count = tempcount + 1
  8. End Sub
  9. Sub Getit()
  10. Dim steps As String, count As Long
  11. FourNumbers steps, count, [exp(1)], [pi()], 1, 0
  12. Debug.Print "Count=" & count & vbCrLf & String(50, "-") & vbCrLf & steps
  13. FourNumbers steps, count, 149, 274, 504, 927
  14. Debug.Print "Count=" & count & vbCrLf & String(50, "-") & vbCrLf & steps
  15. End Sub

It returns:

 

Count=5
--------------------------------------------------
2.71828182845905,3.14159265358979,1,0
0.423310825130748,2.14159265358979,1,2.71828182845905
1.71828182845905,1.14159265358979,1.71828182845905,2.2949710033283
0.576689174869252,0.576689174869252,0.576689174869252,0.576689174869252
0,0,0,0

 

Count=19
--------------------------------------------------
149,274,504,927
125,230,423,778
105,193,355,653
88,162,298,548
74,136,250,460
62,114,210,386
52,96,176,324
44,80,148,272
36,68,124,228
32,56,104,192
24,48,88,160
24,40,72,136
16,32,64,112
16,32,48,96
16,16,48,80
0,32,32,64
32,0,32,64
32,32,32,32
0,0,0,0

根据以下要求编写一个python程序1. Description Ship of Fools is a simple classic dice game. It is played with five standard 6-faced dice by two or more players. - The goal of the game is to gather a 6, a 5 and a 4 (ship, captain and crew) in the mentioned order. - The sum of the two remaining dice (cargo) is preferred as high as possible. The player with the highest cargo score wins the round. Example: - In the first round turn, if a player rolls 6 4 3 3 1 (note we five dice at the beginning), the player can bank the 6 (ship), but the rest needs to be re-rolled since there is no 5. - In the second round turn, if the player rolls 6 5 4 4 (four dice, since the 6 from last turn is banked), the player can bank the 5 (captain) and the 4 (crew). The player has three choices for the remaining 6 and 4. The player can bank both and score 10 points, or re-roll one or two of the dice and hope for a higher score. - In the second round turn, if the player instead rolled 4 4 3 1, all dice needs to be re-rolled since there is no 5.程序需要包含一下几个类.The division of responsibility between the different classes is as follows. - Die: Responsible for handling randomly generated integer values between 1 and 6. - DiceCup: Handles five objects (dice) of class Die. Has the ability to bank and release dice individually. Can also roll dice that are not banked. - ShipOfFoolsGame: Responsible for the game logic and has the ability to play a round of the game resulting in a score. Also has a property that tells what accumulated score results in a winning state, for example 21. - Player: Responsible for the score of the individual player. Has the ability, given a game logic, play a round of a game. The gained score is accumulated in the attribute score. - PlayRoom: Responsible for handling a number of players and a game. Every round the room lets each player play, and afterwards check if any player has reached the winning score.
06-02
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值