Cody

Problem 44476. How many unique Pythagorean triples?

Solution 2082987

Submitted on 7 Jan 2020 by Othman Salih
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('triples.m'); assert(isempty(strfind(filetext, 'regexp')),'regexp hacks are forbidden')

2   Pass
n = 1; mat_correct = []; assert(isequal(triples(n),mat_correct))

3   Pass
n = 20.5; mat_correct = []; assert(isequal(triples(n),mat_correct))

c = 2.8284 mat = [] c = 3.6056 mat = [] c = 4.4721 mat = [] c = 5.3852 mat = [] c = 6.3246 mat = [] c = 7.2801 mat = [] c = 8.2462 mat = [] c = 9.2195 mat = [] c = 10.1980 mat = [] c = 11.1803 mat = [] c = 12.1655 mat = [] c = 13.1529 mat = [] c = 14.1421 mat = [] c = 15.1327 mat = [] c = 16.1245 mat = [] c = 17.1172 mat = [] c = 18.1108 mat = [] c = 19.1050 mat = [] c = 4.2426 mat = [] c = 5 mat = 3 4 5 mat = [] c = 5.8310 mat = [] c = 6.7082 mat = [] c = 7.6158 mat = [] c = 8.5440 mat = [] c = 9.4868 mat = [] c = 10.4403 mat = [] c = 11.4018 mat = [] c = 12.3693 mat = [] c = 13.3417 mat = [] c = 14.3178 mat = [] c = 15.2971 mat = [] c = 16.2788 mat = [] c = 17.2627 mat = [] c = 18.2483 mat = [] c = 19.2354 mat = [] c = 5.6569 mat = [] c = 6.4031 mat = [] c = 7.2111 mat = [] c = 8.0623 mat = [] c = 8.9443 mat = [] c = 9.8489 mat = [] c = 10.7703 mat = [] c = 11.7047 mat = [] c = 12.6491 mat = [] c = 13.6015 mat = [] c = 14.5602 mat = [] c = 15.5242 mat = [] c = 16.4924 mat = [] c = 17.4642 mat = [] c = 18.4391 mat = [] c = 19.4165 mat = [] c = 7.0711 mat = [] c = 7.8102 mat = [] c = 8.6023 mat = [] c = 9.4340 mat = [] c = 10.2956 mat = [] c = 11.1803 mat = [] c = 12.0830 mat = [] c = 13 mat = 5 12 13 mat = [] c = 13.9284 mat = [] c = 14.8661 mat = [] c = 15.8114 mat = [] c = 16.7631 mat = [] c = 17.7200 mat = [] c = 18.6815 mat = [] c = 19.6469 mat = [] c = 8.4853 mat = [] c = 9.2195 mat = [] c = 10 mat = 6 8 10 mat = [] c = 10.8167 mat = [] c = 11.6619 mat = [] c = 12.5300 mat = [] c = 13.4164 mat = [] c = 14.3178 mat = [] c = 15.2315 mat = [] c = 16.1555 mat = [] c = 17.0880 mat = [] c = 18.0278 mat = [] c = 18.9737 mat = [] c = 19.9249 mat = [] c = 9.8995 mat = [] c = 10.6301 mat = [] c = 11.4018 mat = [] c = 12.2066 mat = [] c = 13.0384 mat = [] c = 13.8924 mat = [] c = 14.7648 mat = [] c = 15.6525 mat = [] c = 16.5529 mat = [] c = 17.4642 mat = [] c = 18.3848 mat = [] c = 19.3132 mat = [] c = 20.2485 mat = [] c = 11.3137 mat = [] c = 12.0416 mat = [] c = 12.8062 mat = [] c = 13.6015 mat = [] c = 14.4222 mat = [] c = 15.2643 mat = [] c = 16.1245 mat = [] c = 17 mat = 8 15 17 mat = [] c = 17.8885 mat = [] c = 18.7883 mat = [] c = 19.6977 mat = [] c = 20.6155 mat = [] c = 12.7279 mat = [] c = 13.4536 mat = [] c = 14.2127 mat = [] c = 15 mat = 9 12 15 mat = [] c = 15.8114 mat = [] c = 16.6433 mat = [] c = 17.4929 mat = [] c = 18.3576 mat = [] c = 19.2354 mat = [] c = 20.1246 mat = [] c = 21.0238 mat = [] c = 14.1421 mat = [] c = 14.8661 mat = [] c = 15.6205 mat = [] c = 16.4012 mat = [] c = 17.2047 mat = [] c = 18.0278 mat = [] c = 18.8680 mat = [] c = 19.7231 mat = [] c = 20.5913 mat = [] c = 21.4709 mat = [] c = 15.5563 mat = [] c = 16.2788 mat = [] c = 17.0294 mat = [] c = 17.8045 mat = [] c = 18.6011 mat = [] c = 19.4165 mat = [] c = 20.2485 mat = [] c = 21.0950 mat = [] c = 21.9545 mat = [] c = 16.9706 mat = [] c = 17.6918 mat = [] c = 18.4391 mat = [] c = 19.2094 mat = [] c = 20 mat = 12 16 20 mat = [] c = 20.8087 mat = [] c = 21.6333 mat = [] c = 22.4722 mat = [] c = 18.3848 mat = [] c = 19.1050 mat = [] c = 19.8494 mat = [] c = 20.6155 mat = [] c = 21.4009 mat = [] c = 22.2036 mat = [] c = 23.0217 mat = [] c = 19.7990 mat = [] c = 20.5183 mat = [] c = 21.2603 mat = [] c = 22.0227 mat = [] c = 22.8035 mat = [] c = 23.6008 mat = [] c = 21.2132 mat = [] c = 21.9317 mat = [] c = 22.6716 mat = [] c = 23.4307 mat = [] c = 24.2074 mat = [] c = 22.6274 mat = [] c = 23.3452 mat = [] c = 24.0832 mat = [] c = 24.8395 mat = [] c = 24.0416 mat = [] c = 24.7588 mat = [] c = 25.4951 mat = [] c = 25.4558 mat = [] c = 26.1725 mat = [] c = 26.8701 mat = []

4   Pass
n = 15; mat_correct = [3, 4, 5; 5, 12, 13; 6, 8, 10; 9, 12, 15]; assert(isequal(triples(n),mat_correct))

c = 2.8284 c = 3.6056 c = 4.4721 c = 5.3852 c = 6.3246 c = 7.2801 c = 8.2462 c = 9.2195 c = 10.1980 c = 11.1803 c = 12.1655 c = 13.1529 c = 14.1421 c = 4.2426 c = 5 mat = 3 4 5 c = 5.8310 c = 6.7082 c = 7.6158 c = 8.5440 c = 9.4868 c = 10.4403 c = 11.4018 c = 12.3693 c = 13.3417 c = 14.3178 c = 5.6569 c = 6.4031 c = 7.2111 c = 8.0623 c = 8.9443 c = 9.8489 c = 10.7703 c = 11.7047 c = 12.6491 c = 13.6015 c = 14.5602 c = 7.0711 c = 7.8102 c = 8.6023 c = 9.4340 c = 10.2956 c = 11.1803 c = 12.0830 c = 13 mat = 3 4 5 5 12 13 c = 13.9284 c = 14.8661 c = 8.4853 c = 9.2195 c = 10 mat = 3 4 5 5 12 13 6 8 10 c = 10.8167 c = 11.6619 c = 12.5300 c = 13.4164 c = 14.3178 c = 15.2315 c = 9.8995 c = 10.6301 c = 11.4018 c = 12.2066 c = 13.0384 c = 13.8924 c = 14.7648 c = 15.6525 c = 11.3137 c = 12.0416 c = 12.8062 c = 13.6015 c = 14.4222 c = 15.2643 c = 16.1245 c = 12.7279 c = 13.4536 c = 14.2127 c = 15 mat = 3 4 5 5 12 13 6 8 10 9 12 15 c = 15.8114 c = 16.6433 c = 14.1421 c = 14.8661 c = 15.6205 c = 16.4012 c = 17.2047 c = 15.5563 c = 16.2788 c = 17.0294 c = 17.8045 c = 16.9706 c = 17.6918 c = 18.4391 c = 18.3848 c = 19.1050 c = 19.7990

5   Pass
n = 16; mat_correct = [3, 4, 5; 5, 12, 13; 6, 8, 10; 9, 12, 15]; assert(isequal(triples(n),mat_correct))

c = 2.8284 c = 3.6056 c = 4.4721 c = 5.3852 c = 6.3246 c = 7.2801 c = 8.2462 c = 9.2195 c = 10.1980 c = 11.1803 c = 12.1655 c = 13.1529 c = 14.1421 c = 15.1327 c = 4.2426 c = 5 mat = 3 4 5 c = 5.8310 c = 6.7082 c = 7.6158 c = 8.5440 c = 9.4868 c = 10.4403 c = 11.4018 c = 12.3693 c = 13.3417 c = 14.3178 c = 15.2971 c = 5.6569 c = 6.4031 c = 7.2111 c = 8.0623 c = 8.9443 c = 9.8489 c = 10.7703 c = 11.7047 c = 12.6491 c = 13.6015 c = 14.5602 c = 15.5242 c = 7.0711 c = 7.8102 c = 8.6023 c = 9.4340 c = 10.2956 c = 11.1803 c = 12.0830 c = 13 mat = 3 4 5 5 12 13 c = 13.9284 c = 14.8661 c = 15.8114 c = 8.4853 c = 9.2195 c = 10 mat = 3 4 5 5 12 13 6 8 10 c = 10.8167 c = 11.6619 c = 12.5300 c = 13.4164 c = 14.3178 c = 15.2315 c = 16.1555 c = 9.8995 c = 10.6301 c = 11.4018 c = 12.2066 c = 13.0384 c = 13.8924 c = 14.7648 c = 15.6525 c = 16.5529 c = 11.3137 c = 12.0416 c = 12.8062 c = 13.6015 c = 14.4222 c = 15.2643 c = 16.1245 c = 17 c = 12.7279 c = 13.4536 c = 14.2127 c = 15 mat = 3 4 5 5 12 13 6 8 10 9 12 15 c = 15.8114 c = 16.6433 c = 17.4929 c = 14.1421 c = 14.8661 c = 15.6205 c = 16.4012 c = 17.2047 c = 18.0278 c = 15.5563 c = 16.2788 c = 17.0294 c = 17.8045 c = 18.6011 c = 16.9706 c = 17.6918 c = 18.4391 c = 19.2094 c = 18.3848 c = 19.1050 c = 19.8494 c = 19.7990 c = 20.5183 c = 21.2132

6   Pass
n = 100 mat_correct = ... [3 4 5; 5 12 13; 6 8 10; 7 24 25; 8 15 17; 9 12 15; 9 40 41; 10 24 26; 11 60 61; 12 16 20; 12 35 37; 13 84 85; 14 48 50; 15 20 25; 15 36 39; 16 30 34; 16 63 65; 18 24 30; 18 80 82; 20 21 29; 20 48 52; 21 28 35; 21 72 75; 24 32 40; 24 45 51; 24 70 74; 25 60 65; 27 36 45; 28 45 53; 28 96 100; 30 40 50; 30 72 78; 32 60 68; 33 44 55; 33 56 65; 35 84 91; 36 48 60; 36 77 85; 39 52 65; 39 80 89; 40 42 58; 40 75 85; 42 56 70; 45 60 75; 48 55 73; 48 64 80; 51 68 85; 54 72 90; 57 76 95; 60 63 87; 60 80 100; 65 72 97];

n = 100

7   Pass
n = 1000; s_correct = [881, 3]; assert(isequal(size(triples(n)), s_correct))

c = 2.8284 c = 3.6056 c = 4.4721 c = 5.3852 c = 6.3246 c = 7.2801 c = 8.2462 c = 9.2195 c = 10.1980 c = 11.1803 c = 12.1655 c = 13.1529 c = 14.1421 c = 15.1327 c = 16.1245 c = 17.1172 c = 18.1108 c = 19.1050 c = 20.0998 c = 21.0950 c = 22.0907 c = 23.0868 c = 24.0832 c = 25.0799 c = 26.0768 c = 27.0740 c = 28.0713 c = 29.0689 c = 30.0666 c = 31.0644 c = 32.0624 c = 33.0606 c = 34.0588 c = 35.0571 c = 36.0555 c = 37.0540 c = 38.0526 c = 39.0512 c = 40.0500 c = 41.0488 c = 42.0476 c = 43.0465 c = 44.0454 c = 45.0444 c = 46.0435 c = 47.0425 c = 48.0416 c = 49.0408 c = 50.0400 c = 51.0392 c = 52.0384 c = 53.0377 c = 54.0370 c = 55.0364 c = 56.0357 c = 57.0351 c = 58.0345 c = 59.0339 c = 60.0333 c = 61.0328 c = 62.0322 c = 63.0317 c = 64.0312 c = 65.0308 c = 66.0303 c = 67.0298 c = 68.0294 c = 69.0290 c = 70.0286 c = 71.0282 c = 72.0278 c = 73.0274 c = 74.0270 c = 75.0267 c = 76.0263 c = 77.0260 c = 78.0256 c = 79.0253 c = 80.0250 c = 81.0247 c = 82.0244 c = 83.0241 c = 84.0238 c = 85.0235 c = 86.0233 c = 87.0230 c = 88.0227 c = 89.0225 c = 90.0222 c = 91.0220 c = 92.0217 c = 93.0215 c = 94.0213 c = 95.0211 c = 96.0208 c = 97.0206 c = 98.0204 c = 99.0202 c = 100.0200 c = 101.0198 c = 102.0196 c = 103.0194 c = 104.0192 c = 105.0190 c = 106.0189 c = 107.0187 c = 108.0185 c = 109.0183 c = 110.0182 c = 111.0180 c = 112.0179 c = 113.0177 c = 114.0175 c = 115.0174 c = 116.0172 c = 117.0171 c = 118.0169 c = 119.0168 c = 120.0167 c = 121.0165 c = 122.0164 c = 123.0163 c = 124.0161 c = 125.0160 c = 126.0159 c = 127.0157 c = 128.0156 c = 129.0155 c = 130.0154 c = 131.0153 c = 132.0152 c = 133.0150 c = 134.0149 c = 135.0148 c = 136.0147 c = 137.0146 c = 138.0145 c = 139.0144 c = 140.0143 c = 141.0142 c = 142.0141 c = 143.0140 c = 144.0139 c = 145.0138 c = 146.0137 c = 147.0136 c = 148.0135 c = 149.0134 c = 150.0133 c = 151.0132 c = 152.0132 c = 153.0131 c = 154.0130 c = 155.0129 c = 156.0128 c = 157.0127 c = 158.0127 c = 159.0126 c = 160.0125 c = 161.0124 c = 162.0123 c = 163.0123 c = 164.0122 c = 165.0121 c = 166.0120 c = 167.0120 c = 168.0119 c = 169.0118 c = 170.0118 c = 171.0117 c = 172.0116 c = 173.0116 c = 174.0115 c = 175.0114 c = 176.0114 c = 177.0113 c = 178.0112 c = 179.0112 c = 180.0111 c = 181.0110 c = 182.0110 c = 183.0109 c = 184.0109 c = 185.0108 c = 186.0108 c = 187.0107 c = 188.0106 c = 189.0106 c = 190.0105 c = 191.0105 c = 192.0104 c = 193.0104 c = 194.0103 c = 195.0103 c = 196.0102 c = 197.0102 c = 198.0101 c = 199.0100 c = 200.0100 c = 201.0100 c = 202.0099 c = 203.0099 c = 204.0098 c = 205.0098 c = 206.0097 c = 207.0097 c = 208.0096 c = 209.0096 c = 210.0095 c = 211.0095 c = 212.0094 c = 213.0094 c = 214.0093 c = 215.0093 c = 216.0093 c = 217.0092 c = 218.0092 c = 219.0091 c = 220.0091 c = 221.0090 c = 222.0090 c = 223.0090 c = 224.0089 c = 225.0089 c = 226.0088 c = 227.0088 c = 228.0088 c = 229.0087 c = 230.0087 c = 231.0087 c = 232.0086 c = 233.0086 c = 234.0085 c = 235.0085 c = 236.0085 c = 237.0084 c = 238.0084 c = 239.0084 c = 240.0083 c = 241.0083 c = 242.0083 c = 243.0082 c = 244.0082 c = 245.0082 c = 246.0081 c = 247.0081 c = 248.0081 c = 249.0080 c = 250.0080 c = 251.0080 c = 252.0079 c = 253.0079 c = 254.0079 c = 255.0078 c = 256.0078 c = 257.0078 c = 258.0078 c = 259.0077 c = 260.0077 c = 261.0077 c = 262.0076 c = 263.0076 c = 264.0076 c = 265.0075 c = 266.0075 c = 267.0075 c = 268.0075 c = 269.0074 c = 270.0074 c = 271.0074 c = 272.0074 c = 273.0073 c = 274.0073 c = 275.0073 c = 276.0072 c = 277.0072 c = 278.0072 c = 279.0072 c = 280.0071 c = 281.0071 c = 282.0071 c = 283.0071 c = 284.0070 c = 285.0070 c = 286.0070 c = 287.0070 c = 288.0069 c = 289.0069 c = 290.0069 c = 291.0069 c = 292.0068 c = 293.0068 c = 294.0068 c = 295.0068 c = 296.0068 c = 297.0067 c = 298.0067 c = 299.0067 c = 300.0067 c = 301.0066 c = 302.0066 c = 303.0066 c = 304.0066 c = 305.0066 c = 306.0065 c = 307.0065 c = 308.0065 c = 309.0065 c = 310.0065 c = 311.0064 c = 312.0064 c = 313.0064 c = 314.0064 c = 315.0063 c = 316.0063 c = 317.0063 c = 318.0063 c = 319.0063 c = 320.0062 c = 321.0062 c = 322.0062 c = 323.0062 c = 324.0062 c = 325.0062 c = 326.0061 c = 327.0061 c = 328.0061 c = 329.0061 c = 330.0061 c = 331.0060 c = 332.0060 c = 333.0060 c = 334.0060 c = 335.0060 c = 336.0060 c = 337.0059 c = 338.0059 c = 339.0059 c = 340.0059 c = 341.0059 c = 342.0058 c = 343.0058 c = 344.0058 c = 345.0058 c = 346.0058 c = 347.0058 c = 348.0057 c = 349.0057 c = 350.0057 c = 351.0057 c = 352.0057 c = 353.0057 c = 354.0056 c = 355.0056 c = 356.0056 c = 357.0056 c = 358.0056 c = 359.0056 c = 360.0056 c = 361.0055 c = 362.0055 c = 363.0055 c = 364.0055 c = 365.0055 c = 366.0055 c = 367.0054 c = 368.0054 c = 369.0054 c = 370.0054 c = 371.0054 c = 372.0054 c = 373.0054 c = 374.0053 c = 375.0053 c = 376.0053 c = 377.0053 c = 378.0053 c = 379.0053 c = 380.0053 c = 381.0052 c = 382.0052 c = 383.0052 c = 384.0052 c = 385.0052 c = 386.0052 c = 387.0052 c = 388.0052 c = 389.0051 c = 390.0051 c = 391.0051 c = 392.0051 c = 393.0051 c = 394.0051 c = 395.0051 c = 396.0051 c = 397.0050 c = 398.0050 c = 399.0050 c = 400.0050 c = 401.0050 c = 402.0050 c = 403.0050 c = 404.0050 c = 405.0049 c = 406.0049 c = 407.0049 c = 408.0049 c = 409.0049 c = 410.0049 c = 411.0049 c = 412.0049 c = 413.0048 c = 414.0048 c = 415.0048 c = 416.0048 c = 417.0048 c = 418.0048 c = 419.0048 c = 420.0048 c = 421.0048 c = 422.0047 c = 423.0047 c = 424.0047 c = 425.0047 c = 426.0047 c = 427.0047 c = 428.0047 c = 429.0047 c = 430.0047 c = 431.0046 c = 432.0046 c = 433.0046 c = 434.0046 c = 435.0046 c = 436.0046 c = 437.0046 c = 438.0046 c = 439.0046 c = 440.0045 c = 441.0045 c = 442.0045 c = 443.0045 c = 444.0045 c = 445.0045 c = 446.0045 c = 447.0045 c = 448.0045 c = 449.0045 c = 450.0044 c = 451.0044 c = 452.0044 c = 453.0044 c = 454.0044 c = 455.0044 c = 456.0044 c = 457.0044 c = 458.0044 c = 459.0044 c = 460.0043 c = 461.0043 c = 462.0043 c = 463.0043 c = 464.0043 c = 465.0043 c = 466.0043 c = 467.0043 c = 468.0043 c = 469.0043 c = 470.0043 c = 471.0042 c = 472.0042 c = 473.0042 c = 474.0042 c = 475.0042 c = 476.0042 c = 477.0042 c = 478.0042 c = 479.0042 c = 480.0042 c = 481.0042 c = 482.0041 c = 483.0041 c = 484.0041 c = 485.0041 c = 486.0041 c = 487.0041 c = 488.0041 c = 489.0041 c = 490.0041 c = 491.0041 c = 492.0041 c = 493.0041 c = 494.0040 c = 495.0040 c = 496.0040 c = 497.0040 c = 498.0040 c = 499.0040 c = 500.0040 c = 501.0040 c = 502.0040 c = 503.0040 c = 504.0040 c = 505.0040 c = 506.0040 c = 507.0039 c = 508.0039 c = 509.0039 c = 510.0039 c = 511.0039 c = 512.0039 c = 513.0039 c = 514.0039 c = 515.0039 c = 516.0039 c = 517.0039 c = 518.0039 c = 519.0039 c = 520.0038 c = 521.0038 c = 522.0038 c = 523.0038 c = 524.0038 c = 525.0038 c = 526.0038 c = 527.0038 c = 528.0038 c = 529.0038 c = 530.0038 c = 531.0038 c = 532.0038 c = 533.0038 c = 534.0037 c = 535.0037 c = 536.0037 c = 537.0037 c = 538.0037 c = 539.0037 c = 540.0037 c = 541.0037 c = 542.0037 c = 543.0037 c = 544.0037 c = 545.0037 c = 546.0037 c = 547.0037 c = 548.0036 c = 549.0036 c = 550.0036 c = 551.0036 c = 552.0036 c = 553.0036 c = 554.0036 c = 555.0036 c = 556.0036 c = 557...

Suggested Problems

More from this Author25

Community Treasure Hunt

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

Start Hunting!