forked from CrumpLab/7709Rproblems
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfizzbuzz.Rmd
More file actions
70 lines (60 loc) · 1.44 KB
/
fizzbuzz.Rmd
File metadata and controls
70 lines (60 loc) · 1.44 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
---
title: "Fizzbuzz"
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 fizzbuzz 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}
total <- 1
for (i in 2:100) {
if (i %% 3 == 0) {
if (i %% 5 == 0) {
total <- paste(total,"FizzBuzz", sep = ", ")
}
else {
total <- paste(total,"Fizz", sep = ", ")
}
}
else if (i %% 5 == 0) {
total <- paste(total, "Buzz", sep = ", ")
}
else {
total <- paste(total, i, sep = ", ")
}
}
print(total)
```
### Matt's Code
```{r,eval=F}
answer <- 1:100
for(i in 1:100){
if(i%%3 == 0) answer[i] <-"fizz"
if(i%%5 == 0) answer[i] <-"buzz"
if(i%%5 == 0 & i%%3 ==0) answer[i] <-"fizzbuzz"
}
print(answer)
```
### Zoren's code
```{r,eval=F}
result <-1
for (j in 2:100){
if(j %% 3 == 0){
if (j %% 5 == 0) {
result <-paste(result, "FizzBuzz", sep = ",") }
else {result <- paste(result,"Fizz", sep = ", ")
}
}
else if (j %% 5 == 0) {
result <- paste(result, "Buzz", sep = ", ")
}
else {
result <- paste(result, j, sep = ", ")
}
}
print(result)
```