Skip to contents

generate_math_problems() generates one problem per target answer, numbered in order.

Usage

generate_math_problems(targets, op = "auto", max_factor = 12L)

Arguments

targets

Integer vector of desired answers (1-100), in the order the problems should be numbered.

op

One of "auto" (default), "add", "subtract", or "multiply". "auto" picks subtraction when target < 50, and otherwise picks addition or multiplication at random (only considering multiplication when target actually has a suitable factor pair, e.g. never for a prime target).

max_factor

Largest multiplication factor to consider.

Value

A data frame with columns problem (1-based index), op, operands (a list column of numeric vectors, one per problem, allowing more than two operands per problem), and target.

Examples

set.seed(42)
generate_math_problems(c(34, 37, 67, 64, 34))
#>   problem       op target operands
#> 1       1 subtract     34   92, 58
#> 2       2 subtract     37   83, 46
#> 3       3      add     67   10, 57
#> 4       4      add     64   19, 45
#> 5       5 subtract     34   79, 45