Cody

# Problem 44765. Lights Out 11 - 5x5, with wrapping, x moves

Solution 1955897

Submitted on 2 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 0 0 0 1 1 1 1 0 1 0 1 1 1 0 1 1 1 0 0 0 0 0 1 1]; moves = lights_out_11(board); % [2 4 13 25] b1 = diag(ones(1,5),0) + diag(ones(1,4),1) + diag(ones(1,4),-1); b1(1,5) = 1; b1(5,1) = 1; b2 = eye(5); b3 = zeros(5); b_map = [b1,b2,b3,b3,b2; b2,b1,b2,b3,b3; b3,b2,b1,b2,b3; b3,b3,b2,b1,b2; b2,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)

moves = 13 2 4 25

2   Pass
board = [1 1 0 1 1 1 0 0 0 1 0 0 0 0 0 1 0 0 0 1 1 1 0 1 1]; moves = lights_out_11(board); % [1 5 21 25] b1 = diag(ones(1,5),0) + diag(ones(1,4),1) + diag(ones(1,4),-1); b1(1,5) = 1; b1(5,1) = 1; b2 = eye(5); b3 = zeros(5); b_map = [b1,b2,b3,b3,b2; b2,b1,b2,b3,b3; b3,b2,b1,b2,b3; b3,b3,b2,b1,b2; b2,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)

moves = 1 5 21 25

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_11(board); % [2 6 8 12 14 18 20 24] b1 = diag(ones(1,5),0) + diag(ones(1,4),1) + diag(ones(1,4),-1); b1(1,5) = 1; b1(5,1) = 1; b2 = eye(5); b3 = zeros(5); b_map = [b1,b2,b3,b3,b2; b2,b1,b2,b3,b3; b3,b2,b1,b2,b3; b3,b3,b2,b1,b2; b2,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)

moves = 3 23 11 15

4   Pass
board = [1 1 0 0 0 0 1 0 1 1 0 0 0 0 1 0 0 0 1 1 1 0 0 1 1]; moves = lights_out_11(board); % [3 7 17 21 23:25] b1 = diag(ones(1,5),0) + diag(ones(1,4),1) + diag(ones(1,4),-1); b1(1,5) = 1; b1(5,1) = 1; b2 = eye(5); b3 = zeros(5); b_map = [b1,b2,b3,b3,b2; b2,b1,b2,b3,b3; b3,b2,b1,b2,b3; b3,b3,b2,b1,b2; b2,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)

moves = 24 5 6 16 21

5   Pass
board = [0 1 1 1 0 1 1 0 1 1 1 0 1 0 1 1 1 0 1 1 0 1 1 1 0]; moves = lights_out_11(board); % [7:9 12:14 17:19] b1 = diag(ones(1,5),0) + diag(ones(1,4),1) + diag(ones(1,4),-1); b1(1,5) = 1; b1(5,1) = 1; b2 = eye(5); b3 = zeros(5); b_map = [b1,b2,b3,b3,b2; b2,b1,b2,b3,b3; b3,b2,b1,b2,b3; b3,b3,b2,b1,b2; b2,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)

moves = 2 10 18 5 15 19 20

6   Pass
board = [0 1 1 1 0 0 1 1 1 0 0 1 1 1 0 0 1 1 1 0 0 1 1 1 0]; moves = lights_out_11(board); % [11:15] b1 = diag(ones(1,5),0) + diag(ones(1,4),1) + diag(ones(1,4),-1); b1(1,5) = 1; b1(5,1) = 1; b2 = eye(5); b3 = zeros(5); b_map = [b1,b2,b3,b3,b2; b2,b1,b2,b3,b3; b3,b2,b1,b2,b3; b3,b3,b2,b1,b2; b2,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)

moves = 11 13 12 14 15

7   Pass
board = [1 1 1 0 0 0 0 1 0 0 1 1 1 1 1 1 0 0 1 0 1 1 0 1 0]; moves = lights_out_11(board); % [9 11 14 21 23 25] b1 = diag(ones(1,5),0) + diag(ones(1,4),1) + diag(ones(1,4),-1); b1(1,5) = 1; b1(5,1) = 1; b2 = eye(5); b3 = zeros(5); b_map = [b1,b2,b3,b3,b2; b2,b1,b2,b3,b3; b3,b2,b1,b2,b3; b3,b3,b2,b1,b2; b2,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)

moves = 5 13 15 10 4 24

8   Pass
board = [1 1 0 1 1 1 1 0 1 1 0 0 1 0 0 1 1 0 1 1 1 1 0 1 1]; moves = lights_out_11(board); % on your own b1 = diag(ones(1,5),0) + diag(ones(1,4),1) + diag(ones(1,4),-1); b1(1,5) = 1; b1(5,1) = 1; b2 = eye(5); b3 = zeros(5); b_map = [b1,b2,b3,b3,b2; b2,b1,b2,b3,b3; b3,b2,b1,b2,b3; b3,b3,b2,b1,b2; b2,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)

moves = 1 20 8 9 14 18 23

9   Pass
board = [0 0 1 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1 0 1]; moves = lights_out_11(board); b1 = diag(ones(1,5),0) + diag(ones(1,4),1) + diag(ones(1,4),-1); b1(1,5) = 1; b1(5,1) = 1; b2 = eye(5); b3 = zeros(5); b_map = [b1,b2,b3,b3,b2; b2,b1,b2,b3,b3; b3,b2,b1,b2,b3; b3,b3,b2,b1,b2; b2,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)

moves = 11 21 13 7 2 23

10   Pass
board = [1 0 0 0 1 0 1 1 1 0 0 1 1 1 0 0 1 1 1 0 1 0 0 0 1]; moves = lights_out_11(board); b1 = diag(ones(1,5),0) + diag(ones(1,4),1) + diag(ones(1,4),-1); b1(1,5) = 1; b1(5,1) = 1; b2 = eye(5); b3 = zeros(5); b_map = [b1,b2,b3,b3,b2; b2,b1,b2,b3,b3; b3,b2,b1,b2,b3; b3,b3,b2,b1,b2; b2,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)

moves = 13 2 22 4 24

### Community Treasure Hunt

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

Start Hunting!