Cody

# Problem 44776. Lights Out 15 - 5x5, broken buttons I

Solution 1952393

Submitted on 29 Sep 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 0 0 0 1 0 0 1 0 0 0 1 0 1 0 1 0 1 0 1 0 1 0 0]; moves = lights_out_15(board); % [1 10 18] b1 = 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)

pp = 1 ------------------ pp = 2 ------------------ pp = 3 ------------------ moves = 18 10 1

2   Pass
board = [0 1 0 0 0 1 0 1 0 0 0 1 0 1 0 0 0 1 0 1 0 0 0 1 0]; moves = lights_out_15(board); % [7 19] b1 = 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)

pp = 1 ------------------ pp = 2 ------------------ moves = 7 19

3   Pass
board = [0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0]; moves = lights_out_15(board); % [1 5 13 21 25] b1 = 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)

pp = 1 ------------------ pp = 2 ------------------ pp = 3 ------------------ pp = 4 ------------------ moves = 7 19 5 21

4   Pass
board = [1 1 1 0 0 1 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1 1 1 0 0]; moves = lights_out_15(board); % [6:10] b1 = 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)

pp = 1 ------------------ pp = 2 ------------------ pp = 3 ------------------ pp = 4 ------------------ pp = 5 ------------------ moves = 7 9 6 8 10

5   Pass
board = [1 0 1 0 0 1 0 1 1 1 1 0 1 0 1 1 0 0 1 1 0 1 0 1 1]; moves = lights_out_15(board); % [2 5 7 11:13 19 21 24] b1 = 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)

pp = 1 ------------------ pp = 2 ------------------ pp = 3 ------------------ pp = 4 ------------------ pp = 5 ------------------ pp = 6 ------------------ pp = 7 ------------------ moves = 24 12 2 3 15 13 23

6   Pass
board = [0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0]; moves = lights_out_15(board); % [2:4 6 10:11 15:16 20 22:24] b1 = 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)

pp = 1 ------------------ pp = 2 ------------------ pp = 3 ------------------ pp = 4 ------------------ moves = 7 19 5 21

7   Pass
board = [0 1 0 1 0 1 0 0 0 1 0 0 0 0 0 1 0 0 0 1 0 1 0 1 0]; moves = lights_out_15(board); % on your own b1 = 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)

pp = 1 ------------------ pp = 2 ------------------ pp = 3 ------------------ pp = 4 ------------------ moves = 1 5 21 25

8   Pass
board = [1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 1]; moves = lights_out_15(board); b1 = 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)

pp = 1 ------------------ pp = 2 ------------------ pp = 3 ------------------ pp = 4 ------------------ pp = 5 ------------------ pp = 6 ------------------ moves = 6 4 8 20 18 22

9   Pass
board = [1 0 0 1 0 1 1 0 1 0 0 1 0 1 0 1 1 1 0 1 0 1 1 1 0]; moves = lights_out_15(board); b1 = 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)

pp = 1 ------------------ pp = 2 ------------------ pp = 3 ------------------ pp = 4 ------------------ pp = 5 ------------------ pp = 6 ------------------ pp = 7 ------------------ pp = 8 ------------------ pp = 9 ------------------ moves = 3 15 23 21 14 18 6 16 22

10   Pass
board = [0 1 1 1 0 1 0 0 0 1 1 0 0 0 1 1 0 0 0 1 0 1 1 1 0]; moves = lights_out_15(board); b1 = 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)

pp = 1 ------------------ pp = 2 ------------------ pp = 3 ------------------ pp = 4 ------------------ pp = 5 ------------------ pp = 6 ------------------ pp = 7 ------------------ pp = 8 ------------------ moves = 2 6 1 5 21 20 24 25

11   Pass
board = [1 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 1 1 1 0 0 0 0 1]; moves = lights_out_15(board); b1 = 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)

pp = 1 ------------------ pp = 2 ------------------ pp = 3 ------------------ pp = 4 ------------------ pp = 5 ------------------ pp = 6 ------------------ pp = 7 ------------------ pp = 8 ------------------ moves = 2 20 4 10 13 11 23 21

12   Pass
board = [1 1 1 0 0 1 0 1 0 0 1 1 0 0 0 0 0 1 0 1 0 1 0 0 1]; moves = lights_out_15(board); b1 = 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)

pp = 1 ------------------ pp = 2 ------------------ pp = 3 ------------------ pp = 4 ------------------ pp = 5 ------------------ pp = 6 ------------------ pp = 7 ------------------ moves = 7 2 12 18 24 15 25

13   Pass
board = [0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0]; moves = lights_out_15(board); b1 = 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)

pp = 1 ------------------ pp = 2 ------------------ moves = 1 25

14   Pass
board = [1 0 0 1 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1]; moves = lights_out_15(board); b1 = 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)

pp = 1 ------------------ pp = 2 ------------------ pp = 3 ------------------ pp = 4 ------------------ pp = 5 ------------------ pp = 6 ------------------ pp = 7 ------------------ pp = 8 ------------------ moves = 21 2 8 14 20 3 9 15

15   Pass
board = [0 1 1 1 0 1 0 0 0 0 1 0 0 1 1 1 0 0 0 0 0 1 1 1 0]; moves = lights_out_15(board); b1 = 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)

pp = 1 ------------------ pp = 2 ------------------ pp = 3 ------------------ pp = 4 ------------------ pp = 5 ------------------ pp = 6 ------------------ pp = 7 ------------------ pp = 8 ------------------ moves = 3 11 13 15 2 6 20 24

16   Pass
board = [1 1 0 0 0 1 1 0 1 1 0 1 1 0 1 0 1 1 1 1 1 1 0 1 0]; moves = lights_out_15(board); b1 = 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)

pp = 1 ------------------ pp = 2 ------------------ pp = 3 ------------------ pp = 4 ------------------ pp = 5 ------------------ pp = 6 ------------------ pp = 7 ------------------ pp = 8 ------------------ moves = 18 15 2 4 7 23 17 21

17   Pass
board = [1 0 0 1 0 1 0 0 1 0 0 1 0 1 0 0 1 0 0 1 0 1 0 0 1]; moves = lights_out_15(board); b1 = 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)

pp = 1 ------------------ pp = 2 ------------------ pp = 3 ------------------ pp = 4 ------------------ pp = 5 ------------------ pp = 6 ------------------ pp = 7 ------------------ pp = 8 ------------------ moves = 3 5 2 8 18 24 23 21

18   Pass
board = [0 1 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 1 0 1 0 0 1 1 1]; moves = lights_out_15(board); b1 = 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)

pp = 1 ------------------ pp = 2 ------------------ pp = 3 ------------------ pp = 4 ------------------ pp = 5 ------------------ pp = 6 ------------------ pp = 7 ------------------ pp = 8 ------------------ moves = 19 17 11 8 14 20 4 10

19   Pass
board = [0 1 1 0 0 0 1 1 1 1 0 0 1 0 0 1 0 0 0 0 0 1 0 0 0]; moves = lights_out_15(board); b1 = 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)

pp = 1 ------------------ pp = 2 ------------------ pp = 3 ------------------ pp = 4 ------------------ moves = 12 5 11 21

20   Pass
board = [0 0 0 0 0 1 0 0 1 0 1 1 0 1 0 1 1 1 1 1 0 0 0 1 1]; moves = lights_out_15(board); b1 = 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)

pp = 1 ------------------ pp = 2 ------------------ pp = 3 ------------------ pp = 4 ------------------ pp = 5 ------------------ pp = 6 ------------------ pp = 7 ------------------ moves = 19 3 8 12 24 16 22

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!