Cody

# Problem 44756. Lights Out 5 - 5x5, 10 moves

Solution 1958180

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 = [0 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 0 1]; moves = lights_out_5(board); % [1 2 3 4 5 16 17 18 19 20] 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]),2); %remove semicolon to display progress end assert(sum(abs(board(:)))==0) assert(numel(moves)==10)

moves = 18 9 16 17 2 1 20 19 3 9 4 5 moves = 1 2 3 4 5 9 16 17 18 19 20 ii = 9 6 7 8 2 1 11 10 3 6 4 5 moves = 1 2 3 4 5 16 17 18 19 20

2   Pass
board = [0 0 0 0 0 1 1 1 0 0 0 0 0 0 1 1 1 0 0 1 0 0 1 0 1]; moves = lights_out_5(board); % [1 2 3 11 13 14 16 17 21 24] 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]),2); %remove semicolon to display progress end assert(sum(abs(board(:)))==0) assert(numel(moves)==10)

moves = 24 14 13 3 2 1 11 17 16 21

3   Pass
board = [1 0 0 0 1 0 1 1 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0]; moves = lights_out_5(board); % [1 2 3 4 6 7 8 11 12 16] 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]),2); %remove semicolon to display progress end assert(sum(abs(board(:)))==0) assert(numel(moves)==10)

moves = 8 4 12 16 3 7 11 6 2 1

4   Pass
board = [1 1 0 1 1 0 0 1 1 0 1 1 0 1 0 1 1 0 0 0 0 1 0 0 0]; moves = lights_out_5(board); % [3 6:7 11 13:15 19 22: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]),2); %remove semicolon to display progress end assert(sum(abs(board(:)))==0) assert(numel(moves)==10)

moves = 11 3 6 7 13 14 15 19 23 22

5   Pass
board = [1 0 1 0 1 0 1 1 0 0 0 0 1 0 0 0 1 0 1 0 1 0 1 1 0]; moves = lights_out_5(board); % [2 3 9 10 14 16 17 20 23 24] 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]),2); %remove semicolon to display progress end assert(sum(abs(board(:)))==0) assert(numel(moves)==10)

moves = 8 4 9 15 12 18 22 17 11 6

6   Pass
board = [1 0 0 1 1 0 1 0 0 0 0 0 1 0 0 0 0 0 0 1 1 1 1 0 1]; moves = lights_out_5(board); % [2 4 7 9 11 12 17 19 20 21] 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]),2); %remove semicolon to display progress end assert(sum(abs(board(:)))==0) assert(numel(moves)==10)

moves = 16 12 20 19 9 4 2 7 11 17 16 21 moves = 2 4 7 9 11 12 16 17 19 20 21 ii = 7 6 10 9 4 2 1 3 5 8 7 11 moves = 2 4 7 9 11 12 17 19 20 21

7   Pass
board = [0 0 0 1 1 1 0 1 0 0 1 0 1 0 1 1 0 0 1 0 1 1 0 1 1]; moves = lights_out_5(board); % [1 4 6 12 14 15 18 21 23 24] 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]),2); %remove semicolon to display progress end assert(sum(abs(board(:)))==0) assert(numel(moves)==10)

moves = 2 6 11 5 18 22 23 25 moves = 2 6 11 5 18 22 23 25 1 1

8   Pass
board = [0 1 1 1 1 0 0 0 1 1 1 1 0 0 0 1 0 0 1 0 1 1 1 1 0]; moves = lights_out_5(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]),2); %remove semicolon to display progress end assert(sum(abs(board(:)))==0) assert(numel(moves)==10)

moves = 17 13 14 10 15 9 8 12 16 11

9   Pass
board = [0 1 1 1 1 1 0 1 1 0 0 1 1 1 0 0 1 1 1 1 1 1 0 0 1]; moves = lights_out_5(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]),2); %remove semicolon to display progress end assert(sum(abs(board(:)))==0) assert(numel(moves)==10)

moves = 11 24 22 5 3 8 13 12 16 21

10   Pass
board = [1 1 1 1 0 0 1 1 0 1 0 1 0 1 0 1 0 1 1 0 0 1 1 1 1]; moves = lights_out_5(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]),2); %remove semicolon to display progress end assert(sum(abs(board(:)))==0) assert(numel(moves)==10)

moves = 24 23 15 11 3 2 moves = 24 23 15 11 3 2 1 1 1 1

11   Pass
board = [0 1 0 1 0 0 0 0 1 1 1 0 1 0 0 1 0 1 1 0 0 1 1 0 0]; moves = lights_out_5(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]),2); %remove semicolon to display progress end assert(sum(abs(board(:)))==0) assert(numel(moves)==10)

moves = 3 7 12 16 22 15 24 25 moves = 3 7 12 16 22 15 24 25 1 1

12   Pass
board = [1 0 0 1 1 0 0 1 1 0 0 1 0 0 0 0 1 1 0 0 0 0 0 0 0]; moves = lights_out_5(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]),2); %remove semicolon to display progress end assert(sum(abs(board(:)))==0) assert(numel(moves)==10)

moves = 25 19 24 23 21 12 8 6 2 1

13   Pass
board = [0 1 1 0 1 0 0 0 1 1 0 1 1 0 0 1 1 1 1 0 0 0 1 1 0]; moves = lights_out_5(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]),2); %remove semicolon to display progress end assert(sum(abs(board(:)))==0) assert(numel(moves)==10)

moves = 9 15 19 23 22 11 17 18 24 25

14   Pass
board = [0 0 1 1 1 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 1 1]; moves = lights_out_5(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]),2); %remove semicolon to display progress end assert(sum(abs(board(:)))==0) assert(numel(moves)==10)

moves = 19 18 17 23 20 25 24 22 16 21