#Please do not post homework #Guy Adami, 2026-03-29, Assignment 16 with(ListTools): #Finds the location of a value n in Q Location:=proc(Q,n) local r,c, row, col: for r from 1 to nops(Q) do for c from 1 to nops(Q[r]) do if n = Q[r][c] then row:=r: col:=c: fi: od: od: RETURN([row,col]) end: #Finds what number bumped out "bumped" and returns that number and its col position FindBumpee:=proc(p,bumped) local i, bumpee,col: bumpee:=0: col:=0; for i from 1 to nops(p) do if bumped > p[i] then bumpee:=p[i]: col:=i: fi: od: RETURN([bumpee,col]); end: RSAnti:= proc(P,Q) local pi,n, i,j, L, bumped,bumpee,B,row,col: pi:=[]: #`Get the largest value in Q which is equal to the number of elements to start` n:=0: for i from 1 to nops(Q) do n:=n + nops(Q[i]): od: for i from n by -1 to 1 do #`locate row and column of n` L:=Location(Q,i): row:=L[1]: col:=L[2]: #`Get bumped value` bumped:=P[row][col]: #`Removes the bumped element from P` P[row] := subsop(col = NULL, P): for r from row-1 by -1 to 1 do B=FindBumpee(P[r],bumped): bumpee:= B[1]: P[r][B[2]]:=bumped: bumped:=bumpee: od: pi:=[op(pi),bumped]: od: pi:=Reverse(pi); end: