Advertisement
Guest User

Untitled

a guest
Jul 1st, 2015
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. (* check if vector x works when rotated k times *)
  2. ok[x_, k_] := Block[{n = Length[x], m, v},
  3. m = RotateRight[x, #] & /@ Range[k];
  4. v = Tuples[{0, 1}, n];
  5. Unequal @@ (m.# & /@ v)];
  6.  
  7. (* compute a canonical representative for the rotation class of x *)
  8. MinRotation[x_] :=
  9. First[Sort[RotateRight[x, #] & /@ Range[Length[x]]]];
  10.  
  11. f[n_] := f[n] = Block[{k, v},
  12. v = Select[Tuples[{0, 1}, n], # == MinRotation[#] &];
  13. For[k = 1, k <= n, k++,
  14. s = Select[v, ok[#, k] &];
  15. If[s != {}, Return[{k, First[s], Length[s]}]]]];
  16.  
  17. TableForm[Prepend[f[#], #] & /@ Range[12],
  18. TableDirections -> {Column, Row, Row},
  19. TableHeadings -> {None, {"n", "f(n)", "Example", "# of examples"}}]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement