Cody

# Problem 1699. Find last zero for each column

Solution 275795

Submitted on 8 Jul 2013 by Evan
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
%% a = 0; z_correct = 1; assert(isequal(lastzerorow(a),z_correct))

ans = [1] ans = 1

2   Pass
%% a = 1; z_correct = 0; assert(isequal(lastzerorow(a),z_correct))

ans = {[]} ans = [0] ans = 0

3   Pass
%% a = randi(1000,1000,1); z_correct = 0; assert(isequal(lastzerorow(a),z_correct))

ans = [0x1 double] ans = [0] ans = 0

4   Pass
%% a = [0;1;0;2;0;3;0;4;0;5;0;6;0;7;0;8;0;9;0;10]; z_correct = 19; assert(isequal(lastzerorow(a),z_correct))

ans = [19] ans = 19

5   Pass
%% n = randi(1000); a = tril(ones(n)); z_correct = 0:n-1; assert(isequal(lastzerorow(a),z_correct))

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

6   Pass
%% n = randi(1000); a = tril(ones(n),-1); z_correct = 1:n; assert(isequal(lastzerorow(a),z_correct))

ans = Columns 1 through 13 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] Columns 14 through 25 [14] [15] [16] [17] [18] [19] [20] [21] [22] [23] [24] [25] Columns 26 through 37 [26] [27] [28] [29] [30] [31] [32] [33] [34] [35] [36] [37] Columns 38 through 49 [38] [39] [40] [41] [42] [43] [44] [45] [46] [47] [48] [49] Columns 50 through 61 [50] [51] [52] [53] [54] [55] [56] [57] [58] [59] [60] [61] Columns 62 through 73 [62] [63] [64] [65] [66] [67] [68] [69] [70] [71] [72] [73] Columns 74 through 85 [74] [75] [76] [77] [78] [79] [80] [81] [82] [83] [84] [85] Columns 86 through 97 [86] [87] [88] [89] [90] [91] [92] [93] [94] [95] [96] [97] Columns 98 through 108 [98] [99] [100] [101] [102] [103] [104] [105] [106] [107] [108] Columns 109 through 119 [109] [110] [111] [112] [113] [114] [115] [116] [117] [118] [119] Columns 120 through 130 [120] [121] [122] [123] [124] [125] [126] [127] [128] [129] [130] Columns 131 through 141 [131] [132] [133] [134] [135] [136] [137] [138] [139] [140] [141] Columns 142 through 152 [142] [143] [144] [145] [146] [147] [148] [149] [150] [151] [152] Columns 153 through 163 [153] [154] [155] [156] [157] [158] [159] [160] [161] [162] [163] Columns 164 through 174 [164] [165] [166] [167] [168] [169] [170] [171] [172] [173] [174] Columns 175 through 185 [175] [176] [177] [178] [179] [180] [181] [182] [183] [184] [185] Columns 186 through 196 [186] [187] [188] [189] [190] [191] [192] [193] [194] [195] [196] Columns 197 through 207 [197] [198] [199] [200] [201] [202] [203] [204] [205] [206] [207] Columns 208 through 218 [208] [209] [210] [211] [212] [213] [214] [215] [216] [217] [218] Columns 219 through 229 [219] [220] [221] [222] [223] [224] [225] [226] [227] [228] [229] Columns 230 through 240 [230] [231] [232] [233] [234] [235] [236] [237] [238] [239] [240] Columns 241 through 251 [241] [242] [243] [244] [245] [246] [247] [248] [249] [250] [251] Columns 252 through 262 [252] [253] [254] [255] [256] [257] [258] [259] [260] [261] [262] Columns 263 through 273 [263] [264] [265] [266] [267] [268] [269] [270] [271] [272] [273] Columns 274 through 284 [274] [275] [276] [277] [278] [279] [280] [281] [282] [283] [284] Columns 285 through 287 [285] [286] [287] ans = Columns 1 through 16 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Columns 17 through 32 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 Columns 33 through 48 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 Columns 49 through 64 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 Columns 65 through 80 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 Columns 81 through 96 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 Columns 97 through 112 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 Columns 113 through 128 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 Columns 129 through 144 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 Columns 145 through 160 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 Columns 161 through 176 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 Columns 177 through 192 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 Columns 193 through 208 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 Columns 209 through 224 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 Columns 225 through 240 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 Columns 241 through 256 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 Columns 257 through 272 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 Columns 273 through 287 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287

7   Pass
%% n = randi(1000); d = randi(n-1); a = tril(ones(n),-d); z_correct = min((0:n-1)+d,n); assert(isequal(lastzerorow(a),z_correct))

ans = Columns 1 through 11 [190] [191] [192] [193] [194] [195] [196] [197] [198] [199] [200] Columns 12 through 22 [201] [202] [203] [204] [205] [206] [207] [208] [209] [210] [211] Columns 23 through 33 [212] [213] [214] [215] [216] [217] [218] [219] [220] [221] [222] Columns 34 through 44 [223] [224] [225] [226] [227] [228] [229] [230] [231] [232] [233] Columns 45 through 55 [234] [235] [236] [237] [238] [239] [240] [241] [242] [243] [244] Columns 56 through 66 [245] [246] [247] [248] [249] [250] [251] [252] [253] [254] [255] Columns 67 through 77 [256] [257] [258] [259] [260] [261] [262] [263] [264] [265] [266] Columns 78 through 88 [267] [268] [269] [270] [271] [272] [273] [274] [275] [276] [277] Columns 89 through 99 [278] [279] [280] [281] [282] [283] [284] [285] [286] [287] [288] Columns 100 through 110 [289] [290] [291] [292] [293] [294] [295] [296] [297] [298] [299] Columns 111 through 121 [300] [301] [302] [303] [304] [305] [306] [307] [308] [309] [310] Columns 122 through 132 [311] [312] [313] [314] [315] [316] [317] [318] [319] [320] [321] Columns 133 through 143 [322] [323] [324] [325] [326] [327] [328] [329] [330] [331] [332] Columns 144 through 154 [333] [334] [335] [336] [337] [338] [339] [340] [341] [342] [343] Columns 155 through 165 [344] [345] [346] [347] [348] [349] [350] [351] [352] [353] [354] Columns 166 through 176 [355] [355] [355] [355] [355] [355] [355] [355] [355] [355] [355] Columns 177 through 187 [355] [355] [355] [355] [355] [355] [355] [355] [355] [355] [355] Columns 188 through 198 [355] [355] [355] [355] [355] [355] [355] [355] [355] [355] [355] Columns 199 through 209 [355] [355] [355] [355] [355] [355] [355] [355] [355] [355] [355] Columns 210 through 220 [355] [355] [355] [355] [355] [355] [355] [355] [355] [355] [355] Columns 221 through 231 [355] [355] [355] [355] [355] [355] [355] [355] [355] [355] [355] Columns 232 through 242 [355] [355] [355] [355] [355] [355] [355] [355] [355] [355] [355] Columns 243 through 253 [355] [355] [355] [355] [355] [355] [355] [355] [355] [355] [355] Columns 254 through 264 [355] [355] [355] [355] [355] [355] [355] [355] [355] [355] [355] Columns 265 through 275 [355] [355] [355] [355] [355] [355] [355] [355] [355] [355] [355] Columns 276 through 286 [355] [355] [355] [355] [355] [355] [355] [355] [355] [355] [355] Columns 287 through 297 [355] [355] [355] [355] [355] [355] [355] [355] [355] [355] [355] Columns 298 through 308 [355] [355] [355] [355] [355] [355] [355] [355] [355] [355] [355] Columns 309 through 319 [355] [355] [355] [355] [355] [355] [355] [355] [355] [355] [355] Columns 320 through 330 [355] [355] [355] [355] [355] [355] [355] [355] [355] [355] [355] Columns 331 through 341 [355] [355] [355] [355] [355] [355] [355] [355] [355] [355] [355] Columns 342 through 352 [355] [355] [355] [355] [355] [355] [355] [355] [355] [355] [355] Columns 353 through 355 [355] [355] [355] ans = Columns 1 through 16 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 Columns 17 through 32 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 Columns 33 through 48 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 Columns 49 through 64 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 Columns 65 through 80 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 Columns 81 through 96 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 Columns 97 through 112 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 Columns 113 through 128 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 Columns 129 through 144 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 Columns 145 through 160 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 Columns 161 through 176 350 351 352 353 354 355 355 355 355 355 355 355 355 355 355 355 Columns 177 through 192 355 355 355 355 355 355 355 355 355 355 355 355 355 355 355 355 Columns 193 through 208 355 355 355 355 355 355 355 355 355 355 355 355 355 355 355 355 Columns 209 through 224 355 355 355 355 355 355 355 355 355 355 355 355 355 355 355 355 Columns 225 through 240 355 355 355 355 355 355 355 355 355 355 355 355 355 355 355 355 Columns 241 through 256 355 355 355 355 355 355 355 355 355 355 355 355 355 355 355 355 Columns 257 through 272 355 355 355 355 355 355 355 355 355 355 355 355 355 355 355 355 Columns 273 through 288 355 355 355 355 355 355 355 355 355 355 355 355 355 355 355 355 Columns 289 through 304 355 355 355 355 355 355 355 355 355 355 355 355 355 355 355 355 Columns 305 through 320 355 355 355 355 355 355 355 355 355 355 355 355 355 355 355 355 Columns 321 through 336 355 355 355 355 355 355 355 355 355 355 355 355 355 355 355 355 Columns 337 through 352 355 355 355 355 355 355 355 355 355 355 355 355 355 355 355 355 Columns 353 through 355 355 355 355

8   Pass
%% a = magic(10)-1; z_correct = [0 0 1 0 0 0 0 0 0 0]; assert(isequal(lastzerorow(a),z_correct))

ans = Columns 1 through 6 [0x1 double] [0x1 double] [1] [0x1 double] [0x1 double] [0x1 double] Columns 7 through 10 [0x1 double] [0x1 double] [0x1 double] [0x1 double] ans = [0] [0] [1] [0] [0] [0] [0] [0] [0] [0] ans = 0 0 1 0 0 0 0 0 0 0

9   Pass
%% a = [0 0 9 0; 0 0 1 8; 0 0 4 0; 0 0 2 3; 0 6 7 5]; z_correct = [5 4 0 3]; assert(isequal(lastzerorow(a),z_correct))

ans = [5] [4] [0x1 double] [3] ans = [5] [4] [0] [3] ans = 5 4 0 3

10   Pass
%% a = [0 0 0 0 -4 0 0 0 0; 0 0 0 -3 -3 -3 0 0 0; 0 0 -2 3 -2 2 2 0 0; 0 -1 2 -1 1 -1 -1 1 0]; z_correct = [4 3 2 1 0 1 2 3 4]; assert(isequal(lastzerorow(a),z_correct))

ans = [4] [3] [2] [1] [0x1 double] [1] [2] [3] [4] ans = [4] [3] [2] [1] [0] [1] [2] [3] [4] ans = 4 3 2 1 0 1 2 3 4