Filtering function for KenKen in PARI/GP
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
/* | |
Filters vectors for KenKen game | |
Inputs | |
v: vector | |
c: Number of elements in the sum (size of the KenKen cell) | |
n: Maximum value in the sum (length of a side in the game) | |
u: T/F flag for uniqueness. Set if the cell is contained in a single row or column | |
e: Exclusion set vector. Numbers appearing in the same row or column as the cell | |
Output | |
TF: v satisfies all input conditions | |
Dependencies | |
isunique.gp | |
Example: | |
v = [1,2,4]; | |
c = 3; | |
n = 9; | |
kFilt(v,c,n) = 1 | |
Written by: John Peach 28-Dec-2020 | |
*/ | |
kFilt(v,c,n,u=1,e=[]) = | |
{ | |
length(v) == c & | |
vecmax(v) <= n & | |
if(u,isunique(v),1) & | |
length(setintersect(Set(v),Set(e))) == 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment