Bin bag problem solution of FoE
library(dplyr)
goal <- 164
blocks <- c(14, 27, 32, 73, 111, 155)
prob_dim <- length(blocks)
block_try <- floor(goal/blocks)
block_vector <- vector(mode = 'list', prob_dim)
for(i in 1:prob_dim){
block_vector[[i]] <- 0:block_try[i]
}
combine.df <- expand.grid(block_vector)
combine.mx <- as.matrix(combine.df)
combine.score <- combine.mx %*% blocks
combine.df$score <-combine.score
combine.df %>%
mutate(bingo = score==goal) %>%
filter(bingo)
No comments:
Post a Comment