Cody

# Problem 44766. Lights Out 12 - 5x5, three stages, <7 moves

Solution 1958293

Submitted on 3 Oct 2019 by Augusto Mazzei
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Pass
board = [1 1 0 0 0 1 0 0 0 0 0 0 0 2 0 0 0 2 2 2 0 0 0 2 0]; moves = lights_out_12(board); % [1 1 19] b1 = diag(ones(1,5),0) + diag(ones(1,4),1) + diag(ones(1,4),-1); b2 = eye(5); b3 = zeros(5); b_map = [b1,b2,b3,b3,b3;b2,b1,b2,b3,b3;b3,b2,b1,b2,b3;b3,b3,b2,b1,b2;b3,b3,b3,b2,b1]; for i = 1:numel(moves) board = mod(board + reshape(b_map(moves(i),:),[5,5]),3); %remove semicolon to display progress end assert(sum(abs(board(:)))==0)

moves = 19 19 1 moves = 19 1 19 moves = 1 1 19

2   Pass
board = [2 2 0 2 2 2 0 2 0 2 0 2 2 2 0 2 0 2 0 2 2 2 0 2 2]; moves = lights_out_12(board); % [1 5 13 21 25] b1 = diag(ones(1,5),0) + diag(ones(1,4),1) + diag(ones(1,4),-1); b2 = eye(5); b3 = zeros(5); b_map = [b1,b2,b3,b3,b3;b2,b1,b2,b3,b3;b3,b2,b1,b2,b3;b3,b3,b2,b1,b2;b3,b3,b3,b2,b1]; for i = 1:numel(moves) board = mod(board + reshape(b_map(moves(i),:),[5,5]),3); %remove semicolon to display progress end assert(sum(abs(board(:)))==0)

moves = 13 13 25 25 21 21 5 5 1 1 moves = 13 13 25 25 21 21 5 1 1 5 moves = 13 13 25 25 21 5 5 1 1 21 moves = 13 13 25 21 21 5 5 1 1 25 moves = 13 25 25 21 21 5 5 1 1 13 moves = 1 5 13 21 25

3   Pass
board = [0 1 0 0 0 1 1 1 0 1 0 1 0 1 1 1 0 0 0 1 1 1 0 0 0]; moves = lights_out_12(board); % [5 5 7 7 23 23] b1 = diag(ones(1,5),0) + diag(ones(1,4),1) + diag(ones(1,4),-1); b2 = eye(5); b3 = zeros(5); b_map = [b1,b2,b3,b3,b3;b2,b1,b2,b3,b3;b3,b2,b1,b2,b3;b3,b3,b2,b1,b2;b3,b3,b3,b2,b1]; for i = 1:numel(moves) board = mod(board + reshape(b_map(moves(i),:),[5,5]),3); %remove semicolon to display progress end assert(sum(abs(board(:)))==0)

moves = 7 23 5 moves = 7 5 23 moves = 23 5 7 moves = 5 7 23 5 7 23

4   Pass
board = [2 1 2 0 0 2 0 2 0 0 2 0 2 0 0 2 0 2 0 0 2 1 2 0 0]; moves = lights_out_12(board); % [6:10] b1 = diag(ones(1,5),0) + diag(ones(1,4),1) + diag(ones(1,4),-1); b2 = eye(5); b3 = zeros(5); b_map = [b1,b2,b3,b3,b3;b2,b1,b2,b3,b3;b3,b2,b1,b2,b3;b3,b3,b2,b1,b2;b3,b3,b3,b2,b1]; for i = 1:numel(moves) board = mod(board + reshape(b_map(moves(i),:),[5,5]),3); %remove semicolon to display progress end assert(sum(abs(board(:)))==0)

moves = 9 8 8 6 10 10 9 7 7 6 moves = 9 8 8 6 10 10 9 6 7 7 moves = 6 7 8 9 10

5   Pass
board = [1 1 0 0 0 2 0 0 0 0 1 1 0 0 0 2 0 0 0 0 1 1 0 0 0]; moves = lights_out_12(board); % [1 1 3 3 5 5] b1 = diag(ones(1,5),0) + diag(ones(1,4),1) + diag(ones(1,4),-1); b2 = eye(5); b3 = zeros(5); b_map = [b1,b2,b3,b3,b3;b2,b1,b2,b3,b3;b3,b2,b1,b2,b3;b3,b3,b2,b1,b2;b3,b3,b3,b2,b1]; for i = 1:numel(moves) board = mod(board + reshape(b_map(moves(i),:),[5,5]),3); %remove semicolon to display progress end assert(sum(abs(board(:)))==0)

moves = 3 5 1 moves = 3 1 5 moves = 5 1 3 moves = 1 3 5 1 3 5

6   Pass
board = [0 2 0 2 0 2 2 0 2 2 0 0 2 0 0 2 2 0 2 2 0 2 0 2 0]; moves = lights_out_12(board); % [7 9 13 17 19] b1 = diag(ones(1,5),0) + diag(ones(1,4),1) + diag(ones(1,4),-1); b2 = eye(5); b3 = zeros(5); b_map = [b1,b2,b3,b3,b3;b2,b1,b2,b3,b3;b3,b2,b1,b2,b3;b3,b3,b2,b1,b2;b3,b3,b3,b2,b1]; for i = 1:numel(moves) board = mod(board + reshape(b_map(moves(i),:),[5,5]),3); %remove semicolon to display progress end assert(sum(abs(board(:)))==0)

moves = 17 17 13 9 9 19 19 13 7 7 moves = 19 19 13 7 7 17 17 13 9 9 moves = 17 17 13 9 9 7 7 13 19 19 moves = 19 19 13 7 7 9 9 13 17 17 moves = 19 17 17 9 9 7 19 7 13 13 moves = 7 9 13 17 19

7   Pass
board = [0 2 0 2 0 2 1 1 1 2 2 0 1 0 2 2 1 1 1 2 0 2 0 2 0]; moves = lights_out_12(board); % [7:9 17:19] b1 = diag(ones(1,5),0) + diag(ones(1,4),1) + diag(ones(1,4),-1); b2 = eye(5); b3 = zeros(5); b_map = [b1,b2,b3,b3,b3;b2,b1,b2,b3,b3;b3,b2,b1,b2,b3;b3,b3,b2,b1,b2;b3,b3,b3,b2,b1]; for i = 1:numel(moves) board = mod(board + reshape(b_map(moves(i),:),[5,5]),3); %remove semicolon to display progress end assert(sum(abs(board(:)))==0)

moves = 9 7 3 19 17 17 19 18 18 7 8 8 9 3 3 moves = 9 7 3 19 17 17 19 18 18 9 3 3 8 8 7 moves = 9 7 3 19 17 17 19 18 18 9 3 7 3 8 8 moves = 9 7 3 19 17 17 19 18 18 7 8 8 3 3 9 moves = 7 8 9 17 18 19

8   Pass
board = [0 0 0 0 0 0 2 1 2 0 2 0 2 0 2 0 2 1 2 0 0 0 0 0 0]; moves = lights_out_12(board); % [8 13 13 18] b1 = diag(ones(1,5),0) + diag(ones(1,4),1) + diag(ones(1,4),-1); b2 = eye(5); b3 = zeros(5); b_map = [b1,b2,b3,b3,b3;b2,b1,b2,b3,b3;b3,b2,b1,b2,b3;b3,b3,b2,b1,b2;b3,b3,b3,b2,b1]; for i = 1:numel(moves) board = mod(board + reshape(b_map(moves(i),:),[5,5]),3); %remove semicolon to display progress end assert(sum(abs(board(:)))==0)

moves = 18 18 13 8 8 moves = 8 8 13 18 18 moves = 18 18 8 8 13 moves = 13 13 8 18

9   Pass
board = [0 1 1 1 0 1 2 0 2 1 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0]; moves = lights_out_12(board); % [7 7 12 12 17 17] b1 = diag(ones(1,5),0) + diag(ones(1,4),1) + diag(ones(1,4),-1); b2 = eye(5); b3 = zeros(5); b_map = [b1,b2,b3,b3,b3;b2,b1,b2,b3,b3;b3,b2,b1,b2,b3;b3,b3,b2,b1,b2;b3,b3,b3,b2,b1]; for i = 1:numel(moves) board = mod(board + reshape(b_map(moves(i),:),[5,5]),3); %remove semicolon to display progress end assert(sum(abs(board(:)))==0)

moves = 17 12 7 moves = 17 7 12 moves = 12 7 17 moves = 7 12 17 7 12 17

10   Pass
board = [0 0 0 1 2 0 0 2 2 1 0 1 0 2 2 0 1 1 2 2 2 0 0 0 2]; moves = lights_out_12(board); % on your own b1 = diag(ones(1,5),0) + diag(ones(1,4),1) + diag(ones(1,4),-1); b2 = eye(5); b3 = zeros(5); b_map = [b1,b2,b3,b3,b3;b2,b1,b2,b3,b3;b3,b2,b1,b2,b3;b3,b3,b2,b1,b2;b3,b3,b3,b2,b1]; for i = 1:numel(moves) board = mod(board + reshape(b_map(moves(i),:),[5,5]),3); %remove semicolon to display progress end assert(sum(abs(board(:)))==0)

moves = 9 5 5 17 24 24 17 21 21 moves = 9 5 5 17 24 17 21 21 24 moves = 9 5 5 17 24 24 21 21 17 moves = 17 24 24 17 21 21 9 5 5 moves = 17 24 24 17 21 21 5 5 9 moves = 9 9 5 17 21 24

11   Pass
board = [0 2 1 0 0 2 2 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0]; moves = lights_out_12(board); b1 = diag(ones(1,5),0) + diag(ones(1,4),1) + diag(ones(1,4),-1); b2 = eye(5); b3 = zeros(5); b_map = [b1,b2,b3,b3,b3;b2,b1,b2,b3,b3;b3,b2,b1,b2,b3;b3,b3,b2,b1,b2;b3,b3,b3,b2,b1]; for i = 1:numel(moves) board = mod(board + reshape(b_map(moves(i),:),[5,5]),3); %remove semicolon to display progress end assert(sum(abs(board(:)))==0)

moves = 6 2 1 moves = 6 1 2 moves = 2 1 6 moves = 1 2 6 1 2 6

12   Pass
board = [1 1 1 0 0 0 0 0 0 0 2 1 1 0 0 2 0 0 2 0 0 1 1 2 0]; moves = lights_out_12(board); b1 = diag(ones(1,5),0) + diag(ones(1,4),1) + diag(ones(1,4),-1); b2 = eye(5); b3 = zeros(5); b_map = [b1,b2,b3,b3,b3;b2,b1,b2,b3,b3;b3,b2,b1,b2,b3;b3,b3,b2,b1,b2;b3,b3,b3,b2,b1]; for i = 1:numel(moves) board = mod(board + reshape(b_map(moves(i),:),[5,5]),3); %remove semicolon to display progress end assert(sum(abs(board(:)))==0)

moves = 14 9 14 15 15 9 8 8 6 moves = 6 8 8 14 9 14 9 15 15 moves = 14 9 14 15 15 9 6 8 8 moves = 15 14 14 8 6 8 15 9 9 moves = 15 9 9 8 6 8 15 14 14 moves = 6 6 8 9 14 15