g->w->{var v=0<1;int x=0,l,i=0,j,p,z,y=w[0][0];for(;i<w.length;i++)for(l=w[i].length,v&=y==w[i][0]&l>2,j=0,p=-9;j<l;v&=z>=0&z/3!=p/3,x|=2<<(p=z))z=g.indexOf(y=w[i][j++]);return v&x==8190;}
在线尝试!
说明
g->w->{ // Lambda accepting letter groups as a string and a list of words, in the form of an array of char arrays.
var v=0<1; // Validity variable
int x=0, // The letter coverage (rule 4)
l, // The length of w[i]
i=0, // The w iterator
j, // The w[i] iterator
p, // The previous group
z, // The current group
y=w[0][0]; // The previous character
for(;i<w.length;i++) // For each word...
for(
l=w[i].length, // make a shortcut for the length
v&=y==w[i][0]&l>2, // check if the last character of the previous word is the same as the first of the current.
// Also, check if the length is at least 3
j=0, // Reset the iteration
p=-9 // Set p to an impossible value.
;
j<l //
;
v&=z>=0&z/3!=p/3, // Check that each letter of the word is in the letter pool,
// and that the current letter group isn't the same as the previous one.
x|=2<<(p=z) // After the checks, assign z to p,
// and mark the letter of the pool as used.
)
z=g.indexOf(y=w[i][j++]); // Assign the current letter to y so that it contains the last at the end of the loop.
// and fetch the position of the letter in the pool.
return v&x==8190; // Return true if all matched
// and if the rule 4 is enforced.
}
学分
no letter appears twice