function [M] = A362240(smax) % MATLAB function for OEIS sequence A362240. % Given number of rows "s", returns matrix "M": % M: 1st column is row values % 2nd column is the binary transform of the row (A362241) % 3rd column is the sum of the row % Columns 4+ are a(row). Ignore -1s. K=[0]; V=[0]; % bin sum vector (ignore -1s) M=[0 0 0]; while size(M,1)<smax a=0; while a==0 V(end)=V(end)+1; i=length(V); while V(i) == 2 && i>1 V(i)=0; i=i-1; V(i)=V(i)+1; end if V(1) == 2 V = zeros(1,length(V)+1); end z=0; for m=1:length(K)-length(V)+1 if isequal(K(m:m+length(V)-1),V) z=1; break end end if z==0 K=[K V]; a=1; end end S=sum(V); bM = 0; for q=1:length(V) bM=bM+V(q)*2^(length(V)-q); end V=[bM S V]; if length(V)>size(M,2) M=[M zeros(size(M,1),length(V)-size(M,2))-1]; end M=[M;V]; V(1:2)=[]; end N=(0:size(M,1)-1)'; M=[N M]; end