You and a dragon have agreed to let dice rolls determine whether it eats you or not.
The dragon will roll a single die, of x sides. You will roll several dice, of y sides each. The total number of sides on your dice add to x.
The dragon will let you go uneaten if your total throw matches or exceeds theirs.
What are your chances of survival?
Solution Stats
Problem Comments
11 Comments
Solution Comments
Show comments
Loading...
Problem Recent Solvers166
Suggested Problems
-
6710 Solvers
-
1620 Solvers
-
12453 Solvers
-
823 Solvers
-
1449 Solvers
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
Hello, Erin. It's a really interesting problem. According to Solution 1539769, I think it would be worthwhile for you to include some (small) tolerances within the assert statements in your Test Suite, to allow for rounding due to computations in 'double precision'. —DIV
I agree with David.
The solution to this problem was stupidly easier than I first thought. Expected value of your own throws is all that really matters here.
The test suite has been updated with additional test cases and a check against a tolerance instead of using isequal()
Is test case 7 generating feasible game conditions?
For example:
x = randi([10 100],1,10) -> generates 10 random numbers between 10 and 100, inclusively, a potential result would be:
x =
85 43 18 92 88 48 35 97 78 100
In test case 7, y=5 (rolling 5 sided die); and if sum of all y-sided dice must equal x (sides of dragon die), then x mod 5 must equal 0, or in general, x mod y = 0. Depending on the nature of the reference solution, this might get overlooked. Simulating test cases allows for the use of an approximation method based on the law of large numbers; however, a simulation would not be possible for conditions requiring fractional dice. As such, I would assume the reference solution is limiting the solution methodology/framework to leveraging probability theory.
Whereas, this still encourages rigorous mathematical reasoning and analysis skills, it discourages the solver from using the power of computational computing to approximate solutions for difficult problems using much simpler mathematical methods, which to me feels like the general purpose behind using MATLAB in the first place.
I am so lost, I need help :(
@AJ work out the probability of survival (as a function of x and y) on paper, and then implement it. You don't need to simplify much on paper BTW, keeping sums etc. is fine.
Can someone clear up this 2 confusions i have about the problem.
The problem says i roll several dice of y sides.How many is that? so i just put a rand 100 or smth to see how many times i'll roll?
And second is since i know my dice have y sides how can the sum of the sides be x since x is random?
@Alex You roll x/y dice, each of which has y sides. Each die is rolled once. x is not random; instead, it's supplied to your function as an argument.
I was trying to calculate the probabilities of each point and add them up, but when I explained this problem to my son, I suddenly realized that due to symmetry, the problem became very simple.
Is the test 7 suitable for the problem?
Generally,we can take a random number as x,which may get an illegal n.Of course we can change some assumptions.However the question isn't stated clearly.