Description Usage Arguments Value Examples
returns the board with water filled
1 2 | ## S3 method for class 'board'
percolate(x)
|
x |
board obj |
board with all possible open squares filled
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | mat_example_list <- list(matrix(c(1,1,1,1,0,
0,0,0,1,0,
1,1,1,1,0,
0,1,0,0,0,
0,1,1,1,1), 5, 5),
matrix(c(1,1,1,1,0,
0,0,0,1,0,
0,1,1,1,0,
0,1,0,0,0,
0,1,1,1,1), 5, 5),
matrix(c(1,1,1,1,0,
0,0,0,1,0,
0,1,1,0,0,
0,1,0,0,0,
0,1,1,1,1), 5, 5))
board_example_list <- lapply(mat_example_list, board)
percolate_bool <- function(v) {
lst <- percolate(v)
return (lst$result)
}
lapply(board_example_list, percolate_bool)
percolate_board <- function(v) {
lst <- percolate(v)
return (lst$result_board)
}
board_example_list_after <- lapply(board_example_list, percolate_board)
after_plot <- lapply(board_example_list_after, plot)
before_plot <- lapply(board_example_list, plot)
gg_list <- vector(mode = "list")
gg_list <- c(gg_list, before_plot)
gg_list <- c(gg_list, after_plot)
grid.arrange(grobs = gg_list, nrow = 2)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.