This is an extension of the tidytuesday assignment you have already done. Complete the questions below, using the screencast you chose for the tidytuesday assigment.
library(tidyverse)
set.seed(2020)
sim <- tibble(roll = sample(0:9, 1e4, replace = TRUE)) %>%
mutate(group = lag(cumsum(roll == 0), default = 0)) %>%
group_by(group) %>%
filter(roll <= cummin(roll))
scores <- sim %>%
mutate(decimal = roll * 10 ^ -row_number()) %>%
summarize(score = sum(decimal))
This data is a puzzle that can use R to solve. The puzzle/riddle is that you have a fair 10-sided die, roll the die and each time the score is going to be the number shown divided by 10, roll over and over and If the digits show the die is less than or equal to the last digit of your score,that roll becomes the new last digit of your score, the game ends when you roll a 0. The goal is to simulate many scores and find out what the average final score in the game is. This sequence is always going to be non-decreasing. The variables are that the digit always has to be equal to or less than the cumulative min, always decreasing. In the dataset of scores there is a group and score column. In the dataset of sim there is a roll and group column.
Hint: One graph of your choice.
scores %>%
summarize(mean(score))
## # A tibble: 1 x 1
## `mean(score)`
## <dbl>
## 1 0.478
scores %>%
ggplot(aes(score)) +
geom_histogram(binwidth = .001) +
scale_x_continuous(breaks = seq(0, 1, .1))
The graph shows a leaning zero distribution showing a shape because you cannot go up once you have gone down within a decimal point. It shows a fractal pattern because within the shapes and chunks you cannot go up once you have gone down. The graph better illustrates the data and makes the dataset more clear/easier to understand.