Cody

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

Solution 2867807

Submitted on 22 Aug 2020 by Alfonso Nieto-Castanon
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)

iteration 2: value 12.374369 (state = [0 1 0 0 1 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0]) iteration 3: value 9.093267 (state = [0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0]) iteration 4: value 6.000000 (state = [0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0]) iteration 17: value 0.000000 (state = [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]) moves: [14 1 18 14 10] value trajectory: [23.3345237791561 15.1554445662277 10.5 12.2983738762488 12.8598211496117 0]

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)

iteration 2: value 9.899495 (state = [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]) iteration 3: value 6.062178 (state = [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0]) iteration 4: value 0.000000 (state = [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]) moves: [13 1 25] value trajectory: [21.2132034355964 12.1243556529821 7 0]

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)

iteration 2: value 19.798990 (state = [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]) iteration 3: value 18.186533 (state = [0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 1 0 1 0 1 0]) iteration 4: value 14.000000 (state = [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 1 0 1 0]) iteration 5: value 7.826238 (state = [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0]) iteration 6: value 0.000000 (state = [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]) moves: [13 1 5 21 25] value trajectory: [31.1126983722081 24.2487113059643 21 15.6524758424985 8.57321409974112 0]

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)

iteration 9: value 17.753521 (state = [1 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 0 0 0 0 0]) iteration 11: value 11.739357 (state = [0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0]) iteration 12: value 9.797959 (state = [0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0]) iteration 24: value 0.000000 (state = [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]) moves: [7 9 2 6 10 8 2] value trajectory: [30.0520382004283 30.7439018343476 20.5 20.1246117974981 16.5340557637865 14.5516322108552 14.8492424049175 0]

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)

iteration 4: value 24.000000 (state = [1 1 1 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 1 0 0 1]) iteration 6: value 20.820663 (state = [1 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 1]) iteration 8: value 18.384776 (state = [1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 1]) iteration 9: value 9.000000 (state = [1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1]) iteration 54: value 0.000000 (state = [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]) moves: [18 5 25 2 6 1 11 21 2 8 14 20] value trajectory: [37.8302127934803 32.9089653438087 31 26.8328157299975 26.3320147349192 22.488886144049 24.0416305603426 19.5 9.48683298050514 17.4122801493658 19.0525588832576 18.9291441961859 0]

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)

iteration 2: value 19.798990 (state = [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]) iteration 3: value 18.186533 (state = [0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 1 0 1 0 1 0]) iteration 4: value 14.000000 (state = [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 1 0 1 0]) iteration 5: value 7.826238 (state = [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0]) iteration 6: value 0.000000 (state = [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]) moves: [13 1 5 21 25] value trajectory: [31.1126983722081 24.2487113059643 21 15.6524758424985 8.57321409974112 0]

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)

iteration 3: value 12.124356 (state = [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 1 0 1 0]) iteration 4: value 7.000000 (state = [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0]) iteration 5: value 0.000000 (state = [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]) moves: [1 5 21 25] value trajectory: [19.7989898732233 18.1865334794732 14 7.82623792124926 0]

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)

iteration 434: value 7.937254 (state = [0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0]) iteration 436: value 0.000000 (state = [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]) moves: [6 4 8 20 18 22] value trajectory: [13.4350288425444 14.2894191624432 21 15.0934588481236 13.4721935853075 13.8901943830891 0]

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)

iteration 3: value 25.547749 (state = [1 1 0 0 0 0 1 0 1 0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0]) iteration 4: value 25.000000 (state = [1 1 0 0 1 0 1 0 0 0 0 0 0 1 0 1 1 0 0 0 0 0 0 0 0]) iteration 5: value 24.037731 (state = [0 1 1 0 1 0 0 0 0 0 0 0 0 1 0 1 1 0 0 0 0 0 0 0 0]) iteration 6: value 23.270153 (state = [0 1 0 0 0 0 0 0 1 0 0 0 0 1 0 1 1 0 0 0 0 0 0 0 0]) iteration 8: value 20.820663 (state = [0 1 0 0 1 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 1 0 0 0 0]) iteration 10: value 19.798990 (state = [0 0 0 0 1 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 1 0 0 0 0]) iteration 68: value 19.500000 (state = [0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 1 0 0 0]) iteration 69: value 9.486833 (state = [0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0]) iteration 114: value 0.000000 (state = [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]) moves: [9 25 10 6 16 1 11 17 21 4 8 12 16] value trajectory: [36.4159992311072 31.609927238132 29.5 27.9508497187474 26.3320147349192 22.488886144049 24.0416305603426 21 20.5548047910945 9.9498743710662 18.1865334794732 19.8305320150519 19.6437012805632 0]

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)

iteration 5: value 15.652476 (state = [0 0 1 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 1 0 0]) iteration 9: value 9.260130 (state = [0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0]) iteration 14: value 0.000000 (state = [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]) moves: [1 5 21 25 2 6 20 24] value trajectory: [29.698484809835 30.3108891324554 28 23.4787137637478 17.1464281994822 23.1503239718152 9.89949493661167 15.75 0]

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)

moves: [9 5 25 20 2 25 25 1] value trajectory: [20.5060966544099 24.2487113059643 21 23.4787137637478 21.4330352493528 18.5202591774521 19.7989898732233 21 22.1359436211787] moves: [7 8 9 12 13 14 17 18 19 17 2 20 5 25 25 25 1 25 25 25 1 1] value trajectory: [20.5060966544099 25.1147367097487 36.5 48.6344785106204 62.461988440971 67.4666584321471 71.4177848998413 86.25 90.1249133147988 94.5238065251289 72.7461339178928 56.7874325885578 39.2874025611264 27.1108834234519 28 28.8617393793236 29.698484809835 30.5122926047847 31.3049516849971 32.0780298646909 32.832910318764 33.570820663189 34.2928563989645] iteration 780: value 13.555442 (state = [0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0]) moves: [6 8 10 12 14 16 18 20 4 16 9 5 20 24 25 1 25 25 25 25 1] value trajectory: [20.5060966544099 22.0836477965032 41 48.6344785106204 44.0908153700972 48.2849614269288 55.1543289325507 69.75 67.9889696936202 53.8951528432752 38.1051177665153 37.8582883923719 26.1916017074176 33.8886042793149 14 14.4308696896618 14.8492424049175 15.2561463023924 15.6524758424985 16.0390149323454 16.416455159382 16.7854103315945] iteration 28: value 0.000000 (state = [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]) moves: [6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 4 16 1 23 5 15 25 20 24] value trajectory: [20.5060966544099 22.0836477965032 25.5 45.8393935387457 58.7877538267963 66.8052206043809 75.6604255869606 69 85.3814968245462 90.3780255371846 87.4685657822283 95.5471087997957 84.1872912024137 101.665812837945 107 103.077640640442 83.7921535706059 63.2040346813398 49.1934955049954 41.2431812546026 42.2137418384109 33.570820663189 17.1464281994822 26.25 0]

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)

iteration 2: value 16.970563 (state = [1 0 1 0 0 0 0 0 0 1 1 0 0 1 0 0 0 0 0 0 0 0 0 1 1]) iteration 4: value 13.000000 (state = [1 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1]) iteration 5: value 11.739357 (state = [0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1]) iteration 6: value 7.348469 (state = [1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1]) iteration 30: value 0.000000 (state = [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]) moves: [7 15 25 2 12 18 24] value trajectory: [27.5771644662754 20.7846096908265 20 14.5344418537486 12.8598211496117 14.5516322108552 14.8492424049175 0]

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)

iteration 2: value 4.949747 (state = [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0]) iteration 3: value 0.000000 (state = [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]) moves: [1 25] value trajectory: [9.89949493661167 6.06217782649107 0]

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)

iteration 2: value 9.192388 (state = [1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1]) iteration 175: value 7.937254 (state = [1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1]) iteration 223: value 0.000000 (state = [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]) moves: [21 3 5 15 9 5 2 8 14 20] value trajectory: [14.142135623731 11.2583302491977 17 19.0065778087482 17.1464281994822 17.1973835219198 8.48528137423857 15.75 17.3925271309261 17.4122801493658 0]

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)

iteration 10: value 17.146428 (state = [0 0 1 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 1 0 0]) iteration 12: value 9.899495 (state = [0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0]) iteration 17: value 0.000000 (state = [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]) moves: [1 5 21 23 25 2 6 20 24] value trajectory: [27.5771644662754 27.712812921102 25 27.9508497187474 25.7196422992234 18.5202591774521 24.7487373415292 10.5 16.601957715884 0]

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)

iteration 3: value 27.712813 (state = [1 1 0 0 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0]) iteration 4: value 25.000000 (state = [1 0 0 0 1 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0]) iteration 5: value 24.037731 (state = [0 0 1 0 1 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0]) iteration 6: value 13.472194 (state = [0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0]) iteration 7: value 10.583005 (state = [0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0]) moves: [18 15 1 2 4 21 21 23 13 13 3 3 13 13] value trajectory: [41.365746699413 37.2390923627309 32 27.9508497187474 26.3320147349192 14.5516322108552 15.556349186104 16.5 12.6491106406735 13.2664991614216 13.856406460551 19.8305320150519 14.9666295470958 15.4919333848297 16] moves: [7 8 9 12 13 14 17 18 19 8 17 20 5 16 5 5 5] value trajectory: [41.365746699413 44.6003082948986 43 48.0754615162455 61.8496160052752 66.8052206043809 70.7106781186548 75 92.4966215599251 85.4030883516515 62.3538290724796 50.4777178564959 43.9644742945938 45.5075543179371 38 39.1695034433678 40.3050865276332 41.4095399636364] iteration 15: value 29.047375 (state = [0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0]) moves: [6 8 10 12 14 16 18 20 15 1 23 16 20 18 2 13 2 15 15 13 13 13 13 13 13 13] value trajectory: [41.365746699413 47.6313972081441 54.5 65.9640053362438 63.0743608766668 47.6235235991626 65.7609306503489 70.5 78.2663720891674 63.8450272143414 54.5596004384196 51.3791056753618 48.6415460280612 45.5075543179371 30 38.1387270369634 39.2444263558534 32.6917420765551 40.2492235949962 34.3693177121688 35.1781181986757 35.9687364248454 36.7423461417477 37.5 38.2426463519459 38.9711431702997 39.6862696659689] moves: [6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 15 16 20 18 1 3 13 24 24 13 13 13 13 13 13 13 13] value trajectory: [41.365746699413 47.6313972081441 48 53.10661446562 58.1753813911005 68.7895340876794 77.7817459305202 71.25 87.7532050696725 66.332495807108 62.3538290724796 83.8290671545378 58.9311038416896 61.9677335393187 80 87.6159945443753 66.8215908221287 63.2040346813398 59.2558014037444 41.2431812546026 42.2137418384109 35.9687364248454 36.7423461417477 46.25 38.2426463519459 38.9711431702997 39.6862696659689 40.3887360535088 41.0791918128875 41.7582327212252 42.4264068711929 43.0842198490352 43.7321392113398] moves: [7 8 9 12 13 14 17 18 19 14 2 17 12 8 4 21 5 16 16 5 5] value trajectory: [21.0010714012405 31.4367221573751 33.4 35.1062672467467 45.6829837029063 51.9890132624192 60.5283404695685 61.2 50.1221009136688 63.5133647353059 38.1051177665153 34.0724595531347 27.1270160541111 32.920358442763 25 23.5017020660207 24.1830519165799 24.8457239781818 27.9508497187474 26.1206814612483 26.7353698309936 27.3362396828825] iteration 6: value 28.169132 (state = [0 1 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0]) iteration 7: value 15.874508 (state = [0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0]) iteration 9: value 15.556349 (state = [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0]) iteration 10: value 0.000000 (state = [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]) moves: [18 15 4 23 2 7 17 21] value trajectory: [39.9515331370399 42.4352447854375 38 34.1000366568718 31.2309942204855 30.4261400772428 16.9705627484771 16.5 0]

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)

iteration 5: value 15.652476 (state = [1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1]) iteration 59: value 14.551632 (state = [0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 1]) iteration 61: value 9.000000 (state = [1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1]) iteration 63: value 0.000000 (state = [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]) moves: [3 5 23 21 2 8 18 24] value trajectory: [25.4558441227157 27.712812921102 25 23.4787137637478 17.1464281994822 24.4731996273475 15.556349186104 15.75 0]

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)

iteration 63: value 10.500000 (state = [0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1]) iteration 64: value 8.944272 (state = [0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0]) iteration 149: value 7.937254 (state = [1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1]) iteration 172: value 0.000000 (state = [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]) moves: [19 17 11 10 4 8 14 20] value trajectory: [20.1525432638166 18.6195461813654 21.5 11.7393568818739 17.1464281994822 13.8901943830891 15.556349186104 15.75 0]

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)

iteration 2: value 12.727922 (state = [0 0 0 1 0 1 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0]) iteration 3: value 9.526279 (state = [0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0]) iteration 4: value 7.000000 (state = [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0]) iteration 5: value 0.000000 (state = [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]) moves: [12 5 11 21] value trajectory: [23.6880771697493 15.5884572681199 11 7.82623792124926 0]

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)

iteration 2: value 20.859650 (state = [0 1 1 1 0 0 0 1 1 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 1]) iteration 3: value 16.021470 (state = [0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 1]) iteration 4: value 14.000000 (state = [0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 1]) iteration 5: value 11.739357 (state = [0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0]) iteration 6: value 9.797959 (state = [0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0]) iteration 8: value 7.348469 (state = [0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0]) iteration 27: value 0.000000 (state = [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]) moves: [19 3 4 24 18 14 10] value trajectory: [31.4662517628014 25.5477494116409 18.5 15.6524758424985 12.8598211496117 14.5516322108552 14.8492424049175 0]

Suggested Problems

More from this Author139

Community Treasure Hunt

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

Start Hunting!