-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Use Roxygen to generate docs. * Add latin constraint testing functions. * Add remove_both function.
- Loading branch information
1 parent
ca80951
commit 9f3a9f8
Showing
9 changed files
with
156 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#' Does a row satisfy the latin constraint? | ||
#' | ||
#' @param R A Room square | ||
#' @param i A row index | ||
#' | ||
#' @return True if and only if row i of R satisfies the latin constraint. | ||
is_row_latin_i <- function(R, i) { | ||
R <- R |> tidyr::pivot_longer(first:second) | ||
u <- R[R$row == i, "value"]$value | ||
u <- u[!is.na(u)] | ||
length(u) == length(unique(u)) | ||
} | ||
|
||
#' Does a column satisfy the latin constraint? | ||
#' | ||
#' @param R A Room square | ||
#' @param i A column index | ||
#' | ||
#' @return True if and only if column i of R satisfies the latin constraint. | ||
is_col_latin_i <- function(R, i) { | ||
R <- R |> tidyr::pivot_longer(first:second) | ||
u <- R[R$col == i, "value"]$value | ||
u <- u[!is.na(u)] | ||
length(u) == length(unique(u)) | ||
} | ||
|
||
#' Is a Room square row latin? | ||
#' | ||
#' @param R A Room square | ||
#' | ||
#' @return True if and only if R is row latin. | ||
is_row_latin <- function(R) { | ||
all(purrr::map_lgl(1:max(R$row), is_row_latin_i, R = R)) | ||
} | ||
|
||
#' Is A Room square column latin? | ||
#' | ||
#' @param R A Room square | ||
#' | ||
#' @return True if and only if R is column latin. | ||
is_col_latin <- function(R) { | ||
all(purrr::map_lgl(1:max(R$col), is_col_latin_i, R = R)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#' Remove both elements of a pair from a list | ||
#' | ||
#' @param X A list | ||
#' @param p A pair | ||
#' | ||
#' @return The list X with both elements of p removed (if they exist). | ||
remove_both <- function(X, p) { | ||
m1 <- match(p[1], X) | ||
if(!is.na(m1)) { | ||
X <- X[-m1] | ||
} | ||
m2 <- match(p[2], X) | ||
if(!is.na(m2)) { | ||
X <- X[-m2] | ||
} | ||
return(X) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters