login
a(n) is the Manhattan distance between n and 1 in a 3-dimensional cubic spiral of positive integers with 1..8 at the center (illustration in the comments).
0

%I #17 Aug 17 2018 11:02:20

%S 0,1,2,1,2,3,2,1,2,3,4,3,4,3,4,3,4,5,4,5,6,5,4,5,4,3,2,3,2,3,4,3,4,5,

%T 4,3,2,3,4,3,2,3,2,1,2,1,2,3,4,3,4,5,4,3,4,3,2,3,2,3,2,3,2,1,2

%N a(n) is the Manhattan distance between n and 1 in a 3-dimensional cubic spiral of positive integers with 1..8 at the center (illustration in the comments).

%C Similar to A214526, but three-dimensional, and the core is 2 X 2 X 2 rather than 1 X 1.

%C The spiral begins as follows:

%C Level z=-2:

%C 95 94 93 92 91 90

%C 96 77 76 75 74 89

%C 97 78 67 66 73 88

%C 98 79 68 65 72 87

%C 99 80 69 70 71 86

%C 100 81 82 83 84 85

%C z=-1:

%C 116 115 114 113 112 111

%C 117 52 51 50 49 110

%C 118 53 62 61 60 109

%C 119 54 63 64 59 108

%C 120 55 56 57 58 107

%C 101 102 103 104 105 106

%C z=0:

%C 137 136 135 134 133 132

%C 138 39 38 37 48 131

%C 139 40 3 2 47 130

%C 140 41 4 1 46 129

%C 121 42 43 44 45 128

%C 122 123 124 125 126 127

%C z=1:

%C 144 145 146 147 148 149

%C 143 34 35 36 25 150

%C 142 33 6 7 26 151

%C 141 32 5 8 27 152

%C 160 31 30 29 28 153

%C 159 158 157 156 155 154

%C z=2:

%C 165 166 167 168 169 170

%C 164 21 22 23 24 171

%C 163 20 11 12 13 172

%C 162 19 10 9 14 173

%C 161 18 17 16 15 174

%C 180 179 178 177 176 175

%C z=3:

%C 186 187 188 189 190 191

%C 185 204 205 206 207 192

%C 184 203 214 215 208 193

%C 183 202 213 216 209 194

%C 182 201 212 211 210 195

%C 181 200 199 198 197 196

%C Algorithm sketch:

%C 1. At every x-y plane the direction is clockwise if z > 0 and counterclockwise if z <= 0.

%C 2. After an N*N cube is complete and we start building an M*M cube, M=N+2:

%C 2a. The spiral at the first new edge of the M*M cube progresses from center to edges, in the same way as the A214526 spiral, e.g., z=-2 in the illustration.

%C 2b. Between the first and last z-edges the spiral progresses according to item 1.

%C 2c. The spiral at the last new edge of the M*M cube progresses from edges to center, e.g., z=3 in the illustration.

%F abs( a(n) - a(n-1) ) = 1.

%Y Cf. A214526.

%K nonn

%O 1,3

%A _Alex Ratushnyak_, Oct 05 2016