forked from CrumpLab/LabJournalWebsite
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHarderProblems.Rmd
More file actions
123 lines (112 loc) · 2.23 KB
/
HarderProblems.Rmd
File metadata and controls
123 lines (112 loc) · 2.23 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
---
title: "Harder Problems"
output:
html_document:
toc: true
toc_float: true
collapsed: false
number_sections: false
toc_depth: 1
#code_folding: hide
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(message=FALSE,warning=FALSE, cache=TRUE)
```
##Progress on Some Harder Problems in R
###1. Fizz Buzz Problem
```{r}
for(i in 1:100)
if(i%%3==0){
print("Fizz")}
if(i%%5==0){
print( "Buzz" )
}else(i%%3==0 && i%%5==0)
print( "FizzBuzz" )
```
###2. Frequency Counts
```{r}
Sent<-" Here I am doing harder problems"
table(unlist(strsplit(Sent,split="")))
```
###3. Random number generator
```{r}
a<-runif(100,0,100)
hist(a)
```
###4. Create a multiplication table
```{r}
e<-c(2,3,1,5,6,8)
e*3
```
###5. Alphabet
```{r}
Alpha <- c("A","B","C","D","E")
NewA <- unique(Alpha)
sampleA<- sample(NewA)
encryption_key <- data.frame(NewA,sampleA)
encrypt_numbers <-function(input_sequence,key){
encrypted_sequence<-c()
for(i in 1:length(input_sequence)){
original_number <- input_sequence[i]
new_number <- key[key$numbers==original_number,]$scrambled_numbers
encrypted_sequence[i] <- new_number
}
return(encrypted_sequence)
}
encrypt_numbers(Alpha,encryption_key)
```
###6. Snakes and Ladders
```{r}
save_rolls <- c()
for(sims in 1:1000){
total_sum<-0
number_of_rolls<-0
while(total_sum < 25){
number_of_rolls <- number_of_rolls+1
total_sum <-total_sum+sample(c(1,2,3,4,5,6),1)
}
save_rolls[sims] <- number_of_rolls
}
mean(save_rolls)
```
###7. Roll Dice
```{r}
total_sum<-0
number_of_rolls<-0
while(total_sum < 12){
number_of_rolls <- number_of_rolls+1
total_sum <-total_sum+sample(c(1,2,3,4,5,6),1)
}
number_of_rolls
```
```{r}
total_sum<-0
number_of_rolls<-0
while(total_sum < 11){
number_of_rolls <- number_of_rolls+1
total_sum <-total_sum+sample(c(1,2,3,4,5,6),1)
}
number_of_rolls
```
```{r}
total_sum<-0
number_of_rolls<-0
while(total_sum < 2){
number_of_rolls <- number_of_rolls+1
total_sum <-total_sum+sample(c(1,2,3,4,5,6),1)
}
number_of_rolls
```
```{r}
total_sum<-0
number_of_rolls<-0
while(total_sum < 3){
number_of_rolls <- number_of_rolls+1
total_sum <-total_sum+sample(c(1,2,3,4,5,6),1)
}
number_of_rolls
```
###8. Monte Hall
###9.100 Doors
###10.99 Bottles
###11. Tic-Tac-Toe