Cody

# Problem 803. Twist 'n' Match

Solution 1231815

Submitted on 14 Jul 2017 by Augusto Mazzei
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 = 2; m = 1; a = twist_n_match(n,m); [r,c] = size(a); assert(r==n && c==n); assert(isequal(nnz(a==rot90(a)),m));

a = 1 3 4 2 u = 1 o = 1 l = 1

2   Pass
n = 3; m = 7; a = twist_n_match(n,m); [r,c] = size(a); assert(r==n && c==n); assert(isequal(nnz(a==rot90(a)),m));

a = 8 1 6 3 5 7 4 9 2 u = 6 o = 1 o = 2 o = 4 o = 7 o = 8 o = 9 l = 9 a = 0 0 -9 0 5 0 0 0 0 l = 7

3   Pass
n = 6; m = 6; a = twist_n_match(n,m); [r,c] = size(a); assert(r==n && c==n); assert(isequal(nnz(a==rot90(a)),m));

a = 35 1 6 26 19 24 3 32 7 21 23 25 31 9 2 22 27 20 8 28 33 17 10 15 30 5 34 12 14 16 4 36 29 13 18 11 u = 6 o = 1 o = 2 o = 3 o = 4 o = 5 o = 7 l = 6

4   Pass
n = 10; m = 11; a = twist_n_match(n,m); [r,c] = size(a); assert(r==n && c==n); assert(isequal(nnz(a==rot90(a)),m));

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

5   Pass
n = 10; m = 14; a = twist_n_match(n,m); [r,c] = size(a); assert(r==n && c==n); assert(isequal(nnz(a==rot90(a)),m));

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

6   Pass
n = 20; m = 83; a = twist_n_match(n,m); [r,c] = size(a); assert(r==n && c==n); assert(isequal(nnz(a==rot90(a)),m));

a = 400 2 3 397 396 6 7 393 392 10 11 389 388 14 15 385 384 18 19 381 21 379 378 24 25 375 374 28 29 371 370 32 33 367 366 36 37 363 362 40 41 359 358 44 45 355 354 48 49 351 350 52 53 347 346 56 57 343 342 60 340 62 63 337 336 66 67 333 332 70 71 329 328 74 75 325 324 78 79 321 320 82 83 317 316 86 87 313 312 90 91 309 308 94 95 305 304 98 99 301 101 299 298 104 105 295 294 108 109 291 290 112 113 287 286 116 117 283 282 120 121 279 278 124 125 275 274 128 129 271 270 132 133 267 266 136 137 263 262 140 260 142 143 257 256 146 147 253 252 150 151 249 248 154 155 245 244 158 159 241 240 162 163 237 236 166 167 233 232 170 171 229 228 174 175 225 224 178 179 221 181 219 218 184 185 215 214 188 189 211 210 192 193 207 206 196 197 203 202 200 201 199 198 204 205 195 194 208 209 191 190 212 213 187 186 216 217 183 182 220 180 222 223 177 176 226 227 173 172 230 231 169 168 234 235 165 164 238 239 161 160 242 243 157 156 246 247 153 152 250 251 149 148 254 255 145 144 258 259 141 261 139 138 264 265 135 134 268 269 131 130 272 273 127 126 276 277 123 122 280 281 119 118 284 285 115 114 288 289 111 110 292 293 107 106 296 297 103 102 300 100 302 303 97 96 306 307 93 92 310 311 89 88 314 315 85 84 318 319 81 80 322 323 77 76 326 327 73 72 330 331 69 68 334 335 65 64 338 339 61 341 59 58 344 345 55 54 348 349 51 50 352 353 47 46 356 357 43 42 360 361 39 38 364 365 35 34 368 369 31 30 372 373 27 26 376 377 23 22 380 20 382 383 17 16 386 387 13 12 390 391 9 8 394 395 5 4 398 399 1 u = 83 o = 1 o = 2 o = 3 o = 4 o = 5 o = 6 o = 7 o = 8 o = 9 o = 10 o = 11 o = 12 o = 13 o = 14 o = 15 o = 16 o = 17 o = 18 o = 19 o = 21 o = 22 o = 23 o = 24 o = 25 o = 26 o = 27 o = 28 o = 29 o = 30 o = 31 o = 32 o = 33 o = 34 o = 35 o = 36 o = 37 o = 38 o = 41 o = 42 o = 43 o = 44 o = 45 o = 46 o = 47 o = 48 o = 49 o = 50 o = 51 o = 52 o = 53 o = 54 o = 55 o = 56 o = 57 o = 61 o = 62 o = 63 o = 64 o = 65 o = 66 o = 67 o = 68 o = 69 o = 70 o = 71 o = 72 o = 73 o = 74 o = 75 o = 76 o = 81 o = 82 o = 83 o = 84 o = 85 o = 86 o = 87 o = 88 o = 89 o = 90 o = 91 o = 92 o = 93 l = 83

7   Pass
n = 21; m = 1; a = twist_n_match(n,m); [r,c] = size(a); assert(r==n && c==n); assert(isequal(nnz(a==rot90(a)),m));

a = 233 256 279 302 325 348 371 394 417 440 1 24 47 70 93 116 139 162 185 208 231 255 278 301 324 347 370 393 416 439 21 23 46 69 92 115 138 161 184 207 230 232 277 300 323 346 369 392 415 438 20 22 45 68 91 114 137 160 183 206 229 252 254 299 322 345 368 391 414 437 19 42 44 67 90 113 136 159 182 205 228 251 253 276 321 344 367 390 413 436 18 41 43 66 89 112 135 158 181 204 227 250 273 275 298 343 366 389 412 435 17 40 63 65 88 111 134 157 180 203 226 249 272 274 297 320 365 388 411 434 16 39 62 64 87 110 133 156 179 202 225 248 271 294 296 319 342 387 410 433 15 38 61 84 86 109 132 155 178 201 224 247 270 293 295 318 341 364 409 432 14 37 60 83 85 108 131 154 177 200 223 246 269 292 315 317 340 363 386 431 13 36 59 82 105 107 130 153 176 199 222 245 268 291 314 316 339 362 385 408 12 35 58 81 104 106 129 152 175 198 221 244 267 290 313 336 338 361 384 407 430 34 57 80 103 126 128 151 174 197 220 243 266 289 312 335 337 360 383 406 429 11 56 79 102 125 127 150 173 196 219 242 265 288 311 334 357 359 382 405 428 10 33 78 101 124 147 149 172 195 218 241 264 287 310 333 356 358 381 404 427 9 32 55 100 123 146 148 171 194 217 240 263 286 309 332 355 378 380 403 426 8 31 54 77 122 145 168 170 193 216 239 262 285 308 331 354 377 379 402 425 7 30 53 76 99 144 167 169 192 215 238 261 284 307 330 353 376 399 401 424 6 29 52 75 98 121 166 189 191 214 237 260 283 306 329 352 375 398 400 423 5 28 51 74 97 120 143 188 190 213 236 259 282 305 328 351 374 397 420 422 4 27 50 73 96 119 142 165 210 212 235 258 281 304 327 350 373 396 419 421 3 26 49 72 95 118 141 164 187 211 234 257 280 303 326 349 372 395 418 441 2 25 48 71 94 117 140 163 186 209 u = 0 l = 1