r4ds
r4ds copied to clipboard
Baby shark
Add baby shark song as exercise π¦ doo doo doo
Cc @jrnold @mine-cetinkaya-rundel
Yes! I'm very invested in this.
A first cut ... the ugly version needs to be uglier. Also, I'm not sure what you'd want the objective to be: print, return a single character vector, or a list (maybe nested)
library("purrr")
things <- c("Baby shark", "Mommy", "Daddy", "Grandma", "Grandpa",
"Let's go hunt", "Run away", "Safe at Last",
"It's the end")
for (what in things) {
for (refrain in seq_len(5)) {
cat(what, ",")
for (doo in seq_len(6)) {
cat(" ", "doo")
}
cat("\n")
}
cat(what, "!", "\n")
}
doo <- function(n) rep("doo", n)
verse <- function(what, n_refrain = 4, n_doo = 6) {
c(rerun(n_refrain, c(what, ",", doo(n_doo))),
list(c(what, "!")))
}
map(things, verse) %>%
flatten() %>%
map_chr(str_c, collapse = " ") %>%
str_c(collapse = "\n")
Sorry, that wasn't reprexed π¬
Here is the Halloween version for the for
loop.
halloween_things <- c("Baby shark", "Mummy", "Ghost", "Pirate", "Cowboy", "Princess",
"Halloween", "Trick-or-treat", "Getting dark", "What's that",
"Swim away", "Swim faster", "Papa shark")
rep_word <- "boo"
for (what in halloween_things) {
for (refrain in seq_len(5)) {
cat(what, ",", sep = "") # single space after comma
for (doo in seq_len(6)) {
cat("", rep_word) # single space between words
}
cat("\n")
}
cat(what, "!", sep = "", "\n") # single space before !
}
#> Baby shark, boo boo boo boo boo boo
#> Baby shark, boo boo boo boo boo boo
#> Baby shark, boo boo boo boo boo boo
#> Baby shark, boo boo boo boo boo boo
#> Baby shark, boo boo boo boo boo boo
#> Baby shark!
#> Mummy, boo boo boo boo boo boo
#> Mummy, boo boo boo boo boo boo
#> Mummy, boo boo boo boo boo boo
#> Mummy, boo boo boo boo boo boo
#> Mummy, boo boo boo boo boo boo
#> Mummy!
#> Ghost, boo boo boo boo boo boo
#> Ghost, boo boo boo boo boo boo
#> Ghost, boo boo boo boo boo boo
#> Ghost, boo boo boo boo boo boo
#> Ghost, boo boo boo boo boo boo
#> Ghost!
#> ...
#> Papa shark, boo boo boo boo boo boo
#> Papa shark, boo boo boo boo boo boo
#> Papa shark, boo boo boo boo boo boo
#> Papa shark, boo boo boo boo boo boo
#> Papa shark, boo boo boo boo boo boo
#> Papa shark!
Created on 2019-01-17 by the reprex package (v0.2.1)
I edited out part of the output to keep it short.
Will work out the rest later!
We should be able to write it in a way that it samples words from a wordbag related to events/holidays etc. and generate new versions, because everyone needs more πΆπ¦!
Not longer going to use since the iteration is now going to be more focussed on specific data analysis activities.