Advertisement
Guest User

euromillion_run

a guest
May 24th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 0.53 KB | None | 0 0
  1. combn(50, 5, simplify=FALSE) %>%  # Get all (sorted) combinations of 5 choices from 1 to 50, i.e. 5,20,21,22,45
  2.     lapply(diff) %>%  # get the differences between consecutive values, i.e. 15,1,1,13
  3.     lapply(rle) %>%  # convert into runs of values, ie (1x15), (2x1s), (1x13)
  4.     sapply(
  5.         # do any of them give a run of 2 or more 1s?
  6.         # (indicating 3 or more values with difference 1)
  7.         function(x) any(x$lengths[x$values==1] >= 2)
  8.     ) %>%
  9.     mean # get the average value, which gives us the proportion (out of 1) of values that returned TRUE
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement