Cody

Problem 249. Project Euler: Problem 9, Pythagorean numbers

Solution 3319193

Submitted on 21 Oct 2020 by Alex
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
x = 1000; y_correct = 31875000; assert(isequal(euler009(x),y_correct))

a = Columns 1 through 29 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 Columns 30 through 58 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 Columns 59 through 87 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 Columns 88 through 116 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 Columns 117 through 145 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 Columns 146 through 174 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 Columns 175 through 203 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 Columns 204 through 232 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 Columns 233 through 250 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 b = Columns 1 through 17 499.4995 498.9980 498.4955 497.9920 497.4874 496.9819 496.4753 495.9677 495.4591 494.9495 494.4388 493.9271 493.4144 492.9006 492.3858 491.8699 491.3530 Columns 18 through 34 490.8350 490.3160 489.7959 489.2748 488.7526 488.2293 487.7049 487.1795 486.6530 486.1254 485.5967 485.0669 484.5361 484.0041 483.4711 482.9369 482.4017 Columns 35 through 51 481.8653 481.3278 480.7892 480.2495 479.7086 479.1667 478.6236 478.0793 477.5340 476.9874 476.4398 475.8910 475.3410 474.7899 474.2376 473.6842 473.1296 Columns 52 through 68 472.5738 472.0169 471.4588 470.8995 470.3390 469.7773 469.2144 468.6504 468.0851 467.5186 466.9510 466.3821 465.8120 465.2406 464.6681 464.0943 463.5193 Columns 69 through 85 462.9431 462.3656 461.7869 461.2069 460.6257 460.0432 459.4595 458.8745 458.2882 457.7007 457.1118 456.5217 455.9304 455.3377 454.7437 454.1485 453.5519 Columns 86 through 102 452.9540 452.3549 451.7544 451.1526 450.5495 449.9450 449.3392 448.7321 448.1236 447.5138 446.9027 446.2901 445.6763 445.0610 444.4444 443.8265 443.2071 Columns 103 through 119 442.5864 441.9643 441.3408 440.7159 440.0896 439.4619 438.8328 438.2022 437.5703 436.9369 436.3021 435.6659 435.0282 434.3891 433.7486 433.1066 432.4631 Columns 120 through 136 431.8182 431.1718 430.5239 429.8746 429.2237 428.5714 427.9176 427.2623 426.6055 425.9472 425.2874 424.6260 423.9631 423.2987 422.6328 421.9653 421.2963 Columns 137 through 153 420.6257 419.9536 419.2799 418.6047 417.9278 417.2494 416.5694 415.8879 415.2047 414.5199 413.8335 413.1455 412.4559 411.7647 411.0718 410.3774 409.6812 Columns 154 through 170 408.9835 408.2840 407.5829 406.8802 406.1758 405.4697 404.7619 404.0524 403.3413 402.6284 401.9139 401.1976 400.4796 399.7599 399.0385 398.3153 397.5904 Columns 171 through 187 396.8637 396.1353 395.4051 394.6731 393.9394 393.2039 392.4666 391.7275 390.9866 390.2439 389.4994 388.7531 388.0049 387.2549 386.5031 385.7494 384.9938 Columns 188 through 204 384.2365 383.4772 382.7160 381.9530 381.1881 380.4213 379.6526 378.8820 378.1095 377.3350 376.5586 375.7803 375.0000 374.2178 373.4336 372.6474 371.8593 Columns 205 through 221 371.0692 370.2771 369.4830 368.6869 367.8887 367.0886 366.2864 365.4822 364.6760 363.8677 363.0573 362.2449 361.4304 360.6138 359.7951 358.9744 358.1515 Columns 222 through 238 357.3265 356.4994 355.6701 354.8387 354.0052 353.1695 352.3316 351.4916 350.6494 349.8049 348.9583 348.1095 347.2585 346.4052 345.5497 344.6920 343.8320 Columns 239 through 250 342.9698 342.1053 341.2385 340.3694 339.4980 338.6243 337.7483 336.8700 335.9894 335.1064 334.2210 333.3333

2   Pass
x = 2000; y_correct = 255000000; assert(isequal(euler009(x),y_correct))

a = Columns 1 through 29 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 Columns 30 through 58 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 Columns 59 through 87 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 Columns 88 through 116 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 Columns 117 through 145 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 Columns 146 through 174 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 Columns 175 through 203 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 Columns 204 through 232 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 Columns 233 through 261 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 Columns 262 through 290 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 Columns 291 through 319 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 Columns 320 through 348 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 Columns 349 through 377 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 Columns 378 through 406 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 Columns 407 through 435 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 Columns 436 through 464 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 Columns 465 through 493 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 Columns 494 through 500 494 495 496 497 498 499 500 b = Columns 1 through 17 999.4997 998.9990 998.4977 997.9960 997.4937 996.9910 996.4877 995.9839 995.4797 994.9749 994.4696 993.9638 993.4575 992.9507 992.4433 991.9355 991.4271 Columns 18 through 34 990.9183 990.4089 989.8990 989.3886 988.8777 988.3662 987.8543 987.3418 986.8288 986.3153 985.8012 985.2867 984.7716 984.2560 983.7398 983.2232 982.7060 Columns 35 through 51 982.1883 981.6701 981.1513 980.6320 980.1122 979.5918 979.0710 978.5495 978.0276 977.5051 976.9821 976.4585 975.9345 975.4098 974.8847 974.3590 973.8327 Columns 52 through 68 973.3060 972.7786 972.2508 971.7224 971.1934 970.6639 970.1339 969.6033 969.0722 968.5405 968.0083 967.4755 966.9421 966.4083 965.8738 965.3389 964.8033 Columns 69 through 85 964.2672 963.7306 963.1934 962.6556 962.1173 961.5784 961.0390 960.4990 959.9584 959.4173 958.8756 958.3333 957.7905 957.2471 956.7032 956.1587 955.6136 Columns 86 through 102 955.0679 954.5217 953.9749 953.4275 952.8796 952.3311 951.7820 951.2323 950.6821 950.1312 949.5798 949.0279 948.4753 947.9221 947.3684 946.8141 946.2592 Columns 103 through 119 945.7037 945.1477 944.5910 944.0338 943.4760 942.9175 942.3585 941.7989 941.2388 940.6780 940.1166 939.5546 938.9920 938.4289 937.8651 937.3007 936.7358 Columns 120 through 136 936.1702 935.6040 935.0373 934.4699 933.9019 933.3333 932.7641 932.1943 931.6239 931.0529 930.4813 929.9090 929.3362 928.7627 928.1886 927.6139 927.0386 Columns 137 through 153 926.4627 925.8861 925.3090 924.7312 924.1528 923.5737 922.9941 922.4138 921.8329 921.2513 920.6692 920.0864 919.5030 918.9189 918.3342 917.7489 917.1630 Columns 154 through 170 916.5764 915.9892 915.4013 914.8128 914.2237 913.6339 913.0435 912.4524 911.8607 911.2684 910.6754 910.0817 909.4875 908.8925 908.2969 907.7007 907.1038 Columns 171 through 187 906.5063 905.9081 905.3093 904.7097 904.1096 903.5088 902.9073 902.3052 901.7024 901.0989 900.4948 899.8900 899.2845 898.6784 898.0716 897.4642 896.8560 Columns 188 through 204 896.2472 895.6378 895.0276 894.4168 893.8053 893.1931 892.5803 891.9668 891.3525 890.7377 890.1221 889.5058 888.8889 888.2713 887.6529 887.0339 886.4143 Columns 205 through 221 885.7939 885.1728 884.5510 883.9286 883.3054 882.6816 882.0570 881.4318 880.8058 880.1792 879.5518 878.9238 878.2950 877.6655 877.0354 876.4045 875.7729 Columns 222 through 238 875.1406 874.5076 873.8739 873.2394 872.6043 871.9684 871.3318 870.6945 870.0565 869.4178 868.7783 868.1381 867.4972 866.8555 866.2132 865.5701 864.9262 Columns 239 through 255 864.2817 863.6364 862.9903 862.3436 861.6961 861.0478 860.3989 859.7491 859.0987 858.4475 857.7955 857.1429 856.4894 855.8352 855.1803 854.5246 853.8682 Columns 256 through 272 853.2110 852.5531 851.8944 851.2349 850.5747 849.9137 849.2520 848.5895 847.9263 847.2622 846.5975 845.9319 845.2656 844.5985 843.9306 843.2620 842.5926 Columns 273 through 289 841.9224 841.2514 840.5797 839.9072 839.2339 838.5598 837.8850 837.2093 836.5329 835.8556 835.1776 834.4988 833.8192 833.1389 832.4577 831.7757 831.0929 Columns 290 through 306 830.4094 829.7250 829.0398 828.3538 827.6671 826.9795 826.2911 825.6019 824.9119 824.2210 823.5294 822.8370 822.1437 821.4496 820.7547 820.0590 819.3625 Columns 307 through 323 818.6651 817.9669 817.2679 816.5680 815.8674 815.1659 814.4635 813.7604 813.0564 812.3515 811.6459 810.9394 810.2320 809.5238 808.8148 808.1049 807.3942 Columns 324 through 340 806.6826 805.9701 805.2569 804.5427 803.8278 803.1119 802.3952 801.6777 800.9592 800.2400 799.5198 798.7988 798.0769 797.3542 796.6306 795.9061 795.1807 Columns 341 through 357 794.4545 793.7274 792.9994 792.2705 791.5408 790.8102 790.0786 789.3462 788.6130 787.8788 787.1437 786.4078 785.6709 784.9332 784.1945 783.4550 782.7145 Columns 358 through 374 781.9732 781.2310 780.4878 779.7437 778.9988 778.2529 777.5061 776.7584 776.0098 775.2603 774.5098 773.7584 773.0061 772.2529 771.4988 770.7437 769.9877 Columns 375 through 391 769.2308 768.4729 767.7141 766.9544 766.1937 765.4321 764.6695 763.9061 763.1416 762.3762 761.6099 760.8426 760.0744 759.3052 758.5351 757.7640 756.9919 Columns 392 through 408 756.2189 755.4449 754.6700 753.8941 753.1172 752.3394 751.5605 750.7808 750.0000 749.2183 748.4355 747.6518 746.8672 746.0815 745.2949 744.5072 743.7186 Columns 409 through 425 742.9290 742.1384 741.3468 740.5542 739.7606 738.9660 738.1703 737.3737 736.5761 735.7775 734.9779 734.1772 733.3756 732.5729 731.7692 730.9645 730.1587 Columns 426 through 442 729.3520 728.5442 727.7354 726.9255 726.1146 725.3027 724.4898 723.6758 722.8608 722.0447 721.2276 720.4095 719.5903 718.7700 717.9487 717.1264 716.3030 Columns 443 through 459 715.4785 714.6530 713.8264 712.9987 712.1700 711.3402 710.5093 709.6774 708.8444 708.0103 707.1752 706.3389 705.5016 704.6632 703.8237 702.9831 702.1415 Columns 460 through 476 701.2987 700.4548 699.6099 698.7638 697.9167 697.0684 696.2190 695.3686 694.5170 693.6643 692.8105 691.9555 691.0995 690.2423 689.3840 688.5246 687.6640 Columns 477 through 493 686.8024 685.9396 685.0756 684.2105 683.3443 682.4769 681.6084 680.7388 679.8680 678.9960 678.1229 677.2487 676.3733 675.4967 674.6190 673.7401 672.8600 Columns 494 through 500 671.9788 671.0963 670.2128 669.3280 668.4421 667.5550 666.6667

3   Pass
x = 320; y_correct = 1044480; assert(isequal(euler009(x),y_correct))

a = Columns 1 through 29 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 Columns 30 through 58 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 Columns 59 through 80 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 b = Columns 1 through 17 159.4984 158.9937 158.4858 157.9747 157.4603 156.9427 156.4217 155.8974 155.3698 154.8387 154.3042 153.7662 153.2248 152.6797 152.1311 151.5789 151.0231 Columns 18 through 34 150.4636 149.9003 149.3333 148.7625 148.1879 147.6094 147.0270 146.4407 145.8503 145.2560 144.6575 144.0550 143.4483 142.8374 142.2222 141.6028 140.9790 Columns 35 through 51 140.3509 139.7183 139.0813 138.4397 137.7936 137.1429 136.4875 135.8273 135.1625 134.4928 133.8182 133.1387 132.4542 131.7647 131.0701 130.3704 129.6654 Columns 52 through 68 128.9552 128.2397 127.5188 126.7925 126.0606 125.3232 124.5802 123.8314 123.0769 122.3166 121.5504 120.7782 120.0000 119.2157 118.4252 117.6285 116.8254 Columns 69 through 80 116.0159 115.2000 114.3775 113.5484 112.7126 111.8699 111.0204 110.1639 109.3004 108.4298 107.5519 106.6667

4   Pass
x = 5000; y_correct = 3984375000 assert(isequal(euler009(x),y_correct))

y_correct = 3.9844e+09 a = 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 ...

Suggested Problems

More from this Author52

Community Treasure Hunt

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

Start Hunting!