Advertisement
Guest User

Generating a Solvable Flipping-bits Game.

a guest
May 13th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. *** Here is a (or THE) way of generating a solvable flipping-bits game. ***
  2.  
  3. * All variables are square arrays with elements of either 0 or 1.
  4.  
  5. Definition 1: A <-> B means A can be transformed to B.
  6. Definition 2: A xor B is the BITWISE XOR operation.
  7. Definition 3: Let [0] be the 'zero array' (i.e. all its elements are 0)
  8.  
  9. CRUCIAL Observation: If A <-> B, then there exist C such that A xor C = B (Make that C called a 'transformer array').
  10. The converse is NOT always true.
  11.  
  12. Proposition 1: If A <-> [0], then (A xor B) <-> B.
  13. Proof: From Def. 1, we have Z such that A xor Z = [0], then (A xor B) xor Z = B xor (A xor Z) = B.
  14. Since Z is a transformer array, hence (A xor B) <-> B.
  15.  
  16. Proposition 2: If A <-> B, then there exists Z such that B xor Z = A.
  17. Proof: From Def. 1, we must have Z such that A xor Z = B. Then by the nature of XOR, we have B xor Z = A.
  18.  
  19. * Prop. 2 guarantees that Prop. 1 can generate all C such that C <-> B for any B, given that we can
  20. generate all A such that A <-> [0].
  21.  
  22. * Actually, We can 'generate' all A such that A <-> [0] !
  23.  
  24. Method 1: To generate an N by N array A such that A <-> [0], start with the [0] N by N array.
  25. Then flip any rows, and then flip any columns.
  26.  
  27. Example: Let N = 5. I want to flip rows 2,4,5 (chosen randomly).
  28. Our A must then be:
  29.  
  30. R\C 1 2 3 4 5
  31.  
  32. 1 [0 0 0 0 0]
  33. 2 [1 1 1 1 1]
  34. A = 3 [0 0 0 0 0]
  35. 4 [1 1 1 1 1]
  36. 5 [1 1 1 1 1]
  37.  
  38. Then, I want to flip columns 2,3,5 (chosen randomly). Then A becomes:
  39.  
  40. R\C 1 2 3 4 5
  41.  
  42. 1 [0 1 1 0 1]
  43. 2 [1 0 0 1 0]
  44. A = 3 [0 1 1 0 1]
  45. 4 [1 0 0 1 0]
  46. 5 [1 0 0 1 0]
  47.  
  48. Obviously, A <-> [0].
  49.  
  50. * And that's it! To generate a solvable flipping-bits game, do the following:
  51. 1. Generate A such that A <-> [0] (Do Method 1)
  52. 2. Generate a random 'target'/'final' square array B
  53. 3. Compute bitwise XOR of A and B, and the result will be your initial array!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement