Created
November 24, 2024 16:42
-
-
Save elipousson/df5f532e1aeef325a8e03b3b9a53015a to your computer and use it in GitHub Desktop.
Function to make basic worksheet questions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
make_worksheet_questions <- function(range = c(0:25), | |
ops = c("+", "+", "+", "-", "-", "x"), | |
n = 30, | |
allow_neg = FALSE) { | |
lhs <- sample(range, n, replace = TRUE) | |
rhs <- sample(range, n, replace = TRUE) | |
ops <- sample(ops, n, replace = TRUE) | |
if (!allow_neg) { | |
for (i in seq(n)) { | |
if ((lhs[[i]] < rhs[[i]]) & (ops[[i]] == "-")) { | |
lhs[[i]] <- lhs[[i]] + rhs[[i]] | |
} | |
} | |
} | |
questions <- paste(lhs, ops, rhs, "=", "____", sep = " ") | |
questions <- stringr::str_pad( | |
questions, | |
max(nchar(questions)), | |
pad = "_", | |
side = "right" | |
) | |
paste0(questions, "\n") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment