acm
cz
acm
cz
Dept. of Computer Science and Engineering, Czech Technical University in Prague
Faculty of Mathematics and Physics, Charles University in Prague
Faculty of Electrical Engineering and Computer Science, Technical University of Ostrava
Faculty of Informatics and Information Technologies, Slovak University of Technology
Faculty of Informatics, Masaryk University
Faculty of Management Science and Informatics, University of Zilina
CTU Open Contest 2008
Alea iacta est
alea.c, alea.C, alea.java, alea.p
Isaac B. Manfred always dreamed about being a terribly rich man. When he was a child, he
played with banknotes instead of toys. After finishing high school, he quickly became a senior
broker in one famous bank. His career rose rapidly and also did his wealth. Unfortunately, the
bank crisis changed his life significantly. The broker suddenly became broke.
To gain his money back, I.B.M. spent a lot of time in casinos, trying to earn some money there.
Most people who ever tried to get rich in casinos are actually very poor today. But this does
not include I.B.M. He is a very clever guy and instead of blindly betting his money, he carefully
studies various games and computes the probabilities of losing or winning. First, he tried his
luck with Roulette and Blackjack, but found out that the odds of winning a fortune are low.
Recently, I.B.M. started to study dice games. He found several of them similar to a trademarked
game called Yahtzee! The rules sometimes vary but basic principles are the same. To give you
an idea, we will describe a simplified version of such rules.
The game consists of rounds. In each round, a player rolls five dice. After the first roll, it is
possible to keep some of the dice and re-roll the rest of them. Any number of dice can be re-
rolled (including none or all of them). If the re-rolled dice still do not fit the player’s intentions,
it is possible to re-roll some of them again, for the third and final time. After at most two such
re-rolls, the player must assign the result to one of possible combinations and the round is scored
according to that combination.
The following table shows the list of combinations, conditions that must be satisfied to use them,
and the number of points scored when the combination is used.
Combination
Condition
Scoring
Example
Score
Ones
At least one 1.
One point for each 1.
11245
2
Twos
At least one 2.
Two points for each 2.
12226
6
Threes
At least one 3.
Three points for each 3.
12455
0
Fours
At least one 4.
Four points for each 4.
44444
20
Fives
At least one 5.
Five points for each 5.
12345
5
Sixes
At least one 6.
Six points for each 6.
14666
18
Sequence
(12345)or(23456).
Thirty points.
12345
30
Ful l House
Three of the same value and
a pair of another value.
Sum of all dice values.
22555
19
Four of a kind
Four of the same value, the
fifth one di.erent.
Sum of all dice values.
44445
21
Five of a kind
All five of the same value.
Fifty points.
11111
50
Chance
None.
Sum of all dice values.
24556
22
A small example: The player rolls 2, 3, 6, 6, 5. The two 6’s are kept and the three remaining
dice re-rolled, they give new values: 1, 1, 6. The player may now choose to score 20 points
immediately for a Full House. Instead, he or she decides to re-roll the two 1’s again, in hope
there will be another 6. The dice give 4 and 5 and the player will score either 18 points for Sixes
or 27 points for Chance.