```{r, include = FALSE} ## Generate two random fractions based on numbers from 1 to 10 f1 <- sample(1:10, 2, replace = FALSE) f2 <- sample(1:10, 2, replace = FALSE) a <- f1[1] b <- f1[2] c <- f2[1] d <- f2[2] ## Save random fractions a/b and c/d as character ## (don't forget escaping \\ within the math mode) fr1 <- paste0("$\\frac{", a, "}{", b, "}$") fr2 <- paste0("$\\frac{", c, "}{", d, "}$") ## Possible answers answers <- c( paste(fr1, "is greater than", fr2), paste(fr2, "is greater than", fr1), "Both fractions are equal" ) ## Correct solution sol <- c(0, 0, 0) if(a/b > c/d) { sol[1] <- 1 } else if(c/d > a/b) { sol[2] <- 1 } else { sol[3] <- 1 } ## Explanation k <- answers[as.logical(sol)] eq <- c(" > ", " < ", " = ")[as.logical(sol)] explanation <- paste0(k, " since $", a, " \\cdot ", d, eq, b, " \\cdot ", c, "$.") ``` Question ======== Which of these numbers is greater: `r fr1` or `r fr2`? ```{r, echo = FALSE, results = "asis"} answerlist(answers, markup = "markdown") ``` Solution ======== `r explanation` Meta-information ================ extype: schoice exsolution: `r paste(sol, collapse = "")`