4 ms·
My logic was similar, in R: library(dplyr) combos <- expand.grid(x = 1:99, y = 1:99) |> filter(x <= y) |> # Remove dupes mutate(sum = x + y, pro
by jcheng 4y ago
My logic was similar, in R:
library(dplyr)
combos <- expand.grid(x = 1:99, y = 1:99) |>
filter(x <= y) |> # Remove dupes
mutate(sum = x + y, prod = x * y)
find_singletons <- function(col = c("sum", "prod")) {
singletons <- combos %>% group_by(!!sym(col)) %>% tally() %>% filter(n == 1)
which(combos[[col]] %in% singletons[[col]])
}
for (i in 1:7) {
# Peter: I don't know the numbers.
combos <- combos[-find_singletons("prod"),]
# Sandy: I don't know the numbers.
combos <- combos[-find_singletons("sum"),]
}
# Peter: I know the numbers.
combos[find_singletons("prod"),]
- blagie 4y agoTo people who either know: - both R and Python; or - neither R nor Python: Which of the solutions do you find more readable? (I have my own opinion, but I'm biased)