Skip to content

Instantly share code, notes, and snippets.

@XerxesZorgon
Created December 30, 2020 22:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save XerxesZorgon/3b73557826369e217ab30c1b5f84448a to your computer and use it in GitHub Desktop.
Save XerxesZorgon/3b73557826369e217ab30c1b5f84448a to your computer and use it in GitHub Desktop.
Filtering function for KenKen in PARI/GP
/*
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