Skip to content

Instantly share code, notes, and snippets.

@yannickwurm
Last active November 16, 2017 23:21
Show Gist options
  • Save yannickwurm/8286f751cd21b721c386ec3478adb505 to your computer and use it in GitHub Desktop.
Save yannickwurm/8286f751cd21b721c386ec3478adb505 to your computer and use it in GitHub Desktop.
ants_fyi <- read.table("https://bit.ly/antsofuk")
colnames(ants_fyi) <- c("genus", "species")
nrow(ants_fyi)
head(ants_fyi)
play_guess_the_genus <- function() {
ants <- read.table("https://bit.ly/antsofuk")
colnames(ants) <- c("genus", "species")
score <- 0
attempts <- 0
while ( (score > -10) & (score < 10)) {
attempts <- attempts + 1
# getting random selection
random_row_num <- sample(x = seq(from = 1, to = nrow(ants), by = 1),
size = 1)
random_species <- ants$species[random_row_num]
expected_genus <- ants$genus[random_row_num]
# asking
print(paste("The species is:", random_species))
user_guess <- readline("What is the genus? Enter your guess: ")
# evaluating
if ( user_guess == expected_genus ) {
score <- score + 1
print(paste("Good job! Your score is now: ", score))
} else {
score <- score - 0.5
print(paste("Fail. Your score is now:", score))
print(paste("I was expecting:", expected_genus))
print("Wax on, wax off. You need more practice.")
}
}
print(paste("You have ", score, "points"))
if (score > 0) {
print("Good stuff you know your ants!")
} else {
print("Shame on you.")
}
}
## let's play
play_guess_the_genus()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment