MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply TodayIncorrect

101Size

Leading solution size is 11.
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test

Code Input and Output

1

Pass

%% n = 4; d = 2; %p = isprime(spiral(n));imagesc(p) assert(isequal(prime_spiral(n),d))

ans = Columns 1 through 6 [0x1 logical] [0x1 logical] [0x1 logical] [0] [2x1 logical] [3x1 logical] Columns 7 through 12 [4x1 logical] [3x1 logical] [2x1 logical] [0] [0x1 logical] [0x1 logical] Column 13 [0x1 logical] c1 = 0 0 0 0 1 0 2 1 1 0 0 0 0 ans = Columns 1 through 6 [0x1 logical] [0x1 logical] [0x1 logical] [1] [2x1 logical] [3x1 logical] Columns 7 through 12 [4x1 logical] [3x1 logical] [2x1 logical] [1] [0x1 logical] [0x1 logical] Column 13 [0x1 logical] c2 = 0 0 0 1 0 2 1 1 0 1 0 0 0 ans = 2

2

Pass

%% n = 7; d = 4; assert(isequal(prime_spiral(n),d))

ans = Columns 1 through 6 [1] [2x1 logical] [3x1 logical] [4x1 logical] [5x1 logical] [6x1 logical] Columns 7 through 11 [7x1 logical] [6x1 logical] [5x1 logical] [4x1 logical] [3x1 logical] Columns 12 through 13 [2x1 logical] [0] c1 = 1 0 1 0 3 0 3 1 2 0 1 0 0 ans = Columns 1 through 6 [1] [2x1 logical] [3x1 logical] [4x1 logical] [5x1 logical] [6x1 logical] Columns 7 through 11 [7x1 logical] [6x1 logical] [5x1 logical] [4x1 logical] [3x1 logical] Columns 12 through 13 [2x1 logical] [1] c2 = 1 0 2 0 2 1 3 0 4 0 1 0 1 ans = 4

3

Pass

%% n = 13; d = 5; assert(isequal(prime_spiral(n),d))

ans = Columns 1 through 5 [7x1 logical] [8x1 logical] [9x1 logical] [10x1 logical] [11x1 logical] Columns 6 through 10 [12x1 logical] [13x1 logical] [12x1 logical] [11x1 logical] [10x1 logical] Columns 11 through 13 [9x1 logical] [8x1 logical] [7x1 logical] c1 = 2 0 1 0 5 0 3 1 2 0 1 0 1 ans = Columns 1 through 5 [7x1 logical] [8x1 logical] [9x1 logical] [10x1 logical] [11x1 logical] Columns 6 through 10 [12x1 logical] [13x1 logical] [12x1 logical] [11x1 logical] [10x1 logical] Columns 11 through 13 [9x1 logical] [8x1 logical] [7x1 logical] c2 = 2 0 3 0 2 1 3 0 5 0 1 0 4 ans = 5

4

Fail

%% n = 52; d = 6; assert(isequal(prime_spiral(n),d))

Error: Assertion failed.

5

Fail

%% n = 81; d = 9; assert(isequal(prime_spiral(n),d))

Error: Assertion failed.