00:00:00
i received an email from a viewer named gilad
levy who had a math question for me pertaining
00:00:06
to the game of dungeons and dragons challenge
your imagination to come alive which is why
00:00:13
i've got all these ridiculous dice out big fan of
crazy dice i've got like the d4 so d for dice and
00:00:19
then four for four sides d12 d20 classic i mean
just for overkill i've also got my d60 and d120
00:00:29
which is completely unnecessary and of course
the staple of the dice world a candy jar's worth
00:00:36
of d6s anyone who visits me in the office can
just um grab a couple of these as a treat and
00:00:41
so gilad's question was not actually about the
numbers or the geometry or anything on this
00:00:46
dice it's about a modification you can make to
dungeons and dragons so if you're rolling a d20
00:00:52
for some reason like you need a high number
so something good happens to your character
00:00:57
so i just roll this roll 12. not bad but what
if you want to give that player an advantage
00:01:02
what you can do is bring in a second identical
dice so instead of rolling just the one dice
00:01:08
you roll one dice and a second phantom dice so on
the main dice i've got 11 and on the phantom dice
00:01:14
i've got four okay at that point you can choose
whichever one you want so you pick the better one
00:01:19
the higher one so you go i rolled an 11. so every
time you roll if you have with advantage you roll
00:01:24
two dice pick your favorite in this case the 16
and discard the other one and gilad's question was
00:01:30
if you're rolling two dice picking the best
one so you have an advantage what is the new
00:01:37
average value what is the expected value from
rolling identical dice at the same time they did
00:01:42
look online first which i appreciate people doing
that before they email me but all i could find
00:01:48
was people putting values into spreadsheets
like on a case-by-case basis and then taking
00:01:53
the average manually and don't get me wrong
big fan of spreadsheets but we can do better
00:02:00
my zeroth step as always was just to simulate it
in software so i put together some terrible python
00:02:06
code uh this is it here it's not great i'll link
to it below if you want to check it out it just
00:02:11
rolls two dice a million times keeps track of
which was the maximum value adds them up and
00:02:17
gives you the average at the end and i've got my
laptop here running that exact code which you can
00:02:23
now see next to me here so uh this line that's
just saying run some python code that i've called
00:02:29
higher of two rolls if we run that it asks you how
many sides on your dice let's do the d20 doing a
00:02:36
million rolls and there it is the average result
of rolling to attacking the highest is about
00:02:41
13.829 you think was that accurate doing it a
million times so we can redo the same thing again
00:02:47
let's do another 20. this time 13.83 okay so we're
always getting about 13.83 uh 420 give or take so
00:02:57
we can be reasonably confident that's roughly the
right value and of course uh let me clear that you
00:03:02
can do that so we did that for uh let's you know
do the d12 then you're gonna get an average of
00:03:08
about eight and a half we try it for our
friends the d6 over here it's going to be
00:03:12
around about 4.47 ish so now we can get these
results and we're confident they're correct
00:03:20
now we have to crack the logic behind it with
some tweaks to the code instead of just getting
00:03:27
the average value you can of course get it to spit
out the probability of getting any given value and
00:03:32
that's exactly what gilad did and they did a plot
for the record a single d20 every single face has
00:03:39
a 1 in 20 chance of coming up that means they're 5
each and if we did the chart for this it would be
00:03:45
a bar chart where every single number is five
percent perfectly flat and i've not joined it
00:03:50
together as a line because it doesn't make sense
to have an in-between value i've just done a bar
00:03:55
for every single value to show you the percentage
and what gillett had plotted was the same thing
00:03:59
but with rolling for advantage and you can see
you get a perfectly straight line it starts with a
00:04:07
0.25 percent chance of getting a one and then it
goes up half a percent each point every single
00:04:16
number you go up on the dice until 20 which is
the most likely is the biggest is a 9.75 chance
00:04:23
and we're like that's interesting and we'd run
the simulation over and over and we checked our
00:04:26
numbers and they add up to one so the whole thing
holds together so now we had two questions one was
00:04:32
why when you plot the probability for each of the
different faces with advantage do you get this
00:04:39
perfectly straight arrangement of the
probabilities and secondly the average girl had
00:04:45
noticed is always about two-thirds of the maximum
value i say about two-thirds it's going to be some
00:04:50
weird number probably involving e it won't be that
simple but they had spotted roughly two-thirds and
00:04:55
we had to answer both those questions and my
goodness i was not expecting the result we got
00:05:12
this video is brought to you by jane street
who are also supporting the 2022 international
00:05:18
mathematical olympiad try a sample puzzle at
the end of this video gene suite have actually
00:05:23
provided a brand new imo style puzzle that
you can try we'll put it at the end of the
00:05:27
video but it's based on that cosahedron not the
dice just the actual shape super interesting
00:05:32
check that out at the end but for now we're
going to try and crack what's going on with
00:05:36
the probabilities when you roll for advantage
we're not going to do the d20 though that's a
00:05:40
little bit too much we're going to start
with our friend the d6 whoops that's gone
00:05:51
here i have some d6 and we can look at what
happens if you roll two distinguishable d6
00:05:57
so i've now got a green one and a blue one at the
same time and uh each of them could have oh i've
00:06:01
got two fives there you go each of them could have
any of six possible values of four and a three
00:06:06
so we can do a two-way plot where we've got
all the values the blue can have on one axis
00:06:11
or the values the green can have on the other
axis and inside each square we can put what
00:06:16
that combination is and importantly each of
the squares has a 1 in 36 chance of happening
00:06:22
because that's just 6 squared we could now go
through and color in what values we would get
00:06:29
if we rolled that pair and we picked the highest
so the only way to get one is the bottom corner
00:06:36
so there's a 1 in 36 chance of doing that there
are three ways you can get two if you get any of
00:06:41
these you would choose 2 as the biggest number so
that's a 3 out of 36 chance here's all the ways
00:06:47
you could get three and then four and then five
and finally um six and then i realized what i was
00:06:52
looking at is the same bar chart from before in
fact we can just stand these up and there you are
00:07:00
that's our bar chart because the probabilities are
proportional to the number of squares and that's
00:07:05
why you get that straight line it's because if you
add consecutive odd numbers 1 3 5 7 and so on you
00:07:13
get the square numbers 1 4 9 and up in this case
36 and i was so excited when i realized this and
00:07:21
so we can see the numbers for the case of the d6
because it's 1 over 36 3 over 36 5 over 36 and so
00:07:28
on 36 is just the number of faces squared so if
we want to go back to our d20s it's just 1 over
00:07:35
20 squared wow one over 400 that's 0.25 which is
why we had 0.25 likelihood for getting a 1 if you
00:07:46
roll with advantage and then it goes up by double
that every single time so the next one up is 0.75
00:07:53
all the way up to 9.75 percent that's where the
straight line comes from i'm so pleased when you
00:07:59
start with a probability question and then you can
turn it into a geometry question that then gives
00:08:04
you your probability bar chart for free ah so
pleasing but now where does the average come from
00:08:13
it's working it out time so we're gonna do this
in general for an insider dice bear with me
00:08:31
okay so we don't know how many sides the
dice has we got n sides but we know it's
00:08:35
going to be like this that's going to get too
higher every single time until you get to n
00:08:39
each of these represents a probability of 1 over
n squared because we know there's a total of
00:08:46
n squared of these in because if you clap small
back down again you get your square so good the
00:08:52
question now is for each of these values
on the dice which i'm going to call these x
00:08:58
just because we've already used n how do we
know how many blocks are above them well this
00:09:02
is just the odd numbers so that's 2x uh let's
go minus one so it starts at the right point so
00:09:09
uh so we know each of these has two times x minus
one blocks above them and the probability is then
00:09:16
that times one over n squared so i'm going to put
that on n squared so there you go so for any value
00:09:25
x on an inside a dice this is the probability
of getting that if you roll two of them with
00:09:30
advantage so what's the average value well it's
the chance of getting a value of one times one
00:09:35
chance of getting two times two chance of getting
three times three this is the chance of getting x
00:09:40
times x and then you gotta add them all up future
matt here in the edit because i realized past
00:09:48
matt was getting a bit confused i did have to
do the summation of each of these values the
00:09:53
probabilities times the value of each face x but
i put a one over n at the front which you can see
00:09:59
there i was getting ahead to when i wanted to do
the ratio and then i changed my mind so later on
00:10:03
you can see when i was bringing the uh 1 over n
squared at the front because it's independent of x
00:10:09
and the summation i put an n there to cancel
it out i don't know what i was thinking but the
00:10:12
point is it all works don't worry about the top
line everything is perfect from here so it ends
00:10:19
up being uh 1 over n squared outside the sum of
what we had before but now over here we've only
00:10:27
got 2x minus 1 times x and i just worked out what
that was before and i remembered it it's 1 over
00:10:34
n squared and then this thing here is n on 6
times n plus 1 times 4 n minus 1. and that's
00:10:44
it and you're like hang on i can cancel this out
because if i've got an n squared there and an n
00:10:48
there what i've actually got out the front is just
a 1 over 6 n and that's it that's our equation and
00:10:58
sure enough it works if you put n equals 20 into
that you get out 13.825 exactly what we got from
00:11:08
our simulations if you put in n equals 6 you get
the same result that we got from our simulations
00:11:13
this is the equation for the average value for
any n-sided dice if you roll two of them with
00:11:20
advantage all we have to do now is work out where
that ratio of approximately two-thirds comes from
00:11:27
and that's not so bad to do because the ratio
we're talking about is the ratio of this average
00:11:32
to n so we're just going to divide this whole
thing by n which yes i could just squared
00:11:37
that in what i'm actually going to do is i'm
going to rewrite that as 1 over 6 n plus 1
00:11:44
on n 4 n minus 1 on n convince yourself that's the
same these are all multiplied together we want to
00:11:52
know what is the limit as n goes to infinity
like in theory as we approach infinitely large
00:12:01
n sided dice what would this ratio be well
if well a six is a sixth that's not changing
00:12:08
n plus 1 over n as n goes to infinity that's
just going to equal that's going to equal
00:12:12
1. that's easy put that in there right okay
and 4n minus 1 over n as n goes to infinity
00:12:19
that's just going to equal 4. so actually it's
1 6 times one times four four on six it equals
00:12:29
exactly two-thirds i couldn't believe it so
it's not just like oh this is roughly two-thirds
00:12:37
it's probably the inverse of root two it's
probably something involving e no it's exactly
00:12:42
two-thirds i so there you are so in general just
as a rule of thumb if you're rolling two dice
00:12:48
with advantage the average result you're going
to get is two-thirds of whatever the dice is
00:12:55
easy but hang on what if we were rolling three
dice hey standup maths matt here so i'm building
00:13:06
a model of our diagram from before out of dice
so it's now the dice chart made from dice which
00:13:12
is deeply pleasing but it does mean you have
to ignore the numbers i'm just using these to
00:13:17
represent the different regions little areas
in our two-way uh sample space from before so
00:13:23
you've got uh what the first ice could be going
you know across horizontally one two three four
00:13:28
and eventually i couldn't build five and six
and now the second dust goes straight up so one
00:13:32
two three four and then five and six and so the
blue is one one so one's the biggest number the
00:13:37
orange ones here are all the combinations where
they're ones and twos and so two is the biggest
00:13:42
number and then you got where three is the biggest
number four so biggest number and i could build
00:13:46
five and six same as before however we now need
to add a third dice so instead of having a 2d plot
00:13:54
with two axes we're going to swing this sideways
and have a third axis coming out in this direction
00:14:02
we've got three perfectly good dimensions let's
use them so now i can start building up this
00:14:08
here we go direction oh um i need to put these
wait i'm going to take these off for a second
00:14:13
oh i should have glued these together so i
did there it is right so there's the shell
00:14:19
now of in the 3d plot all the combinations
of the three d6s which are ones and twos
00:14:26
we can then add on the shell for uh threes because
there's no one two three so these are all the dice
00:14:32
where three is the biggest value and then you've
got all the fours uh all the fives finally all the
00:14:38
ones where six is the biggest uh value on the
outer shell and now you can see how much of an
00:14:45
advantage rolling three and picking the highest
is if you rolled a single d6 by itself one and
00:14:51
six are equally likely if you roll three and
pick the biggest there's only one one of these
00:14:59
out of uh 216 possible options where you get all
ones and there's 91 cases where 6 is the biggest
00:15:09
number so instead of being equal it's now 1 to 91
just ridiculous and these aren't 2d areas anymore
00:15:16
they're not 1 over 36 which is the number of faces
squared they're 1 over the number of faces cubed
00:15:24
so they're one over 216. so each of these volumes
is a 1 over 216 chance of happening there are 216
00:15:31
of them and then you can work out how many there
are from each layer but unlike the odd numbers
00:15:38
there's no obvious formula for these values i mean
they must have some kind of pattern and they do
00:15:43
these are the centered hexagonal numbers so if i
hold that one nice and still right in the middle
00:15:49
and you get that in focus you've got one right
in the center and then you've got concentric
00:15:53
rings which are hexagonal numbers so there's
one and then six around it and then so on it's
00:15:59
so good and we can use that equation to do the
working out for the three dice case let's do it
00:16:05
as soon as i get up our equation for the odd
numbers is easy enough it's just 2x minus 1
00:16:13
and if you're unfamiliar the odd numbers go 1
3 5 7 and so on and x is position one gives you
00:16:22
one when x is two position two it gives you three
now the center hexagonal numbers they go one seven
00:16:29
pretty sure it's nineteen yes nineteen thirty
seven i've written them down down there thirty 37
00:16:37
61 91 and that 91 that was the final outer
shell of this and those are all the shells
00:16:43
below we need now some formula where you put it
as x is one and you get one you put in x as two
00:16:49
you get 7. and that happens to be written it down
as well it's 3. actually let's do this in blue
00:16:55
so it matches it is 3 times x outside of x minus
1 plus one you will occasionally see that with a
00:17:05
plus where they've zero indexed this list but i'm
against my better judgment uh starting from one so
00:17:12
there's our formula for how big each shell is of
all these different ones here so now we can get
00:17:19
rid of all this ridiculous extra bits and we're
going to build that up into the equation for what
00:17:25
the average value is when you roll three dice and
with advantage pick the biggest value so first of
00:17:32
all that's the value of each shell we have the
probability of each shell which is the number of
00:17:39
cubes multiplied by the probability that each
volume represents which as we established before
00:17:44
is just one over the number of faces squared so
i can check in also cubed took a cubed down there
00:17:51
that's the probability we're now going to multiply
that by the value which is the whole thing by h1
00:17:56
is x then we need to add them all up from the
first face eq equals one up to the nth face
00:18:03
future matt here to again clarify past matt got
a bit excited and put the one over n at the front
00:18:09
because that's when you want to compare the
average value as a ratio to the number of
00:18:14
sides but then i decided in hindsight actually i
want to look at just the equation for the average
00:18:20
first and then divided by n to get the ratio
sorry back to past mat and i can give you
00:18:26
the grand conclusion the average value if
you roll three dice and just pick the highest
00:18:34
is one over this time for n pretty exciting
times n plus one times 3n minus 1. nice and neat
00:18:48
check that out and so we can go through and
plug a bunch of values in i did put in the value
00:18:53
for a d20 so if your n equals a 20-sided dice
you now your average value for a d20 comes out at
00:19:02
15.4875 there we go so just over three quarter
it's about three quarters before it was two-thirds
00:19:18
oh that's too neat too neat to not be true okay
let's find out let's find out so i'm going to get
00:19:23
rid of our working out down here oh my goodness
we've now got at the top there that's our value
00:19:28
for the average we want to know now what that is
relative to n so we want to divide that by n again
00:19:35
so now this is the average on n so we just put a
squared down there and oh actually that means we
00:19:41
could rearrange it we could take that n squared
like we did before and we could chuck one over
00:19:45
there we could chunk one over there and now we
want to know as what's the limit as n goes to
00:19:53
infinity of this well it's going to be the 4th is
still going to be the same that's going to be 1
00:19:59
times 1 that's going to be 3 it is it's three
quarters there you are okay so it turns out if you
00:20:07
roll two dice and pick the highest is two-thirds
if you roll and just for comparison you put that
00:20:14
over there so when we had two dice the oh wait m
if we had m dice so we had two dice case that was
00:20:20
two thirds this here this is our three dice this
is the m equals three dice case is three quarters
00:20:30
the big question now on everyone's lips
is if we worked out the m equals four case
00:20:37
you roll four dice you pick the highest will
the pattern continue will it be four fifths
00:20:46
there's only one way to find
out and it involves hypercubes
00:20:52
right if we're rolling four dice at once
we're going to need four orthogonal directions
00:20:57
on our space of all possible results which means
we're gonna need more dice more glue and more
00:21:02
dimensions and i'm not gonna start gluing together
as tempting as it is hypercubes but in theory
00:21:09
each time you add another number on the dice
you're just it's a bigger and bigger hypercube
00:21:14
of possibilities and you have to work out the four
dimensional shells how many 4d content like hyper
00:21:22
volumes there are in uh and you know what we're
just going to work it out using algebra because we
00:21:28
know what the equation is for each of these like
each of the shells and four dimensions because
00:21:33
it's just the difference between two consecutive
hypercubes it's x to the four subtract x minus one
00:21:39
to the four and spoiler we could have done that
um with all the other ones anyway point is we've
00:21:44
now got the sequence of numbers that goes 115 65
175 269 ah what's the pattern well these are the
00:21:53
rhombic dodecahedral numbers so we went from
the odd numbers to the hexagonal numbers
00:22:01
to now this is the rhombic dodecahedron the
greatest of all the dodecahedra and that actually
00:22:09
makes sense because if you've got a square the
the diagonal cross section like the center cross
00:22:16
section of a square is a line and actually that's
why when you look at it from the corner you see a
00:22:21
line but it's wrapped around and the middle cross
section of a cube is a hexagon which is why if you
00:22:28
look at it perfectly quarter on it looks like a
hexagon and they're centered hexagonal numbers
00:22:33
and as some of you may know if you get a 4d cube
and you cut it perfectly in half on the on the
00:22:41
hyper diagonal the cross section of the 4d cube
is a 3d rhombic dodecahedron it's so pleasing
00:22:50
think of it like the 3d hexagon and and that's
why the numbers if you add together consecutive
00:22:57
centered rhombic or decahedral numbers you get
the hypercube numbers ah maths the point is
00:23:04
we've got the equation we can crunch it through
it like we did before indeed i've done it give
00:23:08
it a go it's good fun and it ends up four fifths
it's four fifths if you roll four you don't have
00:23:14
to worry about the hypercubes and the runway
decahedra all that jazz if you roll four dice
00:23:19
and pick the highest value you will get on average
four-fifths of whatever the value of the dice is
00:23:26
sort of some of you have already thought does
this work in the opposite direction so it seems
00:23:31
very very likely that if you roll m dice you end
up on average if you just take the highest one
00:23:39
getting m divided by m plus one times however
many faces you've got that seems very very likely
00:23:46
and we haven't proved that carries on going
up pretty sure it does if you go backwards
00:23:52
you put in the case for one dice a single
one m it should be half it's not half
00:23:58
it's well it would be it is in the case of if
there are infinitely many faces as it tends to
00:24:04
infinity which is how we were working out it's
exactly half but it's not exactly half it's a
00:24:08
half of the value so the average volt roll
on a d6 is three and a half the average roll
00:24:15
on a d d20 here we go it's 10 and a half on my d60
30 and a half because there's an even number of
00:24:23
faces and you're always getting a whole
number in fact before when we worked out the
00:24:29
average for rolling d20s 15 which is three
quarters and a half so i my conjecture is
00:24:40
it's always for m dice rolled with advantage
it's m divided by m plus one times n
00:24:48
plus a half feel free to prove disprove or
extend my conjecture i think it's good enough
00:24:56
for the size and number of rolls in the standard
dnd game so there you are if anyone ever says
00:25:02
there's no practical reason why you want to know
that the central cross section of a 4d hypercube
00:25:07
is a 3d rhombic dodecahedron now you
can just throw some dice in their face
00:25:11
super applied mathematics anyway thank you so much
for watching this video and thanks to jane street
00:25:16
who not only sponsor this video and my
channel they also sponsor the international
00:25:21
mathematical olympiad which is happening this
year from the 6th to 16th of july in oslo norway
00:25:28
and it's where teams all around the world send
six pre-university math students to compete in
00:25:34
like it's like the mass version of the hunger
games it's like the number games they all have to
00:25:40
run out and get like the best calculator there's
nothing to do like that no they they solve very
00:25:45
difficult mass problems and oh my goodness they
have some serious problems so jane street have
00:25:49
set a sample problem if you would like to try it
and they say imagine you're on a huge icosahedron
00:25:56
so actually like this like a like a d20 but ignore
the numbers imagine you start on a random vertex
00:26:03
and you can choose to walk to any of the other
vertices nearby but when you get there you're
00:26:09
completely disorientated you can't see where you
came from you can't see any of the other vertices
00:26:14
all you can do is leave a marker leave a stone
that you can have as many stones as you want
00:26:21
of as many different colours as you want so you
leave a stone of some color and then you walk to
00:26:26
another vertex but when you get there again
totally disorientated but you can look down
00:26:31
to see if you've previously left a stone there and
you can leave or do whatever you want with your
00:26:35
marked stones and the question is at the beginning
of your journey what is the minimum number of
00:26:41
stones you have to take with you so you know for
certain at some point you can say i am definitely
00:26:49
at the exact opposite vertex of where i started
and they've got all the exact wording of that if
00:26:56
you want to double check it and they've got some
other variations of the same puzzle in terms of
00:27:01
being on infinite planes or being on other shapes
at janestreak.com imo 2022 so you can check that
00:27:10
out you can see the puzzle try it for yourself
it's good oh my goodness it's fiendish but you
00:27:14
can give it a go and of course you can keep an eye
on the imo see who wins number games this year and
00:27:22
so there you are huge thanks to jane street for
making the imo possible and indeed my channel