Sum of first n cubes: Difference between revisions

(Added Sidef)
Line 522:
1071225 1168561 1272384 1382976 1500625</pre>
 
=={{header|jq}}==
{{works with|jq}}
'''Works with gojq, the Go implementation of jq'''
<lang jq>
# For the sake of stream-processing efficiency:
def add(s): reduce s as $x (0; . + $x);
 
def sum_of_cubes: add(range(0;.) | .*.*.);</lang>
'''The task'''
<lang jq>
range(0;50) | sum_of_cubes as $sum
| "\(.) => \($sum)"</lang>
{{out}}
<pre>
0 => 0
1 => 0
2 => 1
3 => 9
4 => 36
5 => 100
...
45 => 980100
46 => 1071225
47 => 1168561
48 => 1272384
49 => 1382976
</pre>
Using gojq, the Go implementation of jq, unbounded-precision integer arithmetic allows e.g.
<pre>
1000000 | sum_of_cubes #=> 249999500000250000000000
</pre>
=={{header|Julia}}==
<lang julia>cubesumstil(N = 49, s = 0) = (foreach(n -> print(lpad(s += n^3, 8), n % 10 == 9 ? "\n" : ""), 0:N))
2,478

edits