Taxicab numbers: Difference between revisions
→{{header|jq}}: truncate sum_of_two_cubes to guarantee accuracy
(→{{header|jq}}: shorten) |
(→{{header|jq}}: truncate sum_of_two_cubes to guarantee accuracy) |
||
Line 946:
{{works with|jq|1.4}}
<lang jq># Output: an array
# as it might not capture taxicab numbers greater than $in ^ 3.
▲# Only cubes of 1 to ($in-1) are considered.
def sum_of_two_cubes:
def cubed: .*.*.;
. as $in
| (cubed + 1) as $limit
| [range(1;$in) as $i | range($i;$in) as $j
| [ ($i|cubed) + ($j|cubed), [$i, $j] ] ] | sort
| map( select( .[0] < $limit ) );
# Output a stream of triples [t, d1, d2], in order of t,
|