From d1300ca15ff4a02450fd522f171cb093bbea67b6 Mon Sep 17 00:00:00 2001 From: Riley Ellingsen Date: Thu, 11 Nov 2021 19:26:42 -0500 Subject: [PATCH 1/3] commit script for first problem - game summary --- UWvMSU_Summary.Rscript | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 UWvMSU_Summary.Rscript diff --git a/UWvMSU_Summary.Rscript b/UWvMSU_Summary.Rscript new file mode 100644 index 0000000..9b5dd3c --- /dev/null +++ b/UWvMSU_Summary.Rscript @@ -0,0 +1,26 @@ +#Parse score data for each team +data <- read.table("UWvMSU_1-22-13.txt",header = TRUE, stringsAsFactors = FALSE) +UWscores <- data[data$team=="UW",] +MSUscores <- data[data$team=="MSU",] + +#Create cummulative totals for each team +UWtotal <- numeric(length(UWscores$score)) +for(row in 1:length(UWscores$score)){ + UWtotal[row] <- sum(UWscores$score[1:row]) +} + +MSUtotal <- numeric(length(MSUscores$score)) +for(row in 1:length(MSUscores$score)){ + MSUtotal[row] <- sum(MSUscores$score[1:row]) +} + +# Assign cummulative scores and totals to coordinates and plot on one graph +x1 <- UWscores$time +y1 <- UWtotal +x2 <- MSUscores$time +y2 <- MSUtotal +plot(x1,y1,type = "l", pch=19, main = "UW vs. MSU Basketball + 1-22-13", col="red", xlab = "Time (min)", ylab = "Score") +lines(x2,y2, pch=18, col="blue", type = "l", lty=2) +legend(25, 15, legend=c("UW", "MSU"), col=c("red","blue"), lty = 1:2, cex = 0.8) + From b06162b67ed99580b1a4ca348b23a2a5a3694d4e Mon Sep 17 00:00:00 2001 From: Riley Ellingsen Date: Thu, 11 Nov 2021 20:00:10 -0500 Subject: [PATCH 2/3] commit script for second problem - Guess My Number Game --- GuessMyNumberGame.Rscript.R | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 GuessMyNumberGame.Rscript.R diff --git a/GuessMyNumberGame.Rscript.R b/GuessMyNumberGame.Rscript.R new file mode 100644 index 0000000..a68edc7 --- /dev/null +++ b/GuessMyNumberGame.Rscript.R @@ -0,0 +1,29 @@ +##Guess My Number + +###A game that allows user to guess a randomly generated number and gives feedback +###for correct and incorrect guesses. + +#Generate a random number between 1 and 100 +range <- 1:100 +sample(range, 1) + +randonumber <- sample(range,1) + +# Write a for loop that allows a user to guess up to ten times +# Output 'Lower' if guess is greater than random number +# Output 'Higher' if guess is less than random number +# Output 'Correct!' if user guesses random number + +for (i in 1:10) { + guess <- readline(prompt = "Guess:") + if (guess > randonumber){ + print("Lower") + } else if (guess < randonumber){ + print("Higher") + } else { + print("Correct!") + break + } + } + + \ No newline at end of file From d8eba3902e9b67f85bb098eba55354e98d64ffad Mon Sep 17 00:00:00 2001 From: Riley Ellingsen Date: Thu, 11 Nov 2021 20:53:13 -0500 Subject: [PATCH 3/3] fixed a bug that didn't allow for single or triple digit inputs --- GuessMyNumberGame.Rscript.R | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/GuessMyNumberGame.Rscript.R b/GuessMyNumberGame.Rscript.R index a68edc7..522c696 100644 --- a/GuessMyNumberGame.Rscript.R +++ b/GuessMyNumberGame.Rscript.R @@ -4,10 +4,9 @@ ###for correct and incorrect guesses. #Generate a random number between 1 and 100 -range <- 1:100 -sample(range, 1) -randonumber <- sample(range,1) +range <- 1:100 +randonumber <- sample(range, i) # Write a for loop that allows a user to guess up to ten times # Output 'Lower' if guess is greater than random number @@ -16,6 +15,7 @@ randonumber <- sample(range,1) for (i in 1:10) { guess <- readline(prompt = "Guess:") + guess <- as.integer(guess) if (guess > randonumber){ print("Lower") } else if (guess < randonumber){ @@ -24,6 +24,4 @@ for (i in 1:10) { print("Correct!") break } - } - - \ No newline at end of file + } \ No newline at end of file