Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
28
Task/Set-puzzle/PARI-GP/set-puzzle.parigp
Normal file
28
Task/Set-puzzle/PARI-GP/set-puzzle.parigp
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
dealraw(cards)=vector(cards,i,vector(4,j,1<<random(3)));
|
||||
howmany(a,b,c)=hammingweight(bitor(a,bitor(b,c)));
|
||||
name(v)=Str(["red","green",0,"purple"][v[1]],", ",["oval","squiggle",0,"diamond"][v[2]],", ",["one","two",0,"three"][v[3]],", ",["solid","open",0,"striped"][v[4]]);
|
||||
check(D,sets)={
|
||||
my(S=List());
|
||||
for(i=1,#D-2,for(j=i+1,#D-1,for(k=j+1,#D,
|
||||
for(x=1,4,
|
||||
if(howmany(D[i][x],D[j][x],D[k][x])==2,next(2))
|
||||
);
|
||||
listput(S,[i,j,k]);
|
||||
if(#S>sets,return(0))
|
||||
)));
|
||||
if(#S==sets,Vec(S),0)
|
||||
};
|
||||
deal(cards,sets)={
|
||||
my(v,s);
|
||||
until(s,
|
||||
s=check(v=dealraw(cards),sets)
|
||||
);
|
||||
v=apply(name,v);
|
||||
for(i=1,cards,print(v[i]));
|
||||
for(i=1,sets,
|
||||
print("Set #"i);
|
||||
for(j=1,3,print(" "v[s[i][j]]))
|
||||
)
|
||||
};
|
||||
deal(9,4)
|
||||
deal(12,6)
|
||||
Loading…
Add table
Add a link
Reference in a new issue