Cody

# Problem 659. How long is the longest prime diagonal?

Solution 178690

Submitted on 18 Dec 2012 by Gwendolyn Fischer
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
%% n = 4; d = 2; %p = isprime(spiral(n));imagesc(p) assert(isequal(prime_spiral(n),d))

``` ans = Columns 1 through 6 [0x1 logical] [0] [2x1 logical] [3x1 logical] [4x1 logical] [3x1 logical] Columns 7 through 9 [2x1 logical] [0] [0x1 logical] c1 = 0 0 1 0 2 1 1 0 0 ans = Columns 1 through 6 [0x1 logical] [1] [2x1 logical] [3x1 logical] [4x1 logical] [3x1 logical] Columns 7 through 9 [2x1 logical] [1] [0x1 logical] c2 = 0 1 0 2 1 1 0 1 0 ans = 2 ```

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

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

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

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

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

``` ans = Columns 1 through 6 [0x1 logical] [0] [2x1 logical] [3x1 logical] [4x1 logical] [5x1 logical] Columns 7 through 11 [6x1 logical] [7x1 logical] [8x1 logical] [9x1 logical] [10x1 logical] Columns 12 through 16 [11x1 logical] [12x1 logical] [13x1 logical] [14x1 logical] [15x1 logical] Columns 17 through 21 [16x1 logical] [17x1 logical] [18x1 logical] [19x1 logical] [20x1 logical] Columns 22 through 26 [21x1 logical] [22x1 logical] [23x1 logical] [24x1 logical] [25x1 logical] Columns 27 through 31 [26x1 logical] [27x1 logical] [28x1 logical] [29x1 logical] [30x1 logical] Columns 32 through 36 [31x1 logical] [32x1 logical] [33x1 logical] [34x1 logical] [35x1 logical] Columns 37 through 41 [36x1 logical] [37x1 logical] [38x1 logical] [39x1 logical] [40x1 logical] Columns 42 through 46 [41x1 logical] [42x1 logical] [43x1 logical] [44x1 logical] [45x1 logical] Columns 47 through 51 [46x1 logical] [47x1 logical] [48x1 logical] [49x1 logical] [50x1 logical] Columns 52 through 56 [51x1 logical] [52x1 logical] [51x1 logical] [50x1 logical] [49x1 logical] Columns 57 through 61 [48x1 logical] [47x1 logical] [46x1 logical] [45x1 logical] [44x1 logical] Columns 62 through 66 [43x1 logical] [42x1 logical] [41x1 logical] [40x1 logical] [39x1 logical] Columns 67 through 71 [38x1 logical] [37x1 logical] [36x1 logical] [35x1 logical] [34x1 logical] Columns 72 through 76 [33x1 logical] [32x1 logical] [31x1 logical] [30x1 logical] [29x1 logical] Columns 77 through 81 [28x1 logical] [27x1 logical] [26x1 logical] [25x1 logical] [24x1 logical] Columns 82 through 86 [23x1 logical] [22x1 logical] [21x1 logical] [20x1 logical] [19x1 logical] Columns 87 through 91 [18x1 logical] [17x1 logical] [16x1 logical] [15x1 logical] [14x1 logical] Columns 92 through 96 [13x1 logical] [12x1 logical] [11x1 logical] [10x1 logical] [9x1 logical] Columns 97 through 101 [8x1 logical] [7x1 logical] [6x1 logical] [5x1 logical] [4x1 logical] Columns 102 through 105 [3x1 logical] [2x1 logical] [0] [0x1 logical] c1 = Columns 1 through 16 0 0 0 0 1 0 1 0 1 0 1 0 3 0 1 0 Columns 17 through 32 2 0 1 0 3 0 2 0 3 0 2 0 2 0 3 0 Columns 33 through 48 3 0 2 0 3 0 1 0 2 0 3 0 2 0 2 0 Columns 49 through 64 2 0 5 0 3 1 4 0 2 0 2 0 2 0 3 0 Columns 65 through 80 1 0 4 0 5 0 2 0 1 0 1 0 1 0 2 0 Columns 81 through 96 3 0 2 0 2 0 1 0 1 0 1 0 3 0 1 0 Columns 97 through 105 2 0 1 0 0 0 0 0 0 ans = Columns 1 through 6 [0x1 logical] [0] [2x1 logical] [3x1 logical] [4x1 logical] [5x1 logical] Columns 7 through 11 [6x1 logical] [7x1 logical] [8x1 logical] [9x1 logical] [10x1 logical] Columns 12 through 16 [11x1 logical] [12x1 logical] [13x1 logical] [14x1 logical] [15x1 logical] Columns 17 through 21 [16x1 logical] [17x1 logical] [18x1 logical] [19x1 logical] [20x1 logical] Columns 22 through 26 [21x1 logical] [22x1 logical] [23x1 logical] [24x1 logical] [25x1 logical] Columns 27 through 31 [26x1 logical] [27x1 logical] [28x1 logical] [29x1 logical] [30x1 logical] Columns 32 through 36 [31x1 logical] [32x1 logical] [33x1 logical] [34x1 logical] [35x1 logical] Columns 37 through 41 [36x1 logical] [37x1 logical] [38x1 logical] [39x1 logical] [40x1 logical] Columns 42 through 46 [41x1 logical] [42x1 logical] [43x1 logical] [44x1 logical] [45x1 logical] Columns 47 through 51 [46x1 logical] [47x1 logical] [48x1 logical] [49x1 logical] [50x1 logical] Columns 52 through 56 [51x1 logical] [52x1 logical] [51x1 logical] [50x1 logical] [49x1 logical] Columns 57 through 61 [48x1 logical] [47x1 logical] [46x1 logical] [45x1 logical] [44x1 logical] Columns 62 through 66 [43x1 logical] [42x1 logical] [41x1 logical] [40x1 logical] [39x1 logical] Columns 67 through 71 [38x1 logical] [37x1 logical] [36x1 logical] [35x1 logical] [34x1 logical] Columns 72 through 76 [33x1 logical] [32x1 logical] [31x1 logical] [30x1 logical] [29x1 logical] Columns 77 through 81 [28x1 logical] [27x1 logical] [26x1 logical] [25x1 logical] [24x1 logical] Columns 82 through 86 [23x1 logical] [22x1 logical] [21x1 logical] [20x1 logical] [19x1 logical] Columns 87 through 91 [18x1 logical] [17x1 logical] [16x1 logical] [15x1 logical] [14x1 logical] Columns 92 through 96 [13x1 logical] [12x1 logical] [11x1 logical] [10x1 logical] [9x1 logical] Columns 97 through 101 [8x1 logical] [7x1 logical] [6x1 logical] [5x1 logical] [4x1 logical] Columns 102 through 105 [3x1 logical] [2x1 logical] [1] [0x1 logical] c2 = Columns 1 through 16 0 0 0 0 0 1 0 2 0 1 0 2 0 2 0 1 Columns 17 through 32 0 3 0 2 0 1 0 2 0 5 0 0 0 3 0 4 Columns 33 through 48 0 1 0 4 0 2 0 1 0 2 0 2 0 1 0 4 Columns 49 through 64 0 3 0 2 1 3 0 5 0 1 0 6 0 5 0 1 Columns 65 through 80 0 4 0 2 0 1 0 2 0 4 0 1 0 3 0 2 Columns 81 through 96 0 1 0 2 0 1 0 1 0 6 0 2 0 0 0 2 Columns 97 through 105 0 2 0 1 0 1 0 1 0 ans = 6 ```

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

``` ans = Columns 1 through 6 [0x1 logical] [0] [2x1 logical] [3x1 logical] [4x1 logical] [5x1 logical] Columns 7 through 11 [6x1 logical] [7x1 logical] [8x1 logical] [9x1 logical] [10x1 logical] Columns 12 through 16 [11x1 logical] [12x1 logical] [13x1 logical] [14x1 logical] [15x1 logical] Columns 17 through 21 [16x1 logical] [17x1 logical] [18x1 logical] [19x1 logical] [20x1 logical] Columns 22 through 26 [21x1 logical] [22x1 logical] [23x1 logical] [24x1 logical] [25x1 logical] Columns 27 through 31 [26x1 logical] [27x1 logical] [28x1 logical] [29x1 logical] [30x1 logical] Columns 32 through 36 [31x1 logical] [32x1 logical] [33x1 logical] [34x1 logical] [35x1 logical] Columns 37 through 41 [36x1 logical] [37x1 logical] [38x1 logical] [39x1 logical] [40x1 logical] Columns 42 through 46 [41x1 logical] [42x1 logical] [43x1 logical] [44x1 logical] [45x1 logical] Columns 47 through 51 [46x1 logical] [47x1 logical] [48x1 logical] [49x1 logical] [50x1 logical] Columns 52 through 56 [51x1 logical] [52x1 logical] [53x1 logical] [54x1 logical] [55x1 logical] Columns 57 through 61 [56x1 logical] [57x1 logical] [58x1 logical] [59x1 logical] [60x1 logical] Columns 62 through 66 [61x1 logical] [62x1 logical] [63x1 logical] [64x1 logical] [65x1 logical] Columns 67 through 71 [66x1 logical] [67x1 logical] [68x1 logical] [69x1 logical] [70x1 logical] Columns 72 through 76 [71x1 logical] [72x1 logical] [73x1 logical] [74x1 logical] [75x1 logical] Columns 77 through 81 [76x1 logical] [77x1 logical] [78x1 logical] [79x1 logical] [80x1 logical] Columns 82 through 86 [81x1 logical] [80x1 logical] [79x1 logical] [78x1 logical] [77x1 logical] Columns 87 through 91 [76x1 logical] [75x1 logical] [74x1 logical] [73x1 logical] [72x1 logical] Columns 92 through 96 [71x1 logical] [70x1 logical] [69x1 logical] [68x1 logical] [67x1 logical] Columns 97 through 101 [66x1 logical] [65x1 logical] [64x1 logical] [63x1 logical] [62x1 logical] Columns 102 through 106 [61x1 logical] [60x1 logical] [59x1 logical] [58x1 logical] [57x1 logical] Columns 107 through 111 [56x1 logical] [55x1 logical] [54x1 logical] [53x1 logical] [52x1 logical] Columns 112 through 116 [51x1 logical] [50x1 logical] [49x1 logical] [48x1 logical] [47x1 logical] Columns 117 through 121 [46x1 logical] [45x1 logical] [44x1 logical] [43x1 logical] [42x1 logical] Columns 122 through 126 [41x1 logical] [40x1 logical] [39x1 logical] [38x1 logical] [37x1 logical] Columns 127 through 131 [36x1 logical] [35x1 logical] [34x1 logical] [33x1 logical] [32x1 logical] Columns 132 through 136 [31x1 logical] [30x1 logical] [29x1 logical] [28x1 logical] [27x1 logical] Columns 137 through 141 [26x1 logical] [25x1 logical] [24x1 logical] [23x1 logical] [22x1 logical] Columns 142 through 146 [21x1 logical] [20x1 logical] [19x1 logical] [18x1 logical] [17x1 logical] Columns 147 through 151 [16x1 logical] [15x1 logical] [14x1 logical] [13x1 logical] [12x1 logical] Columns 152 through 156 [11x1 logical] [10x1 logical] [9x1 logical] [8x1 logical] [7x1 logical] Columns 157 through 162 [6x1 logical] [5x1 logical] [4x1 logical] [3x1 logical] [2x1 logical] [0] Column 163 [0x1 logical] c1 = Columns 1 through 16 0 0 0 0 0 1 0 3 0 1 0 1 0 3 0 1 Columns 17 through 32 0 1 0 2 0 1 0 2 0 1 0 2 0 2 0 3 Columns 33 through 48 0 2 0 4 0 2 0 1 0 7 0 1 0 2 0 2 Columns 49 through 64 0 4 0 2 0 3 0 2 0 2 0 3 0 4 0 2 Columns 65 through 80 0 3 0 3 0 2 0 3 0 3 0 2 0 2 0 5 Columns 81 through 96 0 3 1 4 0 2 0 2 0 2 0 4 0 2 0 4 Columns 97 through 112 0 5 0 2 0 3 0 3 0 1 0 2 0 3 0 2 Columns 113 through 128 0 2 0 1 0 2 0 3 0 9 0 1 0 3 0 1 Columns 129 through 144 0 2 0 3 0 2 0 2 0 1 0 3 0 1 0 1 Columns 145 through 160 0 1 0 2 0 1 0 1 0 1 0 1 0 0 0 0 Columns 161 through 163 0 0 0 ans = Columns 1 through 6 [0x1 logical] [0] [2x1 logical] [3x1 logical] [4x1 logical] [5x1 logical] Columns 7 through 11 [6x1 logical] [7x1 logical] [8x1 logical] [9x1 logical] [10x1 logical] Columns 12 through 16 [11x1 logical] [12x1 logical] [13x1 logical] [14x1 logical] [15x1 logical] Columns 17 through 21 [16x1 logical] [17x1 logical] [18x1 logical] [19x1 logical] [20x1 logical] Columns 22 through 26 [21x1 logical] [22x1 logical] [23x1 logical] [24x1 logical] [25x1 logical] Columns 27 through 31 [26x1 logical] [27x1 logical] [28x1 logical] [29x1 logical] [30x1 logical] Columns 32 through 36 [31x1 logical] [32x1 logical] [33x1 logical] [34x1 logical] [35x1 logical] Columns 37 through 41 [36x1 logical] [37x1 logical] [38x1 logical] [39x1 logical] [40x1 logical] Columns 42 through 46 [41x1 logical] [42x1 logical] [43x1 logical] [44x1 logical] [45x1 logical] Columns 47 through 51 [46x1 logical] [47x1 logical] [48x1 logical] [49x1 logical] [50x1 logical] Columns 52 through 56 [51x1 logical] [52x1 logical] [53x1 logical] [54x1 logical] [55x1 logical] Columns 57 through 61 [56x1 logical] [57x1 logical] [58x1 logical] [59x1 logical] [60x1 logical] Columns 62 through 66 [61x1 logical] [62x1 logical] [63x1 logical] [64x1 logical] [65x1 logical] Columns 67 through 71 [66x1 logical] [67x1 logical] [68x1 logical] [69x1 logical] [70x1 logical] Columns 72 through 76 [71x1 logical] [72x1 logical] [73x1 logical] [74x1 logical] [75x1 logical] Columns 77 through 81 [76x1 logical] [77x1 logical] [78x1 logical] [79x1 logical] [80x1 logical] Columns 82 through 86 [81x1 logical] [80x1 logical] [79x1 logical] [78x1 logical] [77x1 logical] Columns 87 through 91 [76x1 logical] [75x1 logical] [74x1 logical] [73x1 logical] [72x1 logical] Columns 92 through 96 [71x1 logical] [70x1 logical] [69x1 logical] [68x1 logical] [67x1 logical] Columns 97 through 101 [66x1 logical] [65x1 logical] [64x1 logical] [63x1 logical] [62x1 logical] Columns 102 through 106 [61x1 logical] [60x1 logical] [59x1 logical] [58x1 logical] [57x1 logical] Columns 107 through 111 [56x1 logical] [55x1 logical] [54x1 logical] [53x1 logical] [52x1 logical] Columns 112 through 116 [51x1 logical] [50x1 logical] [49x1 logical] [48x1 logical] [47x1 logical] Columns 117 through 121 [46x1 logical] [45x1 logical] [44x1 logical] [43x1 logical] [42x1 logical] Columns 122 through 126 [41x1 logical] [40x1 logical] [39x1 logical] [38x1 logical] [37x1 logical] Columns 127 through 131 [36x1 logical] [35x1 logical] [34x1 logical] [33x1 logical] [32x1 logical] Columns 132 through 136 [31x1 logical] [30x1 logical] [29x1 logical] [28x1 logical] [27x1 logical] Columns 137 through 141 [26x1 logical] [25x1 logical] [24x1 logical] [23x1 logical] [22x1 logical] Columns 142 through 146 [21x1 logical] [20x1 logical] [19x1 logical] [18x1 logical] [17x1 logical] Columns 147 through 151 [16x1 logical] [15x1 logical] [14x1 logical] [13x1 logical] [12x1 logical] Columns 152 through 156 [11x1 logical] [10x1 logical] [9x1 logical] [8x1 logical] [7x1 logical] Columns 157 through 162 [6x1 logical] [5x1 logical] [4x1 logical] [3x1 logical] [2x1 logical] [1] Column 163 [0x1 logical] c2 = Columns 1 through 16 0 0 0 2 0 1 0 1 0 1 0 1 0 1 0 1 Columns 17 through 32 0 2 0 0 0 2 0 6 0 1 0 1 0 2 0 1 Columns 33 through 48 0 2 0 2 0 1 0 3 0 2 0 1 0 3 0 3 Columns 49 through 64 0 1 0 2 0 5 0 1 0 3 0 4 0 1 0 4 Columns 65 through 80 0 2 0 1 0 2 0 2 0 1 0 4 0 3 0 2 Columns 81 through 96 1 3 0 5 0 1 0 6 0 5 0 1 0 4 0 2 Columns 97 through 112 0 1 0 2 0 4 0 1 0 3 0 2 0 1 0 2 Columns 113 through 128 0 4 0 1 0 6 0 3 0 1 0 3 0 2 0 1 Columns 129 through 144 0 2 0 2 0 1 0 2 0 2 0 1 0 1 0 2 Columns 145 through 160 0 1 0 3 0 5 0 1 0 1 0 1 0 0 0 1 Columns 161 through 163 0 1 ...```