Cody

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

Solution 2393999

Submitted on 27 May 2020 by jmac
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)

Gaussian elimination returned multiple solutions: computing the shortest nMoves = 10 14 10 14

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)

Gaussian elimination returned multiple solutions: computing the shortest nMoves = 14 10 10 14

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)

Gaussian elimination returned multiple solutions: computing the shortest nMoves = 10 10 12 12

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)

Gaussian elimination returned multiple solutions: computing the shortest nMoves = 10 12 16 14

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)

Gaussian elimination returned multiple solutions: computing the shortest nMoves = 10 10 16 12

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)

Gaussian elimination returned multiple solutions: computing the shortest nMoves = 10 16 18 12

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)

Gaussian elimination returned multiple solutions: computing the shortest nMoves = 10 10 8 12

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)

Gaussian elimination returned multiple solutions: computing the shortest nMoves = 10 12 16 14

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)

Gaussian elimination returned multiple solutions: computing the shortest nMoves = 12 10 10 12

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)

Gaussian elimination returned multiple solutions: computing the shortest nMoves = 10 6 10 14

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)

Gaussian elimination returned multiple solutions: computing the shortest nMoves = 10 14 12 8

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)

Gaussian elimination returned multiple solutions: computing the shortest nMoves = 10 10 14 10

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)

Gaussian elimination returned multiple solutions: computing the shortest nMoves = 12 16 14 10

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)

Gaussian elimination returned multiple solutions: computing the shortest nMoves = 14 10 14 10

### Community Treasure Hunt

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

Start Hunting!