forked from CrumpLab/7709Rproblems
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsnakesladders.Rmd
More file actions
38 lines (33 loc) · 971 Bytes
/
snakesladders.Rmd
File metadata and controls
38 lines (33 loc) · 971 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
---
title: "Snakes and Ladders"
author: "Matt"
date: "2/12/2019"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
This document contains student solutions to the snakes and ladders problem. Students will add to this file using the outline below. Write your name (using three hashtags), then below create an R code block and insert your code. Save the .rmd file, then knit the document to update the html output. Then submit a pull request to merge your changes to the main repository.
### Jeff Kravitz
```{r}
move <- 0
count <- replicate(1000, 0)
game_grid <- data.frame(c(3,6,9,10,14,19,22,24),c(11,17,18,12,4,8,20,16))
for (i in 1:1000) {
spot <- 1
while (spot <= 25) {
move <- sample(1:6, 1)
spot <- spot + move
for (i in 1:8) {
if (spot == game_grid[i,1]) {
spot <- game_grid[i,2]
}
}
count[i] = count[i] + 1
}
}
avg_moves <- mean(count)
print(avg_moves)
```
a### Zoren's code
unfinished