Riddler: Simulating Replacing Die Sides

accumulate() function for simulation


March 29, 2020

Notable topics: accumulate() function for simulation

Recorded on: 2020-03-29

Timestamps by: Alex Cookson

View code



Explaining why the recursive nature of this problem is well-suited to simulation


Introducing the accumulate function as a tool for simulation

Creating a condition to call the done function


After creating a function to simulate one round of the problem, using replicate function to run simulation many times


Using qplot function to quickly create a histogram of simulations

Making observations on the distribution of simulations (looks kind of like a gamma distribution)

Observing that the distribution is kind of log-normal (but that doesn't really apply because we're using integers)


Using table and sort functions to find the most common number of rolls

Starting the Extra Credit portion of the problem (N-sided die)


Using the crossing function to set up a tibble to run simulations


Using map_dbl function to apply a set of simulations to each possibility of N sides

Spotting an error in the formula for simulating one round (6-sided die was hard-coded)


Using simple linear regression with the lm function to find the relationship between number of sides and average number of rolls

Reviewing distributions for different N-sided dice

Calculating variance, standard deviation, and coefficient of variation to get hints on the distribution (and ruling out Poisson)