r4ds icon indicating copy to clipboard operation
r4ds copied to clipboard

Baby shark

Open hadley opened this issue 5 years ago β€’ 4 comments

Add baby shark song as exercise 🦈 doo doo doo

Cc @jrnold @mine-cetinkaya-rundel

hadley avatar Jan 17 '19 17:01 hadley

Yes! I'm very invested in this.

mine-cetinkaya-rundel avatar Jan 17 '19 17:01 mine-cetinkaya-rundel

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")

jrnold avatar Jan 17 '19 17:01 jrnold

Sorry, that wasn't reprexed 😬

jrnold avatar Jan 17 '19 17:01 jrnold

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 πŸ‘ΆπŸ¦ˆ!

mine-cetinkaya-rundel avatar Jan 17 '19 18:01 mine-cetinkaya-rundel

Not longer going to use since the iteration is now going to be more focussed on specific data analysis activities.

hadley avatar Sep 10 '22 13:09 hadley