#Robert Dougherty Bliss, hw2, # OK to post. SetToVec := proc(S, n) if not type(S, set) or not type(n, nonnegint) then return FAIL: fi: if not verify(S, {seq(k, k=1..n)}, `subset`) then return FAIL: fi: [seq(ifelse(k in S, 1, 0), k=1..n)]: end: VecToSet := proc(v) local n: n := nops(v): select(x -> v[x] = 1, {seq(k, k=1..n)}): end: Box := proc(L) local prev: if not type(L, list) then return FAIL: fi: if nops(L) = 0 then return [[]]: fi: prev := Box(L[1..-2]): [seq(seq([op(p), k], p in prev), k=0..L[-1])]: end: CheckBij := proc(n) andmap(v -> SetToVec(VecToSet(v), n) = v, Box([1$n])): end: # This is basically an efficient way to increment an L-ary number by 1. NextInLine := proc(L, v) local res, good, k: res := [seq(x, x in v)]: good := false: for k from 1 to nops(v) do if v[-k] < L[-k] then res[-k] := res[-k] + 1: return res: else res[-k] := 0: fi: od: FAIL: end: TestNext := proc(L, n) local res: res := [[0$nops(L)]]: for k from 1 to n do res := [op(res), NextInLine(L, res[-1])]: od: res: end: