Cody

Problem 1940. Decimation - Optimized for speed

Solution 3795608

Submitted on 23 Nov 2020
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   Fail
assert(isequal(speed_decimation(10,3),4))

y = 1 2 4 5 7 8 10

Assertion failed.

2   Fail
assert(isequal(speed_decimation(1024,3),676))

y = Columns 1 through 14 1 2 4 5 7 8 10 11 13 14 16 17 19 20 Columns 15 through 28 22 23 25 26 28 29 31 32 34 35 37 38 40 41 Columns 29 through 42 43 44 46 47 49 50 52 53 55 56 58 59 61 62 Columns 43 through 56 64 65 67 68 70 71 73 74 76 77 79 80 82 83 Columns 57 through 70 85 86 88 89 91 92 94 95 97 98 100 101 103 104 Columns 71 through 84 106 107 109 110 112 113 115 116 118 119 121 122 124 125 Columns 85 through 98 127 128 130 131 133 134 136 137 139 140 142 143 145 146 Columns 99 through 112 148 149 151 152 154 155 157 158 160 161 163 164 166 167 Columns 113 through 126 169 170 172 173 175 176 178 179 181 182 184 185 187 188 Columns 127 through 140 190 191 193 194 196 197 199 200 202 203 205 206 208 209 Columns 141 through 154 211 212 214 215 217 218 220 221 223 224 226 227 229 230 Columns 155 through 168 232 233 235 236 238 239 241 242 244 245 247 248 250 251 Columns 169 through 182 253 254 256 257 259 260 262 263 265 266 268 269 271 272 Columns 183 through 196 274 275 277 278 280 281 283 284 286 287 289 290 292 293 Columns 197 through 210 295 296 298 299 301 302 304 305 307 308 310 311 313 314 Columns 211 through 224 316 317 319 320 322 323 325 326 328 329 331 332 334 335 Columns 225 through 238 337 338 340 341 343 344 346 347 349 350 352 353 355 356 Columns 239 through 252 358 359 361 362 364 365 367 368 370 371 373 374 376 377 Columns 253 through 266 379 380 382 383 385 386 388 389 391 392 394 395 397 398 Columns 267 through 280 400 401 403 404 406 407 409 410 412 413 415 416 418 419 Columns 281 through 294 421 422 424 425 427 428 430 431 433 434 436 437 439 440 Columns 295 through 308 442 443 445 446 448 449 451 452 454 455 457 458 460 461 Columns 309 through 322 463 464 466 467 469 470 472 473 475 476 478 479 481 482 Columns 323 through 336 484 485 487 488 490 491 493 494 496 497 499 500 502 503 Columns 337 through 350 505 506 508 509 511 512 514 515 517 518 520 521 523 524 Columns 351 through 364 526 527 529 530 532 533 535 536 538 539 541 542 544 545 Columns 365 through 378 547 548 550 551 553 554 556 557 559 560 562 563 565 566 Columns 379 through 392 568 569 571 572 574 575 577 578 580 581 583 584 586 587 Columns 393 through 406 589 590 592 593 595 596 598 599 601 602 604 605 607 608 Columns 407 through 420 610 611 613 614 616 617 619 620 622 623 625 626 628 629 Columns 421 through 434 631 632 634 635 637 638 640 641 643 644 646 647 649 650 Columns 435 through 448 652 653 655 656 658 659 661 662 664 665 667 668 670 671 Columns 449 through 462 673 674 676 677 679 680 682 683 685 686 688 689 691 692 Columns 463 through 476 694 695 697 698 700 701 703 704 706 707 709 710 712 713 Columns 477 through 490 715 716 718 719 721 722 724 725 727 728 730 731 733 734 Columns 491 through 504 736 737 739 740 742 743 745 746 748 749 751 752 754 755 Columns 505 through 518 757 758 760 761 763 764 766 767 769 770 772 773 775 776 Columns 519 through 532 778 779 781 782 784 785 787 788 790 791 793 794 796 797 Columns 533 through 546 799 800 802 803 805 806 808 809 811 812 814 815 817 818 Columns 547 through 560 820 821 823 824 826 827 829 830 832 833 835 836 838 839 Columns 561 through 574 841 842 844 845 847 848 850 851 853 854 856 857 859 860 Columns 575 through 588 862 863 865 866 868 869 871 872 874 875 877 878 880 881 Columns 589 through 602 883 884 886 887 889 890 892 893 895 896 898 899 901 902 Columns 603 through 616 904 905 907 908 910 911 913 914 916 917 919 920 922 923 Columns 617 through 630 925 926 928 929 931 932 934 935 937 938 940 941 943 944 Columns 631 through 644 946 947 949 950 952 953 955 956 958 959 961 962 964 965 Columns 645 through 658 967 968 970 971 973 974 976 977 979 980 982 983 985 986 Columns 659 through 672 988 989 991 992 994 995 997 998 1000 1001 1003 1004 1006 1007 Columns 673 through 683 1009 1010 1012 1013 1015 1016 1018 1019 1021 1022 1024

Assertion failed.

3   Fail
assert(isequal(speed_decimation(2012,50),543))

y = Columns 1 through 14 1 2 3 4 5 6 7 8 9 10 11 12 13 14 Columns 15 through 28 15 16 17 18 19 20 21 22 23 24 25 26 27 28 Columns 29 through 42 29 30 31 32 33 34 35 36 37 38 39 40 41 42 Columns 43 through 56 43 44 45 46 47 48 49 51 52 53 54 55 56 57 Columns 57 through 70 58 59 60 61 62 63 64 65 66 67 68 69 70 71 Columns 71 through 84 72 73 74 75 76 77 78 79 80 81 82 83 84 85 Columns 85 through 98 86 87 88 89 90 91 92 93 94 95 96 97 98 99 Columns 99 through 112 101 102 103 104 105 106 107 108 109 110 111 112 113 114 Columns 113 through 126 115 116 117 118 119 120 121 122 123 124 125 126 127 128 Columns 127 through 140 129 130 131 132 133 134 135 136 137 138 139 140 141 142 Columns 141 through 154 143 144 145 146 147 148 149 151 152 153 154 155 156 157 Columns 155 through 168 158 159 160 161 162 163 164 165 166 167 168 169 170 171 Columns 169 through 182 172 173 174 175 176 177 178 179 180 181 182 183 184 185 Columns 183 through 196 186 187 188 189 190 191 192 193 194 195 196 197 198 199 Columns 197 through 210 201 202 203 204 205 206 207 208 209 210 211 212 213 214 Columns 211 through 224 215 216 217 218 219 220 221 222 223 224 225 226 227 228 Columns 225 through 238 229 230 231 232 233 234 235 236 237 238 239 240 241 242 Columns 239 through 252 243 244 245 246 247 248 249 251 252 253 254 255 256 257 Columns 253 through 266 258 259 260 261 262 263 264 265 266 267 268 269 270 271 Columns 267 through 280 272 273 274 275 276 277 278 279 280 281 282 283 284 285 Columns 281 through 294 286 287 288 289 290 291 292 293 294 295 296 297 298 299 Columns 295 through 308 301 302 303 304 305 306 307 308 309 310 311 312 313 314 Columns 309 through 322 315 316 317 318 319 320 321 322 323 324 325 326 327 328 Columns 323 through 336 329 330 331 332 333 334 335 336 337 338 339 340 341 342 Columns 337 through 350 343 344 345 346 347 348 349 351 352 353 354 355 356 357 Columns 351 through 364 358 359 360 361 362 363 364 365 366 367 368 369 370 371 Columns 365 through 378 372 373 374 375 376 377 378 379 380 381 382 383 384 385 Columns 379 through 392 386 387 388 389 390 391 392 393 394 395 396 397 398 399 Columns 393 through 406 401 402 403 404 405 406 407 408 409 410 411 412 413 414 Columns 407 through 420 415 416 417 418 419 420 421 422 423 424 425 426 427 428 Columns 421 through 434 429 430 431 432 433 434 435 436 437 438 439 440 441 442 Columns 435 through 448 443 444 445 446 447 448 449 451 452 453 454 455 456 457 Columns 449 through 462 458 459 460 461 462 463 464 465 466 467 468 469 470 471 Columns 463 through 476 472 473 474 475 476 477 478 479 480 481 482 483 484 485 Columns 477 through 490 486 487 488 489 490 491 492 493 494 495 496 497 498 499 Columns 491 through 504 501 502 503 504 505 506 507 508 509 510 511 512 513 514 Columns 505 through 518 515 516 517 518 519 520 521 522 523 524 525 526 527 528 Columns 519 through 532 529 530 531 532 533 534 535 536 537 538 539 540 541 542 Columns 533 through 546 543 544 545 546 547 548 549 551 552 553 554 555 556 557 Columns 547 through 560 558 559 560 561 562 563 564 565 566 567 568 569 570 571 Columns 561 through 574 572 573 574 575 576 577 578 579 580 581 582 583 584 585 Columns 575 through 588 586 587 588 589 590 591 592 593 594 595 596 597 598 599 Columns 589 through 602 601 602 603 604 605 606 607 608 609 610 611 612 613 614 Columns 603 through 616 615 616 617 618 619 620 621 622 623 624 625 626 627 628 Columns 617 through 630 629 630 631 632 633 634 635 636 637 638 639 640 641 642 Columns 631 through 644 643 644 645 646 647 648 649 651 652 653 654 655 656 657 Columns 645 through 658 658 659 660 661 662 663 664 665 666 667 668 669 670 671 Columns 659 through 672 672 673 674 675 676 677 678 679 680 681 682 683 684 685 Columns 673 through 686 686 687 688 689 690 691 692 693 694 695 696 697 698 699 Columns 687 through 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 Columns 701 through 714 715 716 717 718 719 720 721 722 723 724 725 ...

Assertion failed.

4   Fail
assert(isequal(speed_decimation(30,5),3))

y = 1 2 3 4 6 7 8 9 11 12 13 14 16 17 18 19 21 22 23 24 26 27 28 29

Assertion failed.

5   Fail
assert(isequal(speed_decimation(10,10),8))

y = 1 2 3 4 5 6 7 8 9

Assertion failed.

6   Fail
assert(isequal(speed_decimation(2048,2),1))

y = Columns 1 through 14 1 3 5 7 9 11 13 15 17 19 21 23 25 27 Columns 15 through 28 29 31 33 35 37 39 41 43 45 47 49 51 53 55 Columns 29 through 42 57 59 61 63 65 67 69 71 73 75 77 79 81 83 Columns 43 through 56 85 87 89 91 93 95 97 99 101 103 105 107 109 111 Columns 57 through 70 113 115 117 119 121 123 125 127 129 131 133 135 137 139 Columns 71 through 84 141 143 145 147 149 151 153 155 157 159 161 163 165 167 Columns 85 through 98 169 171 173 175 177 179 181 183 185 187 189 191 193 195 Columns 99 through 112 197 199 201 203 205 207 209 211 213 215 217 219 221 223 Columns 113 through 126 225 227 229 231 233 235 237 239 241 243 245 247 249 251 Columns 127 through 140 253 255 257 259 261 263 265 267 269 271 273 275 277 279 Columns 141 through 154 281 283 285 287 289 291 293 295 297 299 301 303 305 307 Columns 155 through 168 309 311 313 315 317 319 321 323 325 327 329 331 333 335 Columns 169 through 182 337 339 341 343 345 347 349 351 353 355 357 359 361 363 Columns 183 through 196 365 367 369 371 373 375 377 379 381 383 385 387 389 391 Columns 197 through 210 393 395 397 399 401 403 405 407 409 411 413 415 417 419 Columns 211 through 224 421 423 425 427 429 431 433 435 437 439 441 443 445 447 Columns 225 through 238 449 451 453 455 457 459 461 463 465 467 469 471 473 475 Columns 239 through 252 477 479 481 483 485 487 489 491 493 495 497 499 501 503 Columns 253 through 266 505 507 509 511 513 515 517 519 521 523 525 527 529 531 Columns 267 through 280 533 535 537 539 541 543 545 547 549 551 553 555 557 559 Columns 281 through 294 561 563 565 567 569 571 573 575 577 579 581 583 585 587 Columns 295 through 308 589 591 593 595 597 599 601 603 605 607 609 611 613 615 Columns 309 through 322 617 619 621 623 625 627 629 631 633 635 637 639 641 643 Columns 323 through 336 645 647 649 651 653 655 657 659 661 663 665 667 669 671 Columns 337 through 350 673 675 677 679 681 683 685 687 689 691 693 695 697 699 Columns 351 through 364 701 703 705 707 709 711 713 715 717 719 721 723 725 727 Columns 365 through 378 729 731 733 735 737 739 741 743 745 747 749 751 753 755 Columns 379 through 392 757 759 761 763 765 767 769 771 773 775 777 779 781 783 Columns 393 through 406 785 787 789 791 793 795 797 799 801 803 805 807 809 811 Columns 407 through 420 813 815 817 819 821 823 825 827 829 831 833 835 837 839 Columns 421 through 434 841 843 845 847 849 851 853 855 857 859 861 863 865 867 Columns 435 through 448 869 871 873 875 877 879 881 883 885 887 889 891 893 895 Columns 449 through 462 897 899 901 903 905 907 909 911 913 915 917 919 921 923 Columns 463 through 476 925 927 929 931 933 935 937 939 941 943 945 947 949 951 Columns 477 through 490 953 955 957 959 961 963 965 967 969 971 973 975 977 979 Columns 491 through 504 981 983 985 987 989 991 993 995 997 999 1001 1003 1005 1007 Columns 505 through 518 1009 1011 1013 1015 1017 1019 1021 1023 1025 1027 1029 1031 1033 1035 Columns 519 through 532 1037 1039 1041 1043 1045 1047 1049 1051 1053 1055 1057 1059 1061 1063 Columns 533 through 546 1065 1067 1069 1071 1073 1075 1077 1079 1081 1083 1085 1087 1089 1091 Columns 547 through 560 1093 1095 1097 1099 1101 1103 1105 1107 1109 1111 1113 1115 1117 1119 Columns 561 through 574 1121 1123 1125 1127 1129 1131 1133 1135 1137 1139 1141 1143 1145 1147 Columns 575 through 588 1149 1151 1153 1155 1157 1159 1161 1163 1165 1167 1169 1171 1173 1175 Columns 589 through 602 1177 1179 1181 1183 1185 1187 1189 1191 1193 1195 1197 1199 1201 1203 Columns 603 through 616 1205 1207 1209 1211 1213 1215 1217 1219 1221 1223 1225 1227 1229 1231 Columns 617 through 630 1233 1235 1237 1239 1241 1243 1245 1247 1249 1251 1253 1255 1257 1259 Columns 631 through 644 1261 1263 1265 1267 1269 1271 1273 1275 1277 1279 1281 1283 1285 1287 Columns 645 through 658 1289 1291 1293 1295 1297 1299 1301 1303 1305 1307 1309 1311 1313 1315 Columns 659 through 672 1317 1319 1321 1323 1325 1327 1329 1331 1333 1335 1337 1339 1341 1343 Columns 673 through 686 1345 1347 1349 1351 1353 1355 1357 1359 1361 1363 1365 1367 1369 1371 Columns 687 through 700 1373 1375 1377 1379 1381 1383 1385 1387 1389 1391 1393 1395 1397 1399 Columns 701 through 714 1401 1403 1405 1407 1409 1411 1413 1415 1417 1419 1421 ...

Assertion failed.

7   Fail
assert(isequal(speed_decimation(2048,1024),1773))

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

Assertion failed.

8   Fail
t_in=clock; j=1:50; v=arrayfun(@(x) speed_decimation(100000,x),j); correct=[100000 68929 92620 32942 40333 54212 27152 67341 42610 77328 82991 13252 91717 6850 45758 71249 38339 86953 63331 66903 72606 83990 87828 46101 99979 47141 16871 60389 51549 76409 42868 78390 79590 27573 95835 53636 36954 39891 45943 63811 71589 70886 49313 4069 93694 96031 20739 41403 93714 60023]; assert(all(isequal(v,correct))); t_out=etime(clock,t_in)*1000; fprintf('Actual Time = %.0f msec\n',t_out) v=[100000:100000:1000000]; v=arrayfun(@(x) speed_decimation(x,17),v); correct=[38339 162859 151602 99465 462955 559860 337009 546467 563784 364193]; assert(all(isequal(v,correct))); t_out=etime(clock,t_in)*1000; fprintf('Actual Time = %.0f msec\n',t_out) assert(isequal(speed_decimation(2^20,2^9),210856)); t_out=etime(clock,t_in)*1000; t2=min(100000,t_out); fprintf('Actual Time = %.0f msec\n',t_out) feval(@assignin,'caller','score',floor(t2));

y = 1×0 empty double row vector

Error using arrayfun Non-scalar in Uniform output, at index 1, output 1. Set 'UniformOutput' to false. Error in Test8 (line 3) v=arrayfun(@(x) speed_decimation(100000,x),j);

Suggested Problems

More from this Author80

Community Treasure Hunt

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

Start Hunting!