Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (* check if vector x works when rotated k times *)
- ok[x_, k_] := Block[{n = Length[x], m, v},
- m = RotateRight[x, #] & /@ Range[k];
- v = Tuples[{0, 1}, n];
- Unequal @@ (m.# & /@ v)];
- (* compute a canonical representative for the rotation class of x *)
- MinRotation[x_] :=
- First[Sort[RotateRight[x, #] & /@ Range[Length[x]]]];
- f[n_] := f[n] = Block[{k, v},
- v = Select[Tuples[{0, 1}, n], # == MinRotation[#] &];
- For[k = 1, k <= n, k++,
- s = Select[v, ok[#, k] &];
- If[s != {}, Return[{k, First[s], Length[s]}]]]];
- TableForm[Prepend[f[#], #] & /@ Range[12],
- TableDirections -> {Column, Row, Row},
- TableHeadings -> {None, {"n", "f(n)", "Example", "# of examples"}}]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement