# Riddler: Simulating Replacing Die Sides

accumulate() function for simulation

Published

March 29, 2020

Notable topics: accumulate() function for simulation

Recorded on: 2020-03-29

Timestamps by: Alex Cookson

View code

## Timestamps

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

accumulate

Introducing the accumulate function as a tool for simulation

Creating a condition to call the done function

replicate

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

qplot

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)

tablesort

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

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

crossing

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

map_dbl

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)

lm

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)