Taxicab numbers: Difference between revisions

→‎{{header|Lua}}: added Lua solution
(→‎{{header|C sharp}}: added alternate algorithm)
(→‎{{header|Lua}}: added Lua solution)
Line 1,961:
2006: 1677646971 = 990^3 + 891^3 = 1188^3 + 99^3
</pre>
 
=={{header|Lua}}==
<lang lua>sums, taxis, limit = {}, {}, 1200
for i = 1, limit do
for j = 1, i-1 do
sum = i^3 + j^3
sums[sum] = sums[sum] or {}
table.insert(sums[sum], i.."^3 + "..j.."^3")
end
end
for k,v in pairs(sums) do
if #v > 1 then table.insert(taxis, { sum=k, num=#v, terms=table.concat(v," = ") }) end
end
table.sort(taxis, function(a,b) return a.sum<b.sum end)
for i=1,2006 do
if i<=25 or i>=2000 or taxis[i].num==3 then
print(string.format("%4d%s: %10d = %s", i, taxis[i].num==3 and "*" or " ", taxis[i].sum, taxis[i].terms))
end
end
print("* n=3")</lang>
{{out}}
<pre> 1 : 1729 = 10^3 + 9^3 = 12^3 + 1^3
2 : 4104 = 15^3 + 9^3 = 16^3 + 2^3
3 : 13832 = 20^3 + 18^3 = 24^3 + 2^3
4 : 20683 = 24^3 + 19^3 = 27^3 + 10^3
5 : 32832 = 30^3 + 18^3 = 32^3 + 4^3
6 : 39312 = 33^3 + 15^3 = 34^3 + 2^3
7 : 40033 = 33^3 + 16^3 = 34^3 + 9^3
8 : 46683 = 30^3 + 27^3 = 36^3 + 3^3
9 : 64232 = 36^3 + 26^3 = 39^3 + 17^3
10 : 65728 = 33^3 + 31^3 = 40^3 + 12^3
11 : 110656 = 40^3 + 36^3 = 48^3 + 4^3
12 : 110808 = 45^3 + 27^3 = 48^3 + 6^3
13 : 134379 = 43^3 + 38^3 = 51^3 + 12^3
14 : 149389 = 50^3 + 29^3 = 53^3 + 8^3
15 : 165464 = 48^3 + 38^3 = 54^3 + 20^3
16 : 171288 = 54^3 + 24^3 = 55^3 + 17^3
17 : 195841 = 57^3 + 22^3 = 58^3 + 9^3
18 : 216027 = 59^3 + 22^3 = 60^3 + 3^3
19 : 216125 = 50^3 + 45^3 = 60^3 + 5^3
20 : 262656 = 60^3 + 36^3 = 64^3 + 8^3
21 : 314496 = 66^3 + 30^3 = 68^3 + 4^3
22 : 320264 = 66^3 + 32^3 = 68^3 + 18^3
23 : 327763 = 58^3 + 51^3 = 67^3 + 30^3
24 : 373464 = 60^3 + 54^3 = 72^3 + 6^3
25 : 402597 = 61^3 + 56^3 = 69^3 + 42^3
455*: 87539319 = 414^3 + 255^3 = 423^3 + 228^3 = 436^3 + 167^3
535*: 119824488 = 428^3 + 346^3 = 492^3 + 90^3 = 493^3 + 11^3
588*: 143604279 = 423^3 + 408^3 = 460^3 + 359^3 = 522^3 + 111^3
655*: 175959000 = 525^3 + 315^3 = 552^3 + 198^3 = 560^3 + 70^3
888*: 327763000 = 580^3 + 510^3 = 661^3 + 339^3 = 670^3 + 300^3
1299*: 700314552 = 828^3 + 510^3 = 846^3 + 456^3 = 872^3 + 334^3
1398*: 804360375 = 920^3 + 295^3 = 927^3 + 198^3 = 930^3 + 15^3
1515*: 958595904 = 856^3 + 692^3 = 984^3 + 180^3 = 986^3 + 22^3
1660*: 1148834232 = 846^3 + 816^3 = 920^3 + 718^3 = 1044^3 + 222^3
1837*: 1407672000 = 1050^3 + 630^3 = 1104^3 + 396^3 = 1120^3 + 140^3
2000 : 1671816384 = 944^3 + 940^3 = 1168^3 + 428^3
2001 : 1672470592 = 1124^3 + 632^3 = 1187^3 + 29^3
2002 : 1673170856 = 1034^3 + 828^3 = 1164^3 + 458^3
2003 : 1675045225 = 1081^3 + 744^3 = 1153^3 + 522^3
2004 : 1675958167 = 1096^3 + 711^3 = 1159^3 + 492^3
2005 : 1676926719 = 1095^3 + 714^3 = 1188^3 + 63^3
2006 : 1677646971 = 990^3 + 891^3 = 1188^3 + 99^3
* n=3</pre>
 
=={{header|Mathematica}}==
Anonymous user