Update all new Tasks
This commit is contained in:
parent
00a190b0a6
commit
91df62d461
5697 changed files with 93386 additions and 804 deletions
27
Task/String-matching/PARI-GP/string-matching.pari
Normal file
27
Task/String-matching/PARI-GP/string-matching.pari
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
startsWith(string, prefix)={
|
||||
string=Vec(string);
|
||||
prefix=Vec(prefix);
|
||||
if(#prefix > #string, return(0));
|
||||
for(i=1,#prefix,if(prefix[i]!=string[i], return(0)));
|
||||
1
|
||||
};
|
||||
contains(string, inner)={
|
||||
my(good);
|
||||
string=Vec(string);
|
||||
inner=Vec(inner);
|
||||
for(i=0,#string-#inner,
|
||||
good=1;
|
||||
for(j=1,#inner,
|
||||
if(inner[j]!=string[i+j], good=0; break)
|
||||
);
|
||||
if(good, return(i+1))
|
||||
);
|
||||
0
|
||||
};
|
||||
endsWith(string, suffix)={
|
||||
string=Vec(string);
|
||||
suffix=Vec(suffix);
|
||||
if(#suffix > #string, return(0));
|
||||
for(i=1,#suffix,if(prefix[i]!=string[i+#string-#suffix], return(0)));
|
||||
1
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue