#C28.txt, April 29, 2024, code by class Help:=proc():print(`pmatSeq(m,N,d), ABseq(N,w1,w2)`): end: pmatSeq:=proc(m,N,d) local n: [seq(nops(p_mat(m,n,d)),n=1..N)]: end: dig_prime := proc(b,d) local L,v: L := []: v := nextprime(b^(d-1)-1): while v < b^d do L := [op(L),convert(v,base,b)]: v := nextprime(v): od: L: end: Rev := proc(L) local i: [seq(L[nops(L)+1-i], i = 1..nops(L))]: end: flip := proc(L): local i: [seq( Rev(L[nops(L)+1-i]), i=1..nops(L))]: end: p_mat := proc(m,n,d) local m1,n1,L1,L2: m1,n1 := m,n: if m < n then m1,n1 := n,m: fi: L1 := dig_prime(d,m1): L2 := dig_prime(d,n1): pmathelp(m1,n1,L1,L2,[]): end: pmathelp := proc(m,n,S1,S2,SOFAR) local r,SOL,s1,i,v,j: SOL := {}: r := nops(SOFAR): if r = n then for i from 1 to m do v := [seq(SOFAR[j][i], j=1..n )]: if not(v in S2) then return({}): fi: od: return({flip(SOFAR)}): fi: for s1 in S1 do SOL := SOL union pmathelp(m,n,S1,S2,[op(SOFAR),s1]): od: SOL: end: W:=proc(n) local S,s: option remember: if n=0 then RETURN({[]}):fi: S:=W(n-1):{seq([op(s),0], s in S),seq([op(s),1], s in S)}:end: NuW:=proc(W,w) local i,c: c:=0: for i from 1 to nops(W)-nops(w)+1 do if [op(i..i+nops(w)-1,W)]=w then c:=c+1: fi: od: c: end: #AB(n,w1,w2): The set of binary words of length n with more occurences of consective w1 than w2 AB:=proc(n,w1,w2) local S,G,s: S:=W(n): G:={}: for s in S do if NuW(s,w1)>NuW(s,w2) then G:=G union {s}: fi: od: G: end: #ABseqOld(N,w1,w2): the first N terms of the sequence enumeratring bianry n-letter words #with more occurences of the consectutive substring w1 than w2. For example #ABseqOld(15,[0,0],[1,1]); ABseqOld:=proc(N,w1,w2) local i: [seq(nops(AB(i,w1,w2)),i=1..N)]: end: #start code by Alex Valentino Fqn:=proc(q,n) local S,a,v: option remember: if n=0 then RETURN({[]}): fi: S:=Fqn(q,n-1): {seq(seq([op(v),a],a=0..q-1), v in S)}: end: ABseq:=proc(N,w1,w2) local i, iWords, k, validIWords, validWords, w1count, w2count, word: validWords := []: for i from 1 to N do validIWords := {}: if i < nops(w1) or i < nops(w2) then validWords := [op(validWords), validIWords]: else iWords := Fqn(2,i): for word in iWords do w1count := 0: w2count := 0: # print(word): if nops(w1) <= i then for k from 1 to i - nops(w1) + 1 do # print(evalb(w1 = word[k..k-1 + nops(w1)])): if w1 = word[k..k-1 + nops(w1)] then w1count++: fi: od: fi: # print(w1count): if nops(w2) <= i then for k from 1 to i - nops(w2) + 1 do # print(evalb(w2 = word[k..k-1 + nops(w2)])): if w2 = word[k..k-1 + nops(w2)] then w2count++: fi: od: fi: # print(w2count): if w1count > w2count then validIWords := {word} union validIWords: fi: od: validWords := [op(validWords), validIWords]: fi: od: [seq(nops(validWords[i]),i=1..N)]: end: #end code by Alex Valentino