percolate.board: returns the board with water filled

Description Usage Arguments Value Examples

View source: R/percolate.R

Description

returns the board with water filled

Usage

1
2
## S3 method for class 'board'
percolate(x)

Arguments

x

board obj

Value

board with all possible open squares filled

Examples

 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)

edenhu11/percolate documentation built on Nov. 4, 2019, 11:32 a.m.