Cody

Problem 46. Which doors are open?

Solution 2848020

Submitted on 18 Aug 2020 by Drake Madison
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
x = 1; y_correct = 1; assert(isequal(which_doors_open(x),y_correct))

doors = 0 visits = 1 doors = 1 y = 1

2   Pass
x = 3; y_correct = 1; assert(isequal(which_doors_open(x),y_correct))

doors = 0 0 0 visits = 1 2 3 doors = 1 1 1 visits = 2 doors = 1 0 1 visits = 3 doors = 1 0 0 y = 1

3   Pass
x = 100; y_correct = [1 4 9 16 25 36 49 64 81 100]; assert(isequal(which_doors_open(x),y_correct))

doors = Columns 1 through 30 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 0 0 0 0 0 Columns 31 through 60 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 0 0 0 0 0 Columns 61 through 90 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 0 0 0 0 0 Columns 91 through 100 0 0 0 0 0 0 0 0 0 0 visits = Columns 1 through 30 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 Columns 31 through 60 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 Columns 61 through 90 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 Columns 91 through 100 91 92 93 94 95 96 97 98 99 100 doors = Columns 1 through 30 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 31 through 60 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 61 through 90 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 91 through 100 1 1 1 1 1 1 1 1 1 1 visits = Columns 1 through 30 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 Columns 31 through 50 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 doors = Columns 1 through 30 1 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 1 0 1 0 Columns 31 through 60 1 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 1 0 1 0 Columns 61 through 90 1 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 1 0 1 0 Columns 91 through 100 1 0 1 0 1 0 1 0 1 0 visits = Columns 1 through 30 3 6 9 12 15 18 21 24 27 30 33 36 39 42 45 48 51 54 57 60 63 66 69 72 75 78 81 84 87 90 Columns 31 through 33 93 96 99 doors = Columns 1 through 30 1 0 0 0 1 1 1 0 0 0 1 1 1 0 0 0 1 1 1 0 0 0 1 1 1 0 0 0 1 1 Columns 31 through 60 1 0 0 0 1 1 1 0 0 0 1 1 1 0 0 0 1 1 1 0 0 0 1 1 1 0 0 0 1 1 Columns 61 through 90 1 0 0 0 1 1 1 0 0 0 1 1 1 0 0 0 1 1 1 0 0 0 1 1 1 0 0 0 1 1 Columns 91 through 100 1 0 0 0 1 1 1 0 0 0 visits = 4 8 12 16 20 24 28 32 36 40 44 48 52 56 60 64 68 72 76 80 84 88 92 96 100 doors = Columns 1 through 30 1 0 0 1 1 1 1 1 0 0 1 0 1 0 0 1 1 1 1 1 0 0 1 0 1 0 0 1 1 1 Columns 31 through 60 1 1 0 0 1 0 1 0 0 1 1 1 1 1 0 0 1 0 1 0 0 1 1 1 1 1 0 0 1 0 Columns 61 through 90 1 0 0 1 1 1 1 1 0 0 1 0 1 0 0 1 1 1 1 1 0 0 1 0 1 0 0 1 1 1 Columns 91 through 100 1 1 0 0 1 0 1 0 0 1 visits = 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 doors = Columns 1 through 30 1 0 0 1 0 1 1 1 0 1 1 0 1 0 1 1 1 1 1 0 0 0 1 0 0 0 0 1 1 0 Columns 31 through 60 1 1 0 0 0 0 1 0 0 0 1 1 1 1 1 0 1 0 1 1 0 1 1 1 0 1 0 0 1 1 Columns 61 through 90 1 0 0 1 0 1 1 1 0 1 1 0 1 0 1 1 1 1 1 0 0 0 1 0 0 0 0 1 1 0 Columns 91 through 100 1 1 0 0 0 0 1 0 0 0 visits = 6 12 18 24 30 36 42 48 54 60 66 72 78 84 90 96 doors = Columns 1 through 30 1 0 0 1 0 0 1 1 0 1 1 1 1 0 1 1 1 0 1 0 0 0 1 1 0 0 0 1 1 1 Columns 31 through 60 1 1 0 0 0 1 1 0 0 0 1 0 1 1 1 0 1 1 1 1 0 1 1 0 0 1 0 0 1 0 Columns 61 through 90 1 0 0 1 0 0 1 1 0 1 1 1 1 0 1 1 1 0 1 0 0 0 1 1 0 0 0 1 1 1 Columns 91 through 100 1 1 0 0 0 1 1 0 0 0 visits = 7 14 21 28 35 42 49 56 63 70 77 84 91 98 doors = Columns 1 through 30 1 0 0 1 0 0 0 1 0 1 1 1 1 1 1 1 1 0 1 0 1 0 1 1 0 0 0 0 1 1 Columns 31 through 60 1 1 0 0 1 1 1 0 0 0 1 1 1 1 1 0 1 1 0 1 0 1 1 0 0 0 0 0 1 0 Columns 61 through 90 1 0 1 1 0 0 1 1 0 0 1 1 1 0 1 1 0 0 1 0 0 0 1 0 0 0 0 1 1 1 Columns 91 through 100 0 1 0 0 0 1 1 1 0 0 visits = 8 16 24 32 40 48 56 64 72 80 88 96 doors = Columns 1 through 30 1 0 0 1 0 0 0 0 0 1 1 1 1 1 1 0 1 0 1 0 1 0 1 0 0 0 0 0 1 1 Columns 31 through 60 1 0 0 0 1 1 1 0 0 1 1 1 1 1 1 0 1 0 0 1 0 1 1 0 0 1 0 0 1 0 Columns 61 through 90 1 0 1 0 0 0 1 1 0 0 1 0 1 0 1 1 0 0 1 1 0 0 1 0 0 0 0 0 1 1 Columns 91 through 100 0 1 0 0 0 0 1 1 0 0 visits = 9 18 27 36 45 54 63 72 81 90 99 doors = Columns 1 through 30 1 0 0 1 0 0 0 0 1 1 1 1 1 1 1 0 1 1 1 0 1 0 1 0 0 0 1 0 1 1 Columns 31 through 60 1 0 0 0 1 0 1 0 0 1 1 1 1 1 0 0 1 0 0 1 0 1 1 1 0 1 0 0 1 0 Columns 61 through 90 1 0 0 0 0 0 1 1 0 0 1 1 1 0 1 1 0 0 1 1 1 0 1 0 0 0 0 0 1 0 Columns 91 through 100 0 1 0 0 0 0 1 1 1 0 visits = 10 20 30 40 50 60 70 80 90 100 doors = Columns 1 through 30 1 0 0 1 0 0 0 0 1 0 1 1 1 1 1 0 1 1 1 1 1 0 1 0 0 0 1 0 1 0 Columns 31 through 60 1 0 0 0 1 0 1 0 0 0 1 1 1 1 0 0 1 0 0 0 0 1 1 1 0 1 0 0 1 1 Columns 61 through 90 1 0 0 0 0 0 1 1 0 1 1 1 1 0 1 1 0 0 1 0 1 0 1 0 0 0 0 0 1 1 Columns 91 through 100 0 1 0 0 0 0 1 1 1 1 visits = 11 ...

Suggested Problems

More from this Author95

Community Treasure Hunt

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

Start Hunting!