Riddler: Simulating a Non-increasing Sequence

Simulation

Notable topics: Simulation

Recorded on: 2020-04-05

Timestamps by: Alex Cookson

## Screencast

## Timestamps

Introducing accumulate functon as a possible solution (but not used here)

Using sample function to simulate 1000 rolls of a 10-sided die

Explanation of dividing sample rolls into streaks (instead of using logic similar to a while loop)

Using cumsum function to separate 1000 rolls into individual sequences (which end when a 0 is rolled)

Using lag function to "shift" sequence numbering down by one row

Using cummax and lag functions to check whether a roll is less than the highest value rolled previously in the sequence

Fixing previous step with cummin function (instead of cummax) and dropping the lag function

Finished simulation code and starting to calculate scores

Using -row_number function (note the minus sign!) to calculate decimal position of number in the score

Investigating the distribution of scores

Using seq function in the breaks argument of scale_x_continuous to set custom, evenly-spaced axis ticks and labels