Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- *** Here is a (or THE) way of generating a solvable flipping-bits game. ***
- * All variables are square arrays with elements of either 0 or 1.
- Definition 1: A <-> B means A can be transformed to B.
- Definition 2: A xor B is the BITWISE XOR operation.
- Definition 3: Let [0] be the 'zero array' (i.e. all its elements are 0)
- CRUCIAL Observation: If A <-> B, then there exist C such that A xor C = B (Make that C called a 'transformer array').
- The converse is NOT always true.
- Proposition 1: If A <-> [0], then (A xor B) <-> B.
- 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.
- Since Z is a transformer array, hence (A xor B) <-> B.
- Proposition 2: If A <-> B, then there exists Z such that B xor Z = A.
- 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.
- * Prop. 2 guarantees that Prop. 1 can generate all C such that C <-> B for any B, given that we can
- generate all A such that A <-> [0].
- * Actually, We can 'generate' all A such that A <-> [0] !
- Method 1: To generate an N by N array A such that A <-> [0], start with the [0] N by N array.
- Then flip any rows, and then flip any columns.
- Example: Let N = 5. I want to flip rows 2,4,5 (chosen randomly).
- Our A must then be:
- R\C 1 2 3 4 5
- 1 [0 0 0 0 0]
- 2 [1 1 1 1 1]
- A = 3 [0 0 0 0 0]
- 4 [1 1 1 1 1]
- 5 [1 1 1 1 1]
- Then, I want to flip columns 2,3,5 (chosen randomly). Then A becomes:
- R\C 1 2 3 4 5
- 1 [0 1 1 0 1]
- 2 [1 0 0 1 0]
- A = 3 [0 1 1 0 1]
- 4 [1 0 0 1 0]
- 5 [1 0 0 1 0]
- Obviously, A <-> [0].
- * And that's it! To generate a solvable flipping-bits game, do the following:
- 1. Generate A such that A <-> [0] (Do Method 1)
- 2. Generate a random 'target'/'final' square array B
- 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