Cody

# Problem 44753. Lights Out 3 - 5x5, 6 moves

Solution 1952399

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

pp = 1 ans = 25 ------------------ pp = 2 ans = 300 ------------------ pp = 3 ans = 2300 ------------------ pp = 4 ans = 4191 ------------------ pp = 5 ans = 4930 ------------------ pp = 6 ans = 4735 ------------------ ans = logical 1 moves = 1 11 21 5 15 25

2   Pass
board = [0 0 1 0 0 0 0 1 1 0 1 1 0 1 1 0 1 1 0 0 0 0 1 0 0]; moves = lights_out_3(board); % [4 9 10 16 17 22] 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)==6)

pp = 1 ans = 25 ------------------ pp = 2 ans = 300 ------------------ pp = 3 ans = 2300 ------------------ pp = 4 ans = 3934 ------------------ pp = 5 ans = 4778 ------------------ pp = 6 ans = 5149 ------------------ ans = logical 1 moves = 9 4 10 17 16 22

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

pp = 1 ans = 25 ------------------ pp = 2 ans = 300 ------------------ pp = 3 ans = 2300 ------------------ pp = 4 ans = 4027 ------------------ pp = 5 ans = 4440 ------------------ pp = 6 ans = 5181 ------------------ ans = logical 1 moves = 7 17 8 9 18 19

4   Pass
board = [0 1 1 0 1 0 1 1 0 0 0 0 0 0 1 1 0 1 0 0 1 0 0 0 0]; moves = lights_out_3(board); % [4 8 11 13 17 22] 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)==6)

pp = 1 ans = 25 ------------------ pp = 2 ans = 300 ------------------ pp = 3 ans = 2300 ------------------ pp = 4 ans = 4125 ------------------ pp = 5 ans = 5159 ------------------ pp = 6 ans = 5334 ------------------ ans = logical 1 moves = 4 8 13 11 17 22

5   Pass
board = [0 1 1 1 1 1 1 0 1 1 1 0 1 0 0 0 0 0 1 0 0 1 0 1 0]; moves = lights_out_3(board); % [7 8 12 14 15 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)==6)

pp = 1 ans = 25 ------------------ pp = 2 ans = 300 ------------------ pp = 3 ans = 2300 ------------------ pp = 4 ans = 4214 ------------------ pp = 5 ans = 4937 ------------------ pp = 6 ans = 5206 ------------------ ans = logical 1 moves = 12 7 8 14 15 21

6   Pass
board = [0 0 0 1 0 0 0 0 0 0 0 1 1 1 0 0 1 0 0 0 0 1 0 0 0]; moves = lights_out_3(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)==6)

pp = 1 ans = 25 ------------------ pp = 2 ans = 300 ------------------ pp = 3 ans = 2300 ------------------ pp = 4 ans = 4382 ------------------ pp = 5 ans = 4951 ------------------ pp = 6 ans = 5295 ------------------ ans = logical 1 moves = 9 13 3 2 6 11

7   Pass
board = [0 1 0 0 0 0 1 1 0 1 0 1 0 0 1 1 0 0 1 0 1 1 0 1 0]; moves = lights_out_3(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)==6)

pp = 1 ans = 25 ------------------ pp = 2 ans = 300 ------------------ pp = 3 ans = 2300 ------------------ pp = 4 ans = 4340 ------------------ pp = 5 ans = 4738 ------------------ pp = 6 ans = 4847 ------------------ ans = logical 1 moves = 7 23 19 9 3 4

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

pp = 1 ans = 25 ------------------ pp = 2 ans = 300 ------------------ pp = 3 ans = 2300 ------------------ pp = 4 ans = 4178 ------------------ pp = 5 ans = 4943 ------------------ pp = 6 ans = 5088 ------------------ ans = logical 1 moves = 3 23 18 14 9 5

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

pp = 1 ans = 25 ------------------ pp = 2 ans = 300 ------------------ pp = 3 ans = 2300 ------------------ pp = 4 ans = 4359 ------------------ pp = 5 ans = 4823 ------------------ pp = 6 ans = 5060 ------------------ ans = logical 1 moves = 16 14 8 3 6 1

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

pp = 1 ans = 25 ------------------ pp = 2 ans = 300 ------------------ pp = 3 ans = 2300 ------------------ pp = 4 ans = 4180 ------------------ pp = 5 ans = 4753 ------------------ pp = 6 ans = 4816 ------------------ ans = logical 1 moves = 3 6 2 4 10 5

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

pp = 1 ans = 25 ------------------ pp = 2 ans = 300 ------------------ pp = 3 ans = 2300 ------------------ pp = 4 ans = 4032 ------------------ pp = 5 ans = 4813 ------------------ pp = 6 ans = 5372 ------------------ ans = logical 1 moves = 11 8 9 14 18 23

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

pp = 1 ans = 25 ------------------ pp = 2 ans = 300 ------------------ pp = 3 ans = 2300 ------------------ pp = 4 ans = 4555 ------------------ pp = 5 ans = 5266 ------------------ pp = 6 ans = 5239 ------------------ ans = logical 1 moves = 1 6 12 18 24 25

### Community Treasure Hunt

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

Start Hunting!