Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
45
Task/24-game/PARI-GP/24-game.parigp
Normal file
45
Task/24-game/PARI-GP/24-game.parigp
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
game()={
|
||||
my(v=vecsort(vector(4,i,random(8)+1)));
|
||||
print("Form 24 using */+-() and: "v);
|
||||
while(1,
|
||||
my(ans=input);
|
||||
if (!valid(s,v), next);
|
||||
trap(,
|
||||
print("Arithmetic error");
|
||||
next
|
||||
,
|
||||
if(eval(s)==24, break, print("Bad sum"))
|
||||
)
|
||||
);
|
||||
print("You win!")
|
||||
};
|
||||
valid(s,v)={
|
||||
my(op=vecsort(Vec("+-*/()")),u=[]);
|
||||
s=Vec(s);
|
||||
for(i=1,#s,
|
||||
if(setsearch(op,s[i]),next);
|
||||
trap(,
|
||||
print("Invalid character "s[i]);
|
||||
return(0)
|
||||
,
|
||||
if(setsearch(v,eval(s[i])),
|
||||
u=concat(u,eval(s[i]))
|
||||
,
|
||||
print(s[i]" not allowed");
|
||||
return(0)
|
||||
)
|
||||
)
|
||||
);
|
||||
for(i=2,#s,
|
||||
if(!setsearch(op,s[i])&!setsearch(op,s[i-1]),
|
||||
print("Concatenating digits is not allowed!");
|
||||
return(0)
|
||||
)
|
||||
);
|
||||
if(vecsort(u)!=v,
|
||||
print("Invalid digits");
|
||||
0
|
||||
,
|
||||
1
|
||||
)
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue