MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply Today**New to MATLAB?**

Incorrect

38Size

Leading solution size is 24.
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test

Code Input and Output

1

Pass

!cp diff_digits.m safe !rm *.* !mv safe diff_digits.m % Clean user's function from some known jailbreaking mechanisms fid = fopen('diff_digits.m'); st = regexprep(char(fread(fid)'), '!', 'error(''No shell commands!''); %'); st = regexprep(st, 'feval', 'error(''No fancy functions!''); %'); st = regexprep(st, 'str2func', 'error(''No fancy functions!''); %'); st = regexprep(st, 'regex', 'error(''No fancy functions!''); %'); st = regexprep(st, 'system', 'error(''No shell commands!''); %'); st = regexprep(st, 'dos', 'error(''No shell commands!''); %'); st = regexprep(st, 'unix', 'error(''No shell commands!''); %'); st = regexprep(st, 'perl', 'error(''No external languages commands!''); %'); st = regexprep(st, 'java', 'error(''No external languages commands!''); %'); st = regexprep(st, 'assert', 'error(''No overwriting!''); %'); fclose(fid) fid = fopen('diff_digits.m' , 'w'); fwrite(fid,st); fclose(fid)

ans = 0 ans = 0

2

Pass

%% start=1000; finish=1023; y_correct = 1; assert(isequal(diff_digits(start,finish),y_correct))

counter = 0 counter = 1

3

Pass

%% start=1000; finish=9999; y_correct = 4536; assert(isequal(diff_digits(start,finish),y_correct))

counter = 0 counter = 1 counter = 2 counter = 3 counter = 4 counter = 5 counter = 6 counter = 7 counter = 8 counter = 9 counter = 10 counter = 11 counter = 12 counter = 13 counter = 14 counter = 15 counter = 16 counter = 17 counter = 18 counter = 19 counter = 20 counter = 21 counter = 22 counter = 23 counter = 24 counter = 25 counter = 26 counter = 27 counter = 28 counter = 29 counter = 30 counter = 31 counter = 32 counter = 33 counter = 34 counter = 35 counter = 36 counter = 37 counter = 38 counter = 39 counter = 40 counter = 41 counter = 42 counter = 43 counter = 44 counter = 45 counter = 46 counter = 47 counter = 48 counter = 49 counter = 50 counter = 51 counter = 52 counter = 53 counter = 54 counter = 55 counter = 56 counter = 57 counter = 58 counter = 59 counter = 60 counter = 61 counter = 62 counter = 63 counter = 64 counter = 65 counter = 66 counter = 67 counter = 68 counter = 69 counter = 70 counter = 71 counter = 72 counter = 73 counter = 74 counter = 75 counter = 76 counter = 77 counter = 78 counter = 79 counter = 80 counter = 81 counter = 82 counter = 83 counter = 84 counter = 85 counter = 86 counter = 87 counter = 88 counter = 89 counter = 90 counter = 91 counter = 92 counter = 93 counter = 94 counter = 95 counter = 96 counter = 97 counter = 98 counter = 99 counter = 100 counter = 101 counter = 102 counter = 103 counter = 104 counter = 105 counter = 106 counter = 107 counter = 108 counter = 109 counter = 110 counter = 111 counter = 112 counter = 113 counter = 114 counter = 115 counter = 116 counter = 117 counter = 118 counter = 119 counter = 120 counter = 121 counter = 122 counter = 123 counter = 124 counter = 125 counter = 126 counter = 127 counter = 128 counter = 129 counter = 130 counter = 131 counter = 132 counter = 133 counter = 134 counter = 135 counter = 136 counter = 137 counter = 138 counter = 139 counter = 140 counter = 141 counter = 142 counter = 143 counter = 144 counter = 145 counter = 146 counter = 147 counter = 148 counter = 149 counter = 150 counter = 151 counter = 152 counter = 153 counter = 154 counter = 155 counter = 156 counter = 157 counter = 158 counter = 159 counter = 160 counter = 161 counter = 162 counter = 163 counter = 164 counter = 165 counter = 166 counter = 167 counter = 168 counter = 169 counter = 170 counter = 171 counter = 172 counter = 173 counter = 174 counter = 175 counter = 176 counter = 177 counter = 178 counter = 179 counter = 180 counter = 181 counter = 182 counter = 183 counter = 184 counter = 185 counter = 186 counter = 187 counter = 188 counter = 189 counter = 190 counter = 191 counter = 192 counter = 193 counter = 194 counter = 195 counter = 196 counter = 197 counter = 198 counter = 199 counter = 200 counter = 201 counter = 202 counter = 203 counter = 204 counter = 205 counter = 206 counter = 207 counter = 208 counter = 209 counter = 210 counter = 211 counter = 212 counter = 213 counter = 214 counter = 215 counter = 216 counter = 217 counter = 218 counter = 219 counter = 220 counter = 221 counter = 222 counter = 223 counter = 224 counter = 225 counter = 226 counter = 227 counter = 228 counter = 229 counter = 230 counter = 231 counter = 232 counter = 233 counter = 234 counter = 235 counter = 236 counter = 237 counter = 238 counter = 239 counter = 240 counter = 241 counter = 242 counter = 243 counter = 244 counter = 245 counter = 246 counter = 247 counter = 248 counter = 249 counter = 250 counter = 251 counter = 252 counter = 253 counter = 254 counter = 255 counter = 256 counter = 257 counter = 258 counter = 259 counter = 260 counter = 261 counter = 262 counter = 263 counter = 264 counter = 265 counter = 266 counter = 267 counter = 268 counter = 269 counter = 270 counter = 271 counter = 272 counter = 273 counter = 274 counter = 275 counter = 276 counter = 277 counter = 278 counter = 279 counter = 280 counter = 281 counter = 282 counter = 283 counter = 284 counter = 285 counter = 286 counter = 287 counter = 288 counter = 289 counter = 290 counter = 291 counter = 292 counter = 293 counter = 294 counter = 295 counter = 296 counter = 297 counter = 298 counter = 299 counter = 300 counter = 301 counter = 302 counter = 303 counter = 304 counter = 305 counter = 306 counter = 307 counter = 308 counter = 309 counter = 310 counter = 311 counter = 312 counter = 313 counter = 314 counter = 315 counter = 316 counter = 317 counter = 318 counter = 319 counter = 320 counter = 321 counter = 322 counter = 323 counter = 324 counter = 325 counter = 326 counter = 327 counter = 328 counter = 329 counter = 330 counter = 331 counter = 332 counter = 333 counter = 334 counter = 335 counter = 336 counter = 337 counter = 338 counter = 339 counter = 340 counter = 341 counter = 342 counter = 343 counter = 344 counter = 345 counter = 346 counter = 347 counter = 348 counter = 349 counter = 350 counter = 351 counter = 352 counter = 353 counter = 354 counter = 355 counter = 356 counter = 357 counter = 358 counter = 359 counter = 360 counter = 361 counter = 362 counter = 363 counter = 364 counter = 365 counter = 366 counter = 367 counter = 368 counter = 369 counter = 370 counter = 371 counter = 372 counter = 373 counter = 374 counter = 375 counter = 376 counter = 377 counter = 378 counter = 379 counter = 380 counter = 381 counter = 382 counter = 383 counter = 384 counter = 385 counter = 386 counter = 387 counter = 388 counter = 389 counter = 390 counter = 391 counter = 392 counter = 393 counter = 394 counter = 395 counter = 396 counter = 397 counter = 398 counter = 399 counter = 400 counter = 401 counter = 402 counter = 403 counter = 404 counter = 405 counter = 406 counter = 407 counter = 408 counter = 409 counter = 410 counter = 411 counter = 412 counter = 413 counter = 414 counter = 415 counter = 416 counter = 417 counter = 418 counter = 419 counter = 420 counter = 421 counter = 422 counter = 423 counter = 424 counter = 425 counter = 426 counter = 427 counter = 428 counter = 429 counter = 430 counter = 431 counter = 432 counter = 433 counter = 434 counter = 435 counter = 436 counter = 437 counter = 438 counter = 439 counter = 440 counter = 441 counter = 442 counter = 443 counter = 444 counter = 445 counter = 446 counter = 447 counter = 448 counter = 449 counter = 450 counter = 451 counter = 452 counter = 453 counter = 454 counter = 455 counter = 456 counter = 457 counter = 458 counter = 459 counter = 460 counter = 461 counter = 462 counter = 463 counter = 464 counter = 465 counter = 466 counter = 467 counter = 468 counter = 469 counter = 470 counter = 471 counter = 472 counter = 473 counter = 474 counter = 475 counter = 476 counter = 477 counter = 478 counter = 479 counter = 480 counter = 481 counter = 482 counter = 483 counter = 484 counter = 485 counter = 486 counter = 487 counter = 488 counter = 489 counter = 490 counter = 491 counter = 492 counter = 493 counter = 494 counter = 495 counter = 496 counter = 497 counter = 498 counter = 499 counter = 500 counter = 501 counter = 502 counter = 503 counter = 504 counter = 505 counter = 506 counter = 507 counter = 508 counter = 509 counter = 510 counter = 511 counter = 512 counter = 513 counter = 514 counter = 515 counter = 516 counter = 517 counter = 518 counter = 519 counter = 520 counter = 521 counter = 522 counter = 523 counter = 524 counter = 525 counter = 526 counter = 527 counter = 528 counter = 529 counter = 530 counter = 531 counter = 532 counter = 533 counter = 534 counter = 535 counter = 536 counter = 537 counter = 538 counter = 539 counter = 540 counter = 541 counter = 542 counter = 543 counter = 544 counter = 545 counter = 546 counter = 547 counter = 548 counter = 549 counter = 550 counter = 551 counter = 552 counter = 553 counter = 554 counter = 555 counter = 556 counter = 557 counter = 558 counter = 559 counter = 560 counter = 561 counter = 562 counter = 563 counter = 564 counter = 565 counter = 566 counter = 567 counter = 568 counter = 569 counter = 570 counter = 571 counter = 572 counter = 573 counter = 574 counter = 575 counter = 576 counter = 577 counter = 578 counter = 579 counter = 580 counter = 581 counter = 582 counter = 583 counter = 584 counter = 585 counter = 586 counter = 587 cou...

4

Fail

%% start=1234; finish=5678; y_correct = 2273; assert(isequal(diff_digits(start,finish),y_correct))

Error: Assertion failed.

5

Fail

%% assert(isequal(diff_digits(4321,6789),1210))

Error: Assertion failed.

6

Pass

%% assert(isequal(diff_digits(1988,2012),0))

counter = 0