#Homework 6, Isaac Lam, February 13th 2024 #Old class code # a random word of length n in {0, ..., q-1} RV:=proc(q,n): return [seq(rand(0..q-1)(),1..n)]; end; # LtoC(q,M): inputs a list of basis vectors for our linear code over GF(q) # outputs all the codewords (the actual subset of GF(q)^n with q^k elements) LtoC:=proc(q,M) local n,k,C,i,M1,c: option remember; k:=nops(M); n:=nops(M[1]); if k=1 then return {seq(i*M[1] mod q, i=0..q-1)}; fi; M1:=M[1..k-1]; C:=LtoC(q, M1); return {seq(seq(c + i*M[k] mod q, i=0..q-1), c in C)}; end; # MinW(q,M): The minimal weight of the linear code generated by M over GF(q) MinW:=proc(q,M) local n,c,C: n:=nops(M[1]); C:=LtoC(q,M); return min(seq(HD(c, [0$n]), c in C minus {[0$n]})); end; #End of class code #3. SearchLC:=proc(q,n,k,K): local i,j,currM,currW,M,W: W:=0: M:=[]: for i from 1 to K do: currM:=[]: for j from 1 to k do: currM:=[op(currM), RV(q,n)]: end do: w:=MinW(q,M): if w > W then W:=currW: M:=currM: end if: end do: M: end: #4. skipped