Sum of squares: Difference between revisions
m
→{{header|Wren}}: Changed to Wren S/H
(Added PL/M) |
m (→{{header|Wren}}: Changed to Wren S/H) |
||
(8 intermediate revisions by 6 users not shown) | |||
Line 890:
<syntaxhighlight lang="lisp">(defun sum-of-squares (vector)
(loop for x across vector sum (expt x 2)))</syntaxhighlight>
Or in a functional way:
(reduce #'+ (map 'vector (lambda (x) (* x x)) vec)))</syntaxhighlight>
=={{header|Cowgol}}==
Line 1,125 ⟶ 1,129:
=={{header|Elena}}==
ELENA
<syntaxhighlight lang="elena">import system'routines;
import extensions;
SumOfSquares(list)
= list.selectBy::(x => x * x).summarize(new Integer());
public program()
Line 1,161 ⟶ 1,165:
=={{header|Euler}}==
Using [[Jensen's Device]]
'''begin'''▼
▲<syntaxhighlight lang="euler">
'''new''' i; '''new''' A; '''new''' sum;▼
▲begin
sum <- ` '''formal''' i; '''formal''' lo; '''formal''' hi; '''formal''' term;
▲ new i; new A; new sum;
loop:
';▼
A <- ( 1, 2, 3, 4, 5 );
'''end''' $▼
▲end $
</syntaxhighlight>▼
=={{header|Euphoria}}==
Line 1,307 ⟶ 1,309:
=={{header|Fōrmulæ}}==
{{FormulaeEntry|page=https://formulae.org/?script=examples/Sum_of_squares}}
'''Solution'''
[[File:Fōrmulæ - Sum of squares 01.png]]
'''Test cases'''
[[File:Fōrmulæ - Sum of squares 02.png]]
[[File:Fōrmulæ - Sum of squares 03.png]]
[[File:Fōrmulæ - Sum of squares 04.png]]
[[File:Fōrmulæ - Sum of squares 05.png]]
[[File:Fōrmulæ - Sum of squares 06.png]]
[[File:Fōrmulæ - Sum of squares 07.png]]
=={{header|GAP}}==
Line 2,389 ⟶ 2,405:
{{works with|8080 PL/M Compiler}} ... under CP/M (or an emulator)
<syntaxhighlight lang="plm">
100H: /* CALCULATE THE SUM OF THE
/* CP/M BDOS SYSTEM CALL AND I/O ROUTINES */
Line 2,650 ⟶ 2,666:
5.25
</pre>
=={{header|Refal}}==
<syntaxhighlight lang="refal">$ENTRY Go {
= <Prout <SquareSum 1 2 3 4 5>>
};
SquareSum {
= 0;
s.N e.rest = <+ <* s.N s.N> <SquareSum e.rest>>;
▲};</syntaxhighlight>
{{out}}
<pre>55</pre>
=={{header|ReScript}}==
Line 2,938 ⟶ 2,966:
(echo 3; echo 1; echo 4;echo 1;echo 5; echo 9) | fold</syntaxhighlight>
=={{header|
<syntaxhighlight lang="
for _n
do
: "$((_r += _n * _n))"
done
echo "$_r"
}
sum_squares 3 1 4 1 5 9</syntaxhighlight>▼
{{out}}
▲</syntaxhighlight>
<pre>133</pre>
=={{header|Ursala}}==
Line 3,095 ⟶ 3,124:
=={{header|Wren}}==
<syntaxhighlight lang="
var v = [1, 2, 3, -1, -2, -3]
|