Taxicab numbers: Difference between revisions
Content added Content deleted
m (→{{header|REXX}}: added/changed whitespace and comments. simplified a function, corrected syntax of the output (text string).) |
(Added Elixir) |
||
Line 513: | Line 513: | ||
2006: 1677646971 = 990^3 + 891^3 = 1188^3 + 99^3</pre> |
2006: 1677646971 = 990^3 + 891^3 = 1188^3 + 99^3</pre> |
||
Run-time: about 0.08 seconds with ldc2 compiler. |
Run-time: about 0.08 seconds with ldc2 compiler. |
||
=={{header|DCL}}== |
=={{header|DCL}}== |
||
We invoke external utility SORT which I suppose technically speaking is not a formal part of the language but is darn handy at times; |
We invoke external utility SORT which I suppose technically speaking is not a formal part of the language but is darn handy at times; |
||
Line 656: | Line 657: | ||
(for ((i (in-naturals nfrom)) (taxi (sublist taxis nfrom nto))) |
(for ((i (in-naturals nfrom)) (taxi (sublist taxis nfrom nto))) |
||
(writeln (taxi->string i (first taxi))))) |
(writeln (taxi->string i (first taxi))))) |
||
</lang> |
</lang> |
||
{{out}} |
{{out}} |
||
<lang scheme> |
<lang scheme> |
||
Line 703: | Line 704: | ||
1660. 1148834232 = 846^3 + 816^3 = 920^3 + 718^3 = 1044^3 + 222^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 |
1837. 1407672000 = 1050^3 + 630^3 = 1104^3 + 396^3 = 1120^3 + 140^3 |
||
</lang> |
</lang> |
||
=={{header|Elixir}}== |
|||
<lang elixir>defmodule Taxicab do |
|||
def numbers(n \\ 1200) do |
|||
(for i <- 1..n, j <- i..n, do: {i,j}) |
|||
|> Enum.group_by(fn {i,j} -> i*i*i + j*j*j end) |
|||
|> Enum.filter(fn {_,v} -> length(v)>1 end) |
|||
|> Enum.sort |
|||
end |
|||
end |
|||
nums = Taxicab.numbers |> Enum.with_index |
|||
Enum.each(nums, fn {x,i} -> |
|||
if i in 0..24 or i in 1999..2005 do |
|||
IO.puts "#{i+1} : #{inspect x}" |
|||
end |
|||
end)</lang> |
|||
{{out}} |
|||
<pre> |
|||
1 : {1729, [{9, 10}, {1, 12}]} |
|||
2 : {4104, [{9, 15}, {2, 16}]} |
|||
3 : {13832, [{18, 20}, {2, 24}]} |
|||
4 : {20683, [{19, 24}, {10, 27}]} |
|||
5 : {32832, [{18, 30}, {4, 32}]} |
|||
6 : {39312, [{15, 33}, {2, 34}]} |
|||
7 : {40033, [{16, 33}, {9, 34}]} |
|||
8 : {46683, [{27, 30}, {3, 36}]} |
|||
9 : {64232, [{26, 36}, {17, 39}]} |
|||
10 : {65728, [{31, 33}, {12, 40}]} |
|||
11 : {110656, [{36, 40}, {4, 48}]} |
|||
12 : {110808, [{27, 45}, {6, 48}]} |
|||
13 : {134379, [{38, 43}, {12, 51}]} |
|||
14 : {149389, [{29, 50}, {8, 53}]} |
|||
15 : {165464, [{38, 48}, {20, 54}]} |
|||
16 : {171288, [{24, 54}, {17, 55}]} |
|||
17 : {195841, [{22, 57}, {9, 58}]} |
|||
18 : {216027, [{22, 59}, {3, 60}]} |
|||
19 : {216125, [{45, 50}, {5, 60}]} |
|||
20 : {262656, [{36, 60}, {8, 64}]} |
|||
21 : {314496, [{30, 66}, {4, 68}]} |
|||
22 : {320264, [{32, 66}, {18, 68}]} |
|||
23 : {327763, [{51, 58}, {30, 67}]} |
|||
24 : {373464, [{54, 60}, {6, 72}]} |
|||
25 : {402597, [{56, 61}, {42, 69}]} |
|||
2000 : {1671816384, [{940, 944}, {428, 1168}]} |
|||
2001 : {1672470592, [{632, 1124}, {29, 1187}]} |
|||
2002 : {1673170856, [{828, 1034}, {458, 1164}]} |
|||
2003 : {1675045225, [{744, 1081}, {522, 1153}]} |
|||
2004 : {1675958167, [{711, 1096}, {492, 1159}]} |
|||
2005 : {1676926719, [{714, 1095}, {63, 1188}]} |
|||
2006 : {1677646971, [{891, 990}, {99, 1188}]} |
|||
</pre> |
|||
=={{header|Go}}== |
=={{header|Go}}== |
||
Line 1,304: | Line 1,357: | ||
2006: 1677646971 = 99^3 + 1188^3 = 891^3 + 990^3 |
2006: 1677646971 = 99^3 + 1188^3 = 891^3 + 990^3 |
||
</pre> |
</pre> |
||
=={{header|Perl 6}}== |
=={{header|Perl 6}}== |