Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
51
Task/Zebra-puzzle/PARI-GP/zebra-puzzle.parigp
Normal file
51
Task/Zebra-puzzle/PARI-GP/zebra-puzzle.parigp
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
perm(arr) = {
|
||||
n=#arr;i=n-1;
|
||||
while(i > -1,if (arr[i] < arr[i+1],break);i--);
|
||||
j=n;
|
||||
while(arr[j]<= arr[i],j -=1);
|
||||
tmp = arr[i] ;arr[i]=arr[j];arr[j]=tmp;
|
||||
i +=1; j = n;
|
||||
while(i < j ,tmp = arr[i] ;arr[i]=arr[j];arr[j]=tmp;
|
||||
i +=1; j -=1);
|
||||
return(arr);
|
||||
}
|
||||
perms(arr)={
|
||||
n=#arr;
|
||||
result = List();
|
||||
listput(result,arr);
|
||||
for(i=1,n!-1,arr=perm(arr);listput(result,arr));
|
||||
return(result);
|
||||
}
|
||||
|
||||
adj(x,xs,y,ys)={
|
||||
abs(select(z->z==x,xs,1)[1] - select(z->z==y,ys,1)[1])==1;
|
||||
}
|
||||
eq(x,xs,y,ys)={
|
||||
select(z->z==x,xs,1) == select(z->z==y,ys,1);
|
||||
}
|
||||
|
||||
colors =Vec(perms( ["Blue", "Green", "Red", "White", "Yellow"]));;
|
||||
drinks =Vec(perms( ["Beer", "Coffee", "Milk", "Tea", "Water"]));;
|
||||
nations =Vec(perms( ["Denmark", "England", "Germany", "Norway", "Sweden"]));;
|
||||
smokes =Vec(perms( ["Blend", "BlueMaster", "Dunhill", "PallMall", "Prince"]));;
|
||||
pets =Vec(perms( ["Birds", "Cats", "Dog", "Horse", "Zebra"]));;;
|
||||
colors= select(x->select(z->z=="White",x,1)[1] - select(z->z=="Green",x,1)[1]==1,colors);
|
||||
drinks=select(x->x[3]=="Milk",drinks);
|
||||
nations=select(x->x[1]=="Norway",nations);
|
||||
|
||||
for(n=1,#nations,for(c=1,#colors,\
|
||||
if(eq("Red",colors[c],"England",nations[n]) && adj("Norway",nations[n],"Blue",colors[c]),\
|
||||
for(d=1,#drinks,\
|
||||
if(eq("Denmark",nations[n],"Tea",drinks[d])&& eq("Coffee",drinks[d],"Green",colors[c]),\
|
||||
for(s=1,#smokes,\
|
||||
if(eq("Yellow",colors[c],"Dunhill",smokes[s]) &&\
|
||||
eq("BlueMaster",smokes[s],"Beer",drinks[d]) &&\
|
||||
eq("Germany",nations[n],"Prince",smokes[s]),\
|
||||
for(p=1,#pets,\
|
||||
if(eq("Birds",pets[p],"PallMall",smokes[s]) &&\
|
||||
eq("Sweden",nations[n],"Dog",pets[p]) &&\
|
||||
adj("Blend",smokes[s],"Cats",pets[p]) &&\
|
||||
adj("Horse",pets[p],"Dunhill",smokes[s]),\
|
||||
print("Zebra is owned by ",nations[n][select(z->z=="Zebra",pets[p],1)[1]]);print();\
|
||||
for(i=1,5,printf("House:%s %6s %10s %10s %10s %10s\n",i,colors[c][i],nations[n][i],pets[p][i],drinks[d][i],smokes[s][i]));\
|
||||
)))))))));
|
||||
Loading…
Add table
Add a link
Reference in a new issue