Cody

# Problem 45509. List the households affected by leaks in water distribution

Solution 2863037

Submitted on 21 Aug 2020 by Alfonso Nieto-Castanon
• Size: 23
• This is the leading solution.
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
filetext = fileread('water_loss.m') assert(isempty(strfind(filetext, 'rand'))) assert(isempty(strfind(filetext, 'fileread'))) assert(isempty(strfind(filetext, 'assert'))) assert(isempty(strfind(filetext, 'echo')))

filetext = 'function ans = water_loss(X,P) setdiff(bfsearch(digraph(nonzeros(X),find(X)),P),X)'; end %This code written by profile_id 1379371 '

2   Pass
X = [0 1 1 2 4 2 4]; P = 2; y = [5 6 7 ]; assert(isequal(water_loss(X,P),y))

3   Pass
X = [0 1 2 3 4 5 4 1]; P = 2; y = [6 7 ]; assert(isequal(water_loss(X,P),y))

4   Pass
X = [0 1 1 3 3 4 2 2 2 4 4 11 12 12 10 15 15 17 17 19 19 19 12 23 24]; assert(isequal(water_loss(X,23),25)) assert(isequal(water_loss(X,13),13)) assert(isequal(water_loss(X,2),[7 8 9])) assert(isequal(water_loss(X,10),[16 18 20 21 22]))

5   Pass
X = [0 1 2 1 2 4 5 1 8 7 5 5 6 4 8 ... 8 14 14 12 8 17 12 8 22 22 14 17 16 6 9 ... 15 8 28 7 8 6 9 17]; assert(isequal(water_loss(X,36),36)) P = 17; y = [21 27 38]; assert(isequal(water_loss(X,P),y))

6   Pass
X = [0 1 1 2 2 1 4 2 4 6 3 4 8 4 12 ... 15 12 6 11 3 19 19 18 6 15 1 12 9 5 6 ... 13 3 20 16 24 25 23 2 3 13 22 27 18 36 32 ... 44 25 16 6 30 39 22 5 15 9 16 25 31 27 52 ... 32 58 40 61 16]; P = 19; y = [21 41 60 ]; assert(isequal(water_loss(X,P),y)) P = 15; y = [34 46 47 48 54 56 57 65 ]; assert(isequal(water_loss(X,P),y))

7   Pass
X = [0 1 1 2 1 3 3 2 2 9 7 6 11 2 11 ... 12 9 4 11 6 3 5 20 2 6 2 12 1 26 6 ... 3 10 15 4 34 12 11 3 12 2 21 32 27 4 4 ... 35 42 26 6 41 17 15 39 1 3 37 34 30 43 42 ... 47 18 43 36 26 5 52 23 42 52 8 10 40 36 66 ... 60 56 4 6 7 64 77 57 11 61 10 11 56 29 59 ... 68 54 69 22 70 93 84 9 36 37 69 61 81 38 22 ... 10 82 23 42 61 26 72 55 18 90 12 35 28 63 11 ... 49 13 14 97 37 76 122 55 89 98 57 86 15 125 26 ... 36 109 67 107 56 39 6 96 62 66 89 9 47 115 104 ... 19 20 15 2 66 102 113 84 18 101 21 22 16 24]; y = [95 138 ]; assert(isequal(water_loss(X,52),y)) y = [74 99 103 136 ]; assert(isequal(water_loss(X,36),y)) y = [85 110 126 137 143 148 156 160 ]; assert(isequal(water_loss(X,42),y))

8   Pass
X = [0 1 1 3 2 3 5 7 3 8 8 11 1 5 10 5 4 13 12 12 14 1 8 11 6 ... 18 23 8 21 4 26 5 19 13 28 18 18 33 14 18 39 2 41 9 30 27 32 17 30 40 ... 1 5 51 35 13 23 7 16 15 20 10 22 8 56 7 61 27 4 24 51 56 39 50 66 5 ... 23 4 16 57 58 71 48 6 77 68 25 47 86 63 75 39 43 52 26 71 48 63 30 14 48 ... 37 80 80 69 14 3 60 33 102 107 32 89 101 68 101 109 64 86 69 4 54 79 64 46 117 ... 104 107 48 76 113 122 88 28]; y = [115 130 ]; assert(isequal(water_loss(X,101),y)) y = [81 95 123 125 ]; assert(isequal(water_loss(X,56),y))

9   Pass
X = [0 1 2 2 2 2 5 7 8 6 6 2 11 6 3 14 13 16 6 13 14 3 9 7 18 ... 8 24 23 11 15 21 26 20 19 12 16 26 33 28 1 27 18 19 6 36 15 12 17 19 27 ... 29 21 21 28 36 53 41 23 49 8 4 6 11 21 20 1 36 7 10 44 61 70 42 73 41 ... 39 26 34 39 6 72 6 36 69 34 53 71 78 82 17 24 82 55 47 58 78 52 20 45 43 ... 97 63 71 75 37 55 60 17 61 76 47 93 82 41 52 45 90 86 51 83 114 95 87 14 49 ... 74 58 7 30 108 3 114 11 89 68 30 78 17 93 84 8 8 22 3 63 121 91 77 128 15 ... 137 17 79 22 87 1 120 134 145 157 81 44 17 83 97 126 14 111 87 29 160 101 76 163 115 ... 80 148 95 99 122 67 44 106 159 75 21 83 57 76 158 77 75 70 28 51 17 85 51 59 85 ... 24 100 143 50 161 16 82 1 46 1 40 31 57 38 30 129 195 204 49 106 83 116 59 16 98 ... 40 6 217 99 221 176 2 158 165 151 130 52 184 55 89 214 207 98 78 149 223 224 147 83 213 ... 111 227 9 135 182 46 87 49 84 105 143 13 145 73 64 65 42 256 251 221 197 48 99 52 1 ... 88 194 174 151 123 81 141 215 216 164 214 185 36 146 101 27 44 58 197 127 205 77 3 159 84 ... 284 273 119 8 205 256 298 18 139 180 213 224 203 228 118 184 37 19 312 91 191 309 60 63 111 ... 304 128 90 50 131 124 44 145 31 206 4 193 267 80 152 194 21 170 221 77 289 336 294 177 98 ... 262 84 337 219 213 62 33 92 308 328 252 262 84 210 296 148 362 34 119 189 23 270 208 198 311 ... 323 297 120 171 286 42 42 104 201 374 274 121 113 330 355 250 100 35 330 231 375 25 233 114 331]; y = [321 345 349 366 377 ]; assert(isequal(water_loss(X,77),y)) y = [140 259 300 352 363 ]; assert(isequal(water_loss(X,84),y)) y = [32 54 107 110 132 142 153 173 178 188 192 218 245 248 253 254 260 277 282 ... 287 291 293 295 310 317 320 321 326 327 329 341 345 346 349 366 370 371 376 ... 377 383 384 387 390 391 396 399]; assert(isequal(water_loss(X,5),y))

10   Pass
X = [0 1 1 2 4 3 1 1 7 5 4 9 5 7 10 14 6 12 18 2 12 9 7 7 19 ... 25 5 22 6 29 25 14 24 17 28 13 3 22 35 8 18 31 2 41 34 26 9 24 25 49 ... 43 50 36 22 51 27 13 23 41 33 46 61 60 34 62 8 4 21 40 37 64 39 32 40 53 ... 2 61 11 38 21 30 54 14 24 17 17 29 77 42 36 17 89 38 79 58 36 85 77 46 81 ... 90 44 35 62 94 74 41 79 104 60 60 35 8 21 11 54 2 108 76 1 4 26 56 16 2 ... 91 45 100 56 57 7 7 13 80 33 114 117 133 68 31 32 76 109 50 67 93 134 24 106 87 ... 65 134 60 28 98 97 52 127 158 156 21 38 4 100 19 68 147 92 62 36 75 164 22 82 150 ... 8 122 174 51 24 124 165 112 165 36 140 65 79 30 155 119 142 155 13 185 98 149 147 165 32 ... 92 125 189 170 183 120 121 177 8 186 86 8 159 33 31 131 55 71 88 89 85 135 38 42 22 ... 73 174 54 169 159 190 192 69 73 123 77 197 193 133 63 164 57 111 94 132 243 186 243 59 132 ... 13 190 152 217 252 238 105 1 140 54 58 86 26 197 198 144 90 223 149 258 242 97 149 95 171 ... 220 206 35 229 8 117 206 221 104 212 255 70 38 65 102 84 270 15 174 48 248 50 150 298 107 ... 15 65 121 102 70 286 210 296 135 291 2 190 250 73 293 241 262 182 253 105 72 101 189 269 95 ... 131 282 202 326 68 273 224 83 159 134 201 269 36 278 286 121 147 196 241 256 262 135 149 333 200 ... 298 97 220 208 342 31 179 187 33 325 319 159 283 54 226 96 164 310 73 113 179 126 298 369 60 ... 89 265 142 369 369 245 328 154 243 379 216 361 279 188 249 347 78 155 390 159 261 357 396 260 44]; y = [115 129 130 138 145 163 194 195 204 207 235 239 251 267 271 275 301 303 315 322 338 341 366 392 ]; assert(isequal(water_loss(X,4),y)) y = [143 151 284 289 302 358 388 ]; assert(isequal(water_loss(X,62),y)) y = [130 271 ]; assert(isequal(water_loss(X,57),y)) y = [160 272 352 ]; assert(isequal(water_loss(X,97),y)) y = [275 ]; assert(isequal(water_loss(X,75),y)) y = [145 ]; assert(isequal(water_loss(X,67),y)) y = [275 ]; assert(isequal(water_loss(X,53),y)) y = [99 143 151 219 231 236 263 284 289 302 306 312 340 343 345 354 358 388 393 ]; assert(isequal(water_loss(X,26),y)) y = [160 272 352 ]; assert(isequal(water_loss(X,97),y)) y = [254 ]; assert(isequal(water_loss(X,55),y))

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!