You're given two numeric vectors, a
and b
. b
is identical to a
, except
that two numbers have been swapped. Return a numeric vector of length 2
containing the values of the two swapped numbers in increasing order.
For example, with the following input
a <- c(1, 1, 2, 3, 5, 8, 13, 21, 34, 55) b <- c(1, 1, 13, 3, 5, 8, 2, 21, 34, 55)
The answer would be
c(2, 13)
# # a code chunk named 'grader' should produce a list of arguments to use with the # grade_riddle function. # generate_test_input <- function(a) { swap_indxs <- sample(1:length(a), 2, replace = FALSE) b <- a b[swap_indxs] <- b[rev(swap_indxs)] list(a = a, b = b) } list( test_inputs = list( list( a = c(1, 1, 2, 3, 5, 8, 13, 21, 34, 55), b = c(1, 1, 13, 3, 5, 8, 2, 21, 34, 55)), generate_test_input(1:10), generate_test_input(10:1), generate_test_input(runif(100, -50, 50))), test_timeouts = 0.5, solution = quote(sort(a[a != b])), quoted = TRUE)
# already in environment: # a (numeric vector, 1 <= length <= 10,000) # b (numeric vector, 1 <= length <= 10,000) print(a) print(b)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.