[seqfan] Re: Common terms in An and Am
israel at math.ubc.ca
israel at math.ubc.ca
Thu Dec 7 03:24:15 CET 2023
Here is Maple code to find the terms common to two sequences.
OEISCommonTerms(num1, num2) finds the list of all pairs [i,t] such that
Anum1[i] = Anum2[i] = t, where num1 and num2 are integers of up to 6
digits. The b-files will be used if present, otherwise just the Data. An
error will occur if these sequences are not in OEIS. Thus
> OEISCommOnTerms(110, 225);
[[1,1],[4,15]]
because A000110(1) = A000225(1) = 1 and A000110(4) = A000225(4) = 15 are
the terms that occur at the same index in both A000110 and A000225.
OEISIntersect(num1, num2) finds the set of all integers that occur
at least once in both Anum1 and Anum2. Thus
> OEISIntersect(2821, 2843);
{1, 253}
because A002821(1) = A002843(0) = A002843(1) = 1 and A002821(40) =
A002843(10) = 253.
getbfile:= proc(anumber)
local bfile,nstr,S,L,B,t,found;
nstr:= sprintf("%6d",10^7+anumber)[-6..-1];
bfile := StringTools:-Substitute(sprintf("https://oeis.org/A%s/b%s.txt",
nstr$2)," ","0");
S:= URL:-Get(bfile);
fclose(bfile);
if StringTools:-Search("Sorry, the page you requested was not found.",S)
<> 0 then error "No sequence %1", nstr fi;
S:= StringTools:-Split(S,"\n");
found:= false;
for t in S do
L := sscanf(t,"%d %d");
if nops(L) = 2 then
B[L[1]]:= L[2]; found:= true;
fi
od;
if not found then error "No data" fi;
eval(B)
end proc:
OEISCommonTerms:= proc(num1,num2)
local R, A1, A2, I1, I2, i;
A1:= getbfile(num1);
A2:= getbfile(num2);
I1:= [indices(A1)];
I2:= [indices(A2)];
R:= NULL;
for i from max(min(I1),min(I2)) to min(max(I1),max(I2)) do
if A1[i] = A2[i] then R:= R, [i,A1[i]] fi
od;
[R]
end proc:
OEISIntersect:= proc(anum1, anum2)
local S1, S2;
S1:= convert(getbfile(anum1),set);
S2:= convert(getbfile(anum2),set);
S1 intersect S2;
end proc:
Cheers,
Robert
On Dec 6 2023, Neil Sloane wrote:
>why not download the two b-files and use Maple or whatever to find their
>intersection
>
>a few lines of Unix shell commands will do it automatically
>
>Best regards
>Neil
>
>Neil J. A. Sloane, Chairman, OEIS Foundation.
>Also Visiting Scientist, Math. Dept., Rutgers University,
>Email: njasloane at gmail.com
>
>
>
> On Wed, Dec 6, 2023 at 9:32AM zak seidov via SeqFan
> <seqfan at list.seqfan.eu> wrote:
>
>> Dear all,Is it any possibility to find common terms in any two OEIS
>> sequences, e.g., from their bfiles?Thanks a lot,Zak
>>
>> --
>> Seqfan Mailing list - http://list.seqfan.eu/
>>
>
>--
>Seqfan Mailing list - http://list.seqfan.eu/
>
>
More information about the SeqFan
mailing list