Taxicab numbers: Difference between revisions
Content added Content deleted
Catskill549 (talk | contribs) (added AWK) |
|||
Line 98: | Line 98: | ||
</pre> |
</pre> |
||
=={{header|AWK}}== |
|||
<lang AWK> |
|||
# syntax: GAWK -f TAXICAB_NUMBERS.AWK |
|||
BEGIN { |
|||
stop = 99 |
|||
for (a=1; a<=stop; a++) { |
|||
for (b=1; b<=stop; b++) { |
|||
n1 = a^3 + b^3 |
|||
for (c=1; c<=stop; c++) { |
|||
if (a == c) { continue } |
|||
for (d=1; d<=stop; d++) { |
|||
n2 = c^3 + d^3 |
|||
if (n1 == n2 && (a != d || b != c)) { |
|||
if (n1 in arr) { continue } |
|||
arr[n1] = sprintf("%7d = %2d^3 + %2d^3 = %2d^3 + %2d^3",n1,a,b,c,d) |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
PROCINFO["sorted_in"] = "@ind_num_asc" |
|||
for (i in arr) { |
|||
if (++count <= 25) { |
|||
printf("%2d: %s\n",count,arr[i]) |
|||
} |
|||
} |
|||
printf("\nThere are %d taxicab numbers using bounds of %d\n",length(arr),stop) |
|||
exit(0) |
|||
} |
|||
</lang> |
|||
{{out}} |
|||
<pre> |
|||
1: 1729 = 1^3 + 12^3 = 9^3 + 10^3 |
|||
2: 4104 = 2^3 + 16^3 = 9^3 + 15^3 |
|||
3: 13832 = 2^3 + 24^3 = 18^3 + 20^3 |
|||
4: 20683 = 10^3 + 27^3 = 19^3 + 24^3 |
|||
5: 32832 = 4^3 + 32^3 = 18^3 + 30^3 |
|||
6: 39312 = 2^3 + 34^3 = 15^3 + 33^3 |
|||
7: 40033 = 9^3 + 34^3 = 16^3 + 33^3 |
|||
8: 46683 = 3^3 + 36^3 = 27^3 + 30^3 |
|||
9: 64232 = 17^3 + 39^3 = 26^3 + 36^3 |
|||
10: 65728 = 12^3 + 40^3 = 31^3 + 33^3 |
|||
11: 110656 = 4^3 + 48^3 = 36^3 + 40^3 |
|||
12: 110808 = 6^3 + 48^3 = 27^3 + 45^3 |
|||
13: 134379 = 12^3 + 51^3 = 38^3 + 43^3 |
|||
14: 149389 = 8^3 + 53^3 = 29^3 + 50^3 |
|||
15: 165464 = 20^3 + 54^3 = 38^3 + 48^3 |
|||
16: 171288 = 17^3 + 55^3 = 24^3 + 54^3 |
|||
17: 195841 = 9^3 + 58^3 = 22^3 + 57^3 |
|||
18: 216027 = 3^3 + 60^3 = 22^3 + 59^3 |
|||
19: 216125 = 5^3 + 60^3 = 45^3 + 50^3 |
|||
20: 262656 = 8^3 + 64^3 = 36^3 + 60^3 |
|||
21: 314496 = 4^3 + 68^3 = 30^3 + 66^3 |
|||
22: 320264 = 18^3 + 68^3 = 32^3 + 66^3 |
|||
23: 327763 = 30^3 + 67^3 = 51^3 + 58^3 |
|||
24: 373464 = 6^3 + 72^3 = 54^3 + 60^3 |
|||
25: 402597 = 42^3 + 69^3 = 56^3 + 61^3 |
|||
There are 45 taxicab numbers using bounds of 99 |
|||
</pre> |
|||
=={{header|Befunge}}== |
=={{header|Befunge}}== |
||