# Okay to post homework # Ryan Badi, March 24, 2024, Homework 16 Help := proc(): print("qSR(q,INI,L,n), determine_period_length(qsr)"): end: qSR := proc(q, INI, L, n) local r, i, M, ng: r := nops(L): if nops(INI) <> L[-1][2] then: return FAIL: fi: if not (sort(INI)[-1] < q and sort(INI)[1] >= 0) then: return FAIL: fi: if not (type(L, list) and {seq(type(L[i], list), i=1..nops(L))} = {true} and {seq(type(L[i][1], posint), i=1..nops(L))} = {true} and {seq(type(L[i][2], posint), i=1..nops(L))} = {true} and sort([seq(L[i][1], i=1..nops(L))])[-1] < q and sort([seq(L[i][1], i=1..nops(L))])[1] >= 0 and sort([seq(L[i][2], i=1..nops(L))]) = [seq(L[i][2], i=1..nops(L))]) then: return FAIL: fi: if not type(n, posint) then: return FAIL: fi: M := INI: while nops(M) < n do: ng := add(L[i][1]*M[-L[i][2]], i=1..r) mod q: M:=[op(M), ng]: od: return M: end: determine_period_length := proc(qsr) local count, fail_count: fail_count := nops(qsr): count := 1: while qsr[1..count] <> qsr[count+1..2*count] do: count := count + 1: if count > fail_count then: return FAIL: fi: od: return count: end: printf("Period length of qSR(3,[1,2,1],[[1,2],[2,3]],10000): %a\n", determine_period_length(qSR(3, [1, 2, 1], [[1, 2], [2, 3]], 10000))): printf("Period length of qSR(5,[1,2,4,1,2],[[1,2],[2,5]],10000): %a\n", determine_period_length(qSR(5,[1,2,4,1,2],[[1,2],[2,5]], 10000))): printf("Period length of qSR(11,[3,1,2,4,3],[[1,2],[2,5]],10000): %a\n", determine_period_length(qSR(11,[3,1,2,4,3],[[1,2],[2,5]], 10000))): printf("Period length of qSR(5,[1,0,0,0,0,0],[[3,4],[2,5],[3,6]],10000): %a\n", determine_period_length(qSR(5,[1,0,0,0,0,0],[[3,4],[2,5],[3,6]], 10000))):