Skip to content

Instantly share code, notes, and snippets.

@TimTeaFan
Last active August 3, 2022 22:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TimTeaFan/8b39344feaf313387e6a42c4cae2614d to your computer and use it in GitHub Desktop.
Save TimTeaFan/8b39344feaf313387e6a42c4cae2614d to your computer and use it in GitHub Desktop.
whileループをむりやりにreduceで書き換えた(あまりお勧めしない)
# this reduce() and done() combo mimics a while loop
# coming from this tweet
# https://twitter.com/norimitsunishi1/status/1554353454360932353?s=21&t=lopKMBKt-SKQfOlrM5B_Iw
# of course this is NOT a good solution, since the input to reduce has a limited length, ...
# ... whereas the while loop will just go on forever until it breaks.
library(purrr)
f <- function(char, char2) {
if (nchar(char) > 24) char <- stringr::str_sub(char, 3, 2*12)
char <- paste0(stringr::str_sub(char), sample(c("ドド", "スコ"), size = 1))
if (char == stringr::str_c(rep("ドドスコスコスコ", 3), collapse = "")) {
char <- stringr::str_c(char, "ラブ注入")
return(done(char))
}
char
}
reduce(rep("", 100000), f)
#> [1] "ドドスコスコスコドドスコスコスコドドスコスコスコラブ注入"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment