Sum of squares: Difference between revisions
m changed ;See also: to a ;Related task: |
Added code for FreeBASIC |
||
Line 644:
zresult = sum(p*p) ! P is zero-length; P*P is valid zero-length array expression; SUM(P*P) == 0.0 as expected</lang>
=={{header|FreeBASIC}}==
<lang freebasic>' FB 1.05.0 Win64
Function SumSquares(a() As Double) As Double
Dim As Integer length = UBound(a) - LBound(a) + 1
If length = 0 Then Return 0.0
Dim As Double sum = 0.0
For i As Integer = LBound(a) To UBound(a)
sum += a(i) * a(i)
Next
Return sum
End Function
Dim a(5) As Double = {1.0, 2.0, 3.0, -1.0, -2.0, -3.0}
Dim sum As Double = SumSquares(a())
Print "The sum of the squares is"; sum
Print
Print "Press any key to quit"
Sleep</lang>
{{out}}
<pre>
The sum of the squares is 28
</pre>
=={{header|Frink}}==
|
Revision as of 19:57, 3 October 2016
You are encouraged to solve this task according to the task description, using any language you may know.
- Task
Write a program to find the sum of squares of a numeric vector.
The program should work on a zero-length vector (with an answer of 0).
- Related task
0815
<lang 0815> {x{*%<:d:~$<:1:~>><:2:~>><:3:~>><:4:~>><:5:~>><:6:~>><:7: ~>><:8:~>><:9:~>><:a:~>><:b:~>><:c:~>><:ffffffffffffffff: ~>{x{*>}:8f:{x{*&{=+>{~>&=x<:ffffffffffffffff:/#:8f:{{~% </lang>
- Output:
0 28A
360 Assembly
<lang 360asm>* Sum of squares 27/08/2015 SUMOFSQR CSECT
USING SUMOFSQR,R12 LR R12,R15 LA R7,A a(1) SR R6,R6 sum=0 LA R3,1 i=1
LOOPI CH R3,N do i=1 to hbound(a)
BH ELOOPI L R5,0(R7) a(i) M R4,0(R7) a(i)*a(i) AR R6,R5 sum=sum+a(i)**2 LA R7,4(R7) next a LA R3,1(R3) i=i+1 B LOOPI end i
ELOOPI XDECO R6,PG+23 edit sum
XPRNT PG,80 XR R15,R15 BR R14
A DC F'1',F'2',F'3',F'4',F'5',F'6',F'7',F'8',F'9',F'10' PG DC CL80'The sum of squares is: ' N DC AL2((PG-A)/4)
YREGS END SUMOFSQR</lang>
- Output:
The sum of squares is: 385
ACL2
<lang Lisp>(defun sum-of-squares (xs)
(if (endp xs) 0 (+ (* (first xs) (first xs)) (sum-of-squares (rest xs)))))</lang>
ActionScript
<lang ActionScript>function sumOfSquares(vector:Vector.<Number>):Number { var sum:Number = 0; for(var i:uint = 0; i < vector.length; i++) sum += vector[i]*vector[i]; return sum; }</lang>
Ada
<lang ada>with Ada.Text_IO; use Ada.Text_IO;
procedure Test_Sum_Of_Squares is
type Float_Array is array (Integer range <>) of Float;
function Sum_Of_Squares (X : Float_Array) return Float is Sum : Float := 0.0; begin for I in X'Range loop Sum := Sum + X (I) ** 2; end loop; return Sum; end Sum_Of_Squares;
begin
Put_Line (Float'Image (Sum_Of_Squares ((1..0 => 1.0)))); -- Empty array Put_Line (Float'Image (Sum_Of_Squares ((3.0, 1.0, 4.0, 1.0, 5.0, 9.0))));
end Test_Sum_Of_Squares;</lang>
- Output:
0.00000E+00 1.33000E+02
Aime
<lang aime>real squaredsum(list l) {
integer i; real s;
s = 0; i = -l_length(l); while (i) { s += sq(l[i += 1]); }
return s;
}
integer main(void) {
list l;
l = l_effect(0, 1, 2, 3);
o_form("~\n", squaredsum(l)); o_form("~\n", squaredsum(l_effect())); o_form("~\n", squaredsum(l_effect(.5, -.5, 2)));
return 0;
}</lang>
- Output:
14 0 4.5
ALGOL 68
The computation can be written as a loop. <lang algol68>PROC sum of squares = ([]REAL argv)REAL:(
REAL sum := 0; FOR i FROM LWB argv TO UPB argv DO sum +:= argv[i]**2 OD; sum
); test:(
printf(($g(0)l$,sum of squares([]REAL(3, 1, 4, 1, 5, 9))));
)</lang>
- Output:
133
Another implementation could define a procedure (proc) or operator (op) called map.
<lang algol68>[]REAL data = (3, 1, 4, 1, 5, 9);
PROC map = ( PROC(REAL)REAL func, []REAL argv)REAL:
( REAL out:=0; FOR i FROM LWB argv TO UPB argv DO out:=func(argv[i]) OD; out);
test:(
REAL sum := 0; printf(($xg(0)l$, map ( ((REAL argv)REAL: sum +:= argv ** 2), data) ));
PRIO MAP = 5; # the same priority as the operators <, =<, >=, & > maybe... # OP MAP = ( PROC(REAL)REAL func, []REAL argv)REAL: ( REAL out:=0; FOR i FROM LWB argv TO UPB argv DO out:=func(argv[i]) OD; out);
sum := 0; printf(($g(0)l$, ((REAL argv)REAL: sum +:= argv ** 2) MAP data ))
)</lang>
- Output:
133 133
ALGOL W
<lang algolw>begin
% procedure to sum the elements of a vector. As the procedure can't find % % the bounds of the array for itself, we pass them in lb and ub % real procedure sumSquares ( real array vector ( * ) ; integer value lb ; integer value ub ) ; begin real sum; sum := 0; for i := lb until ub do sum := sum + ( vector( i ) * vector( i ) ); sum end sumOfSquares ;
% test the sumSquares procedure % real array numbers ( 1 :: 5 ); for i := 1 until 5 do numbers( i ) := i; r_format := "A"; r_w := 10; r_d := 1; % set fixed point output % write( sumSquares( numbers, 1, 5 ) );
end.</lang>
Alore
<lang Alore>def sum_squares(a)
var sum = 0 for i in a sum = sum + i**2 end return sum
end
WriteLn(sum_squares([3,1,4,1,5,9])) end</lang>
APL
<lang apl> square_sum←{+/⍵*2}
square_sum 1 2 3 4 5
55
square_sum ⍬ ⍝The empty vector
0</lang>
AutoHotkey
<lang autohotkey>list = 3 1 4 1 5 9 Loop, Parse, list, %A_Space%
sum += A_LoopField**2
MsgBox,% sum</lang>
AWK
Vectors are read, space-separated, from stdin; sum of squares goes to stdout. The empty line produces 0. <lang awk>$ awk '{s=0;for(i=1;i<=NF;i++)s+=$i*$i;print s}' 3 1 4 1 5 9 133
0</lang>
BASIC
Assume the numbers are in an array called a
.
<lang qbasic>sum = 0
FOR I = LBOUND(a) TO UBOUND(a)
sum = sum + a(I) ^ 2
NEXT I PRINT "The sum of squares is: " + sum</lang>
BBC BASIC
BBC BASIC cannot have a zero-length array. <lang bbcbasic> DIM vector(5)
vector() = 1, 2, 3, 4, 5, 6 PRINT "Sum of squares = " ; MOD(vector()) ^ 2</lang>
- Output:
Sum of squares = 91
bc
<lang bc>define s(a[], n) {
auto i, s for (i = 0; i < n; i++) { s += a[i] * a[i] } return(s)
}</lang>
Bracmat
<lang bracmat>( ( sumOfSquares
= sum component . 0:?sum & whl ' ( !arg:%?component ?arg & !component^2+!sum:?sum ) & !sum )
& out$(sumOfSquares$(3 4)) & out$(sumOfSquares$(3 4 i*5)) & out$(sumOfSquares$(a b c)) );</lang>
- Output:
25 0 a^2+b^2+c^2
Brat
<lang brat>p 1.to(10).reduce 0 { res, n | res = res + n ^ 2 } #Prints 385</lang>
C
<lang c>#include <stdio.h>
double squaredsum(double *l, int e) {
int i; double sum = 0.0; for(i = 0 ; i < e ; i++) sum += l[i]*l[i]; return sum;
}
int main() {
double list[6] = {3.0, 1.0, 4.0, 1.0, 5.0, 9.0}; printf("%lf\n", squaredsum(list, 6)); printf("%lf\n", squaredsum(list, 0)); /* the same without using a real list as if it were 0-element long */ printf("%lf\n", squaredsum(NULL, 0)); return 0;
}</lang>
C++
<lang cpp>#include <iostream>
- include <numeric>
- include <vector>
double add_square(double prev_sum, double new_val) {
return prev_sum + new_val*new_val;
}
double vec_add_squares(std::vector<double>& v) {
return std::accumulate(v.begin(), v.end(), 0.0, add_square);
}
int main() {
// first, show that for empty vectors we indeed get 0 std::vector<double> v; // empty std::cout << vec_add_squares(v) << std::endl;
// now, use some values double data[] = { 0, 1, 3, 1.5, 42, 0.1, -4 }; v.assign(data, data+7); std::cout << vec_add_squares(v) << std::endl; return 0;
}</lang>
Alternative version using
:
<lang cpp>#include <numeric>
- include <vector>
- include "boost/lambda/lambda.hpp"
double vec_add_squares(std::vector<double>& v) {
using namespace boost::lambda;
return std::accumulate(v.begin(), v.end(), 0.0, _1 + _2 * _2);
}</lang>
C#
<lang csharp>using System; using System.Collections.Generic; using System.Linq;
class Program {
static int sumsq(ICollection<int> i) { if (i == null || i.Count == 0) return 0; return i.Select(x => x * x).Sum(); }
static void Main() { int[] a = { 1, 2, 3, 4, 5 }; Console.WriteLine(sumsq(a)); // 55 }
}</lang>
Chef
<lang Chef>Sum of squares.
First input is length of vector, then rest of input is vector.
Ingredients. 1 g eggs 0 g bacon
Method. Put bacon into the 1st mixing bowl. Take eggs from refrigerator. Square the eggs. Take bacon from refrigerator. Put bacon into 2nd mixing bowl. Combine bacon into 2nd mixing bowl. Fold bacon into 2nd mixing bowl. Add the bacon into the 1st mixing bowl. Ask the eggs until squared. Pour contents of the 1st mixing bowl into the 1st baking dish.
Serves 1.
</lang>
Clojure
<lang clojure>(defn sum-of-squares [v]
(reduce #(+ %1 (* %2 %2)) 0 v))</lang>
CoffeeScript
<lang coffeescript> sumOfSquares = ( list ) ->
list.reduce (( sum, x ) -> sum + ( x * x )), 0
</lang>
Common Lisp
<lang lisp>(defun sum-of-squares (vector)
(loop for x across vector sum (expt x 2)))</lang>
D
Iterative Version
<lang d>T sumSquares(T)(T[] a) pure nothrow @safe @nogc {
T sum = 0; foreach (e; a) sum += e ^^ 2; return sum;
}
void main() {
import std.stdio: writeln;
[3.1, 1.0, 4.0, 1.0, 5.0, 9.0].sumSquares.writeln;
}</lang>
- Output:
133.61
Polymorphic Functional Style
<lang d>import std.stdio, std.algorithm, std.traits, std.range;
auto sumSquares(Range)(Range data) pure nothrow @safe @nogc {
return reduce!q{a + b ^^ 2}(ForeachType!Range(0), data);
}
void main() {
immutable items = [3.1, 1.0, 4.0, 1.0, 5.0, 9.0]; items.sumSquares.writeln; 10.iota.sumSquares.writeln;
}</lang>
- Output:
133.61 285
Dart
Iterative Version
<lang d>sumOfSquares(list) {
var sum=0; list.forEach((var n) { sum+=(n*n); }); return sum;
}
main() {
print(sumOfSquares([])); print(sumOfSquares([1,2,3])); print(sumOfSquares([10]));
}</lang>
- Output:
0 14 100
Functional Style Version
<lang d>num sumOfSquares(List<num> l) => l.map((num x)=>x*x) .fold(0, (num p,num n)=> p + n);
void main(){
print(sumOfSquares([])); print(sumOfSquares([1,2,3])); print(sumOfSquares([10]));
}</lang>
- Output:
0 14 100
Delphi
Delphi has standard SumOfSquares function in Math unit: <lang Delphi>program SumOfSq;
{$APPTYPE CONSOLE}
uses Math;
type
TDblArray = array of Double;
var
A: TDblArray;
begin
Writeln(SumOfSquares([]):6:2); // 0.00 Writeln(SumOfSquares([1, 2, 3, 4]):6:2); // 30.00 A:= nil; Writeln(SumOfSquares(A):6:2); // 0.00 A:= TDblArray.Create(1, 2, 3, 4); Writeln(SumOfSquares(A):6:2); // 30.00 Readln;
end.</lang>
E
<lang e>def sumOfSquares(numbers) {
var sum := 0 for x in numbers { sum += x**2 } return sum
}</lang>
Eiffel
<lang Eiffel> class APPLICATION
create make
feature -- Initialization
make local a: ARRAY [INTEGER] do a := <<1, -2, 3>> print ("%NSquare sum of <<1, 2, 3>>: " + sum_of_square (a).out)
a := <<>> print ("%NSquare sum of <<>>: " + sum_of_square (a).out) end
feature -- Access
sum_of_square (a: ITERABLE [INTEGER]): NATURAL -- sum of square of each items do Result := 0 across a as it loop Result := Result + (it.item * it.item).as_natural_32 end end
end </lang>
Elixir
<lang elixir>iex(1)> Enum.reduce([3,1,4,1,5,9], 0, fn x,sum -> sum + x*x end) 133</lang>
Emacs Lisp
<lang Emacs Lisp> (defun sum-square (ls)
(apply '+ (mapcar (lambda (k) (* k k) ) ls) ))
(insert (format "%d"(sum-square (number-sequence 0 3) ))) </lang> Output:
14
Erlang
<lang erlang>lists:foldl(fun(X, Sum) -> X*X + Sum end, 0, [3,1,4,1,5,9]).</lang>
Euphoria
<lang euphoria>function SumOfSquares(sequence v)
atom sum sum = 0 for i = 1 to length(v) do sum += v[i]*v[i] end for return sum
end function</lang>
Excel
To find the sum of squares of values from A1 to A10, type in any other cell :
<lang Excel> =SUMSQ(A1:A10) </lang>
The above expression will return zero if there are no values in any cell.
<lang> 12 3 5 23 13 67 15 9 4 2
5691 </lang>
Factor
<lang factor>USE: math sequences ;
- sum-of-squares ( seq -- n ) [ sq ] map-sum ;
{ 1.0 2.0 4.0 8.0 16.0 } sum-of-squares</lang>
FALSE
<lang FALSE> 0 3 1 4 1 5 9$*\ [$0=~][$*+\]#%. </lang>
Fantom
<lang fantom> class SumSquares {
static Int sumSquares (Int[] numbers) { Int sum := 0 numbers.each |n| { sum += n * n } return sum }
public static Void main () { Int[] n := [,] echo ("Sum of squares of $n = ${sumSquares(n)}") n = [1,2,3,4,5] echo ("Sum of squares of $n = ${sumSquares(n)}") }
} </lang>
Fish
<lang Fish>v \0& >l?!v:*&+&
>&n;</lang>
Forth
<lang forth>: fsum**2 ( addr n -- f )
0e dup 0= if 2drop exit then floats bounds do i f@ fdup f* f+ 1 floats +loop ;
create test 3e f, 1e f, 4e f, 1e f, 5e f, 9e f, test 6 fsum**2 f. \ 133.</lang>
Fortran
In ISO Fortran 90 orlater, use SUM intrinsic and implicit element-wise array arithmetic: <lang fortran>real, dimension(1000) :: a = (/ (i, i=1, 1000) /) real, pointer, dimension(:) :: p => a(2:1) ! pointer to zero-length array real :: result, zresult
result = sum(a*a) ! Multiply array by itself to get squares
result = sum(a**2) ! Use exponentiation operator to get squares
zresult = sum(p*p) ! P is zero-length; P*P is valid zero-length array expression; SUM(P*P) == 0.0 as expected</lang>
FreeBASIC
<lang freebasic>' FB 1.05.0 Win64
Function SumSquares(a() As Double) As Double
Dim As Integer length = UBound(a) - LBound(a) + 1 If length = 0 Then Return 0.0 Dim As Double sum = 0.0 For i As Integer = LBound(a) To UBound(a) sum += a(i) * a(i) Next Return sum
End Function
Dim a(5) As Double = {1.0, 2.0, 3.0, -1.0, -2.0, -3.0} Dim sum As Double = SumSquares(a()) Print "The sum of the squares is"; sum Print Print "Press any key to quit" Sleep</lang>
- Output:
The sum of the squares is 28
Frink
<lang frink> f = {|x| x^2} // Anonymous function which squares its argument a = [1,2,3,5,7] println[sum[map[f,a], 0]] </lang>
F#
<lang fsharp>[1 .. 10] |> List.fold (fun a x -> a + x * x) 0 [|1 .. 10|] |> Array.fold (fun a x -> a + x * x) 0</lang>
GAP
<lang gap># Just multiplying a vector by itself yields the sum of squares (it's an inner product)
- It's necessary to check for the empty vector though
SumSq := function(v) if Size(v) = 0 then return 0; else return v*v; fi; end;</lang>
GEORGE
<lang GEORGE>read (n) print ; 0 1, n rep (i)
read print dup mult + ]
print</lang> data
11 8 12 15 6 25 19 33 27 3 37 4
results:
1.100000000000000E+0001 << number of values (11) 8.000000000000000 << 11 data 1.200000000000000E+0001 1.500000000000000E+0001 6.000000000000000 2.500000000000000E+0001 1.900000000000000E+0001 3.300000000000000E+0001 2.700000000000000E+0001 3.000000000000000 3.700000000000000E+0001 4.000000000000000 4.667000000000000E+0003 << sum of squares
Go
- Implementation
<lang go>package main
import "fmt"
var v = []float32{1, 2, .5}
func main() {
var sum float32 for _, x := range v { sum += x * x } fmt.Println(sum)
}</lang>
- Output:
5.25
- Library
<lang go>package main
import (
"fmt"
"github.com/gonum/floats"
)
var v = []float64{1, 2, .5}
func main() {
fmt.Println(floats.Dot(v, v))
}</lang>
- Output:
5.25
Golfscript
<lang golfscript>{0\{.*+}%}:sqsum;
- usage example
[1 2 3]sqsum puts</lang>
Groovy
<lang groovy>def array = 1..3
// square via multiplication def sumSq = array.collect { it * it }.sum() println sumSq
// square via exponentiation sumSq = array.collect { it ** 2 }.sum()
println sumSq</lang>
- Output:
14 14
Haskell
<lang haskell>sumOfSquares = sum . map (^ 2)
> sumOfSquares [3,1,4,1,5,9] 133</lang>
IDL
<lang idl>print,total(array^2)</lang>
Icon and Unicon
<lang icon>procedure main()
local lst lst := [] #Construct a simple list and pass it to getsum every put(lst,seq()\2) write(getsum(lst))
end
procedure getsum(lst)
local total total := 0 every total +:= !lst ^ 2 return total
end</lang>
Inform 7
<lang inform7>Sum Of Squares is a room.
To decide which number is the sum of (N - number) and (M - number) (this is summing): decide on N + M.
To decide which number is (N - number) squared (this is squaring): decide on N * N.
To decide which number is the sum of squares of (L - list of numbers): decide on the summing reduction of squaring applied to L.
When play begins: say the sum of squares of {}; say line break; say the sum of squares of {1, 2, 3}; end the story.</lang>
Io
<lang io>list(3,1,4,1,5,9) map(squared) sum</lang>
J
<lang j>ss=: +/ @: *:</lang>
That is, sum composed with square. The verb also works on higher-ranked arrays. For example:
<lang j> ss 3 1 4 1 5 9 133
ss $0 NB. $0 is a zero-length vector
0
x=: 20 4 ?@$ 0 NB. a 20-by-4 table of random (0,1) numbers ss x
9.09516 5.19512 5.84173 6.6916</lang>
The computation can also be written as a loop. It is shown here for comparison only and is highly non-preferred compared to the version above.
<lang j>ss1=: 3 : 0
z=. 0 for_i. i.#y do. z=. z+*:i{y end.
)
ss1 3 1 4 1 5 9
133
ss1 $0
0
ss1 x
9.09516 5.19512 5.84173 6.6916</lang>
Java
<lang java5>public class SumSquares {
public static void main(final String[] args) { double sum = 0; int[] nums = {1,2,3,4,5}; for (int i : nums) sum += i * i; System.out.println("The sum of the squares is: " + sum); }
}</lang>
JavaScript
<lang javascript>function sumsq(array) {
var sum = 0; var i, iLen;
for (i = 0, iLen = array.length; i < iLen; i++) { sum += array[i] * array[i]; } return sum;
}
alert(sumsq([1,2,3,4,5])); // 55</lang>
An alternative using a while loop and Math.pow
<lang javascript>function sumsq(array) {
var sum = 0, i = array.length;
while (i--) sum += Math.pow(array[i], 2);
return sum;
}
alert(sumsq([1,2,3,4,5])); // 55</lang>
<lang javascript>Functional.reduce("x+y*y", 0, [1,2,3,4,5])</lang>
map (JS 1.6) and reduce (JS 1.8)
<lang javascript>[3,1,4,1,5,9].map(function (n) { return Math.pow(n,2); }).reduce(function (sum,n) { return sum+n; });</lang>
jq
jq supports both arrays and streams, and so we illustrate how to handle both. <lang jq># ss for an input array: def ss: map(.*.) | add;
- ss for a stream, S, without creating an intermediate array:
def ss(S): reduce S as $x (0; . + ($x * $x) );</lang>We can also use a generic "SIGMA" filter that behaves like the mathematical SIGMA:<lang jq>
- SIGMA(exp) computes the sum of exp over the input array:
def SIGMA(exp): map(exp) | add;
- SIGMA(exp; S) computes the sum of exp over elements of the stream, S,
- without creating an intermediate array:
def SIGMA(exp; S): reduce (S|exp) as $x (0; . + $x);</lang> Finally, a "mapreduce" filter:<lang jq> def mapreduce(mapper; reducer; zero):
if length == 0 then zero else map(mapper) | reducer end;
</lang> Demonstration:<lang jq>def demo(n):
"ss: \( [range(0;n)] | ss )", "ss(S): \( ss( range(0;n) ) )", "SIGMA(.*.): \( [range(0;n)] | SIGMA(.*.) )", "SIGMA(.*.;S): \( SIGMA( .*.; range(0;n) ) )", "mapreduce(.*.; add; 0): \( [range(0;n)] | mapreduce(.*.; add; 0) )"
demo(3) # 0^2 + 1^2 + 2^2</lang>
- Output:
<lang jq>"ss: 5" "ss(S): 5" "SIGMA(.*.): 5" "SIGMA(.*.;S): 5" "mapreduce(.*.; add; 0): 5"</lang>
Julia
There are several easy ways to do this in Julia: <lang julia>julia> sum([1,2,3,4,5].^2) 55
julia> sum([x^2 for x in [1,2,3,4,5]]) 55
julia> mapreduce(x->x^2,+,[1:5]) 55
julia> sum([x^2 for x in []]) 0</lang>
K
<lang k>
ss: {+/x*x} ss 1 2 3 4 5
55
ss@!0
0 </lang>
Lang5
<lang lang5>[1 2 3 4 5] 2 ** '+ reduce .</lang>
Lasso
<lang Lasso>define sumofsquares(values::array) => {
local(sum = 0)
with value in #values do { #sum += #value * #value }
return #sum }
sumofsquares(array(1,2,3,4,5))</lang>
- Output:
55
LFE
<lang lisp> (defun sum-sq (nums)
(lists:foldl (lambda (x acc) (+ acc (* x x))) 0 nums))
</lang>
Usage: <lang lisp> > (sum-sq '(3 1 4 1 5 9)) 133 </lang>
Liberty BASIC
<lang lb>' [RC] Sum of Squares
SourceList$ ="3 1 4 1 5 9" 'SourceList$ =""
' If saved as an array we'd have to have a flag for last data. ' LB has the very useful word$() to read from delimited strings. ' The default delimiter is a space character, " ".
SumOfSquares =0 n =0 data$ ="666" ' temporary dummy to enter the loop.
while data$ <>"" ' we loop until no data left. data$ =word$( SourceList$, n +1) ' first data, as a string NewVal =val( data$) ' convert string to number SumOfSquares =SumOfSquares +NewVal^2 ' add to existing sum of squares n =n +1 ' increment number of data items found wend
n =n -1
print "Supplied data was "; SourceList$ print "This contained "; n; " numbers." print "Sum of squares is "; SumOfSquares
end</lang>
LiveCode
<lang LiveCode>put "1,2,3,4,5" into nums repeat for each item n in nums
add (n * n) to m
end repeat put m // 55</lang>
Logo
<lang logo>print apply "sum map [? * ?] [1 2 3 4 5] ; 55</lang>
Logtalk
<lang logtalk>sum(List, Sum) :-
sum(List, 0, Sum).
sum([], Sum, Sum). sum([X| Xs], Acc, Sum) :-
Acc2 is Acc + X, sum(Xs, Acc2, Sum).</lang>
Lua
<lang lua>function squaresum(a, ...) return a and a^2 + squaresum(...) or 0 end function squaresumt(t) return squaresum(unpack(t)) end
print(squaresumt{3, 5, 4, 1, 7})</lang>
Maple
<lang Maple> F := V -> add(v^2, v in V): F(<1,2,3,4,5>); </lang>
Mathematica
As a function 1: <lang mathematica>SumOfSquares[x_]:=Total[x^2] SumOfSquares[{1,2,3,4,5}]</lang> As a function 2: <lang mathematica>SumOfSquares[x_]:=x.x SumOfSquares[{1,2,3,4,5}]</lang> Pure function 1: (postfix operator in the following examples) <lang mathematica>{1,2,3,4,5} // Total[#^2] &</lang> Pure function 2: <lang mathematica>{1, 2, 3, 4, 5} // #^2 & // Total</lang> Pure function 3: <lang mathematica>{1, 2, 3, 4, 5} // #.#&</lang>
MATLAB
<lang Matlab>function [squaredSum] = sumofsquares(inputVector)
squaredSum = sum( inputVector.^2 );</lang>
Maxima
<lang maxima>nums : [3,1,4,1,5,9]; sum(nums[i]^2,i,1,length(nums));</lang> or <lang maxima>nums : [3,1,4,1,5,9]; lsum(el^2, el, nums);</lang>
Mercury
<lang>
- - module sum_of_squares.
- - interface.
- - import_module io.
- - pred main(io::di, io::uo) is det.
- - implementation.
- - import_module int, list.
main(!IO) :-
io.write_int(sum_of_squares([3, 1, 4, 1, 5, 9]), !IO), io.nl(!IO).
- - func sum_of_squares(list(int)) = int.
sum_of_squares(Ns) = list.foldl((func(N, Acc) = Acc + N * N), Ns, 0). </lang>
МК-61/52
<lang>x^2 + С/П БП 00</lang>
Modula-3
<lang modula3>MODULE SumSquares EXPORTS Main;
IMPORT IO, Fmt;
TYPE RealArray = ARRAY OF REAL;
PROCEDURE SumOfSquares(x: RealArray): REAL =
VAR sum := 0.0; BEGIN FOR i := FIRST(x) TO LAST(x) DO sum := sum + x[i] * x[i]; END; RETURN sum; END SumOfSquares;
BEGIN
IO.Put(Fmt.Real(SumOfSquares(RealArray{3.0, 1.0, 4.0, 1.0, 5.0, 9.0}))); IO.Put("\n");
END SumSquares.</lang>
MOO
<lang moo>@verb #100:sum_squares this none this rd @program #100:sum_squares sum = 0; list = args[1]; for i in (list)
sum = sum + (i^2);
endfor player:tell(toliteral(list), " => ", sum); .
- Output:
- 100
- sum_squares({3,1,4,1,5,9})
{3, 1, 4, 1, 5, 9} => 133
- 100
- sum_squares({})
{} => 0 </lang>
MUMPS
<lang MUMPS>SUMSQUARE(X)
;X is assumed to be a list of numbers separated by "^" NEW RESULT,I SET RESULT=0,I=1 FOR QUIT:(I>$LENGTH(X,"^")) SET RESULT=($PIECE(X,"^",I)*$PIECE(X,"^",I))+RESULT,I=I+1 QUIT RESULT</lang>
Nemerle
<lang Nemerle>SS(x : list[double]) : double {
|[] => 0.0 |_ => x.Map(fun (x) {x*x}).FoldLeft(0.0, _+_)
}</lang>
NetRexx
<lang netrexx>/*NetRexx *************************************************************
- program to sum the squares of a vector of fifteen numbers.
- translated from REXX
- 14.05.2013 Walter Pachl
- /
numeric digits 50 /*allow 50-digit # (default is 9)*/ v='-100 9 8 7 6 0 3 4 5 2 1 .5 10 11 12' /* vector with some #s. */ n=v.words() x= sum=0 /*initialize SUM to zero. */
/*if vector is empty, sum = zero.*/
loop Until x= /*loop until list is exhausted */
Parse v x v /* pick next number */ If x> Then /* there is a number */ sum=sum + x**2 /*add its square to the sum. */ end
say "The sum of" n "elements for the V vector is:" sum</lang>
- Output:
The sum of 15 elements for the V vector is: 10650.25
NewLISP
<lang NewLISP>(apply + (map (fn(x) (* x x)) '(3 1 4 1 5 9))) -> 133 (apply + (map (fn(x) (* x x)) '())) -> 0</lang>
Nim
<lang nim>import math, sequtils
echo sum(map(@[1,2,3,4,5], proc (x: int): int = x*x))</lang>
Objeck
<lang objeck> bundle Default {
class Sum { function : native : SquaredSum(values : Float[]) ~ Float { sum := 0.0; for(i := 0 ; i < values->Size() ; i += 1;) { sum += (values[i] * values[i]); }; return sum; }
function : Main(args : String[]) ~ Nil { SquaredSum([3.0, 1.0, 4.0, 1.0, 5.0, 9.0])->PrintLine(); } }
} </lang>
OCaml
<lang ocaml>List.fold_left (fun sum a -> sum + a * a) 0 ints</lang>
<lang ocaml>List.fold_left (fun sum a -> sum +. a *. a) 0. floats</lang>
Oforth
<lang Oforth>#sq [1, 1.2, 3, 4.5 ] map sum</lang>
Octave
<lang octave>a = [1:10]; sumsq = sum(a .^ 2);</lang>
Order
<lang c>#include <order/interpreter.h>
ORDER_PP(8to_lit(
8seq_fold(8plus, 0, 8seq_map(8fn(8X, 8times(8X, 8X)), 8seq(3, 1, 4, 1, 5, 9)))
))</lang>
Oz
<lang oz>declare
fun {SumOfSquares Xs} for X in Xs sum:S do {S X*X} end end
in
{Show {SumOfSquares [3 1 4 1 5 9]}}</lang>
PARI/GP
<lang parigp>ss(v)={
sum(i=1,#v,v[i]^2)
};</lang>
Pascal
Example from the documenation of the run time library: <lang pascal>Program Example45;
{ Program to demonstrate the SumOfSquares function. }
Uses math;
Var
I : 1..100; ExArray : Array[1..100] of Float;
begin
Randomize; for I:=low(ExArray) to high(ExArray) do ExArray[i]:=(Random-Random)*100; Writeln('Max : ',MaxValue(ExArray):8:4); Writeln('Min : ',MinValue(ExArray):8:4); Writeln('Sum squares : ',SumOfSquares(ExArray):8:4); Writeln('Sum squares (b) : ',SumOfSquares(@ExArray[1],100):8:4);
end.</lang>
Perl
<lang perl>sub sum_of_squares {
my $sum = 0; $sum += $_**2 foreach @_; return $sum;
}
print sum_of_squares(3, 1, 4, 1, 5, 9), "\n";</lang> or <lang perl>use List::Util qw(reduce); sub sum_of_squares {
reduce { $a + $b **2 } 0, @_;
}
print sum_of_squares(3, 1, 4, 1, 5, 9), "\n";</lang>
Perl 6
<lang perl6>say [+] map * ** 2, 3, 1, 4, 1, 5, 9;</lang>
If this expression seems puzzling, note that * ** 2
is equivalent to {$^x ** 2}
— the leftmost asterisk is not the multiplication operator but the Whatever
star, which specifies currying behavior.
Another convenient way to distribute the exponentiation is via the cross metaoperator, which
as a list infix is looser than comma in precedence but tighter than the reduction list operator:
<lang perl6>say [+] 3,1,4,1,5,9 X** 2</lang>
Phix
<lang Phix>?sum(sq_power(tagset(10),2)) -- prints 385</lang>
PHP
<lang php> function sum_squares(array $args) {
return array_reduce( $args, create_function('$x, $y', 'return $x+$y*$y;'), 0 );
} </lang>
In PHP5.3 support for anonymous functions was reworked. While the above code would still work, it is suggested to use
<lang php> function sum_squares(array $args) {
return array_reduce($args, function($x, $y) { return $x+$y*$y; }, 0);
}
</lang>
Usage for both examples: sum_squares(array(1,2,3,4,5)); // 55
PicoLisp
<lang PicoLisp>: (sum '((N) (* N N)) (3 1 4 1 5 9)) -> 133
- (sum '((N) (* N N)) ())
-> 0</lang>
PL/I
<lang PL/I> declare A(10) float initial (10, 9, 8, 7, 6, 5, 4, 3, 2, 1);
put (sum(A**2)); </lang>
Pop11
<lang pop11>define sum_squares(v);
lvars s = 0, j; for j from 1 to length(v) do s + v(j)*v(j) -> s; endfor; s;
enddefine;
sum_squares({1 2 3 4 5}) =></lang>
PostScript
<lang> /sqrsum{ /x exch def /sum 0 def /i 0 def x length 0 eq {} { x length{ /sum sum x i get 2 exp add def /i i 1 add def }repeat }ifelse sum == }def </lang>
<lang postscript> [3 1 4 1 5 9] 0 {dup * +} fold </lang>
PowerShell
<lang powershell>function Get-SquareSum ($a) {
if ($a.Length -eq 0) { return 0 } else { $x = $a ` | ForEach-Object { $_ * $_ } ` | Measure-Object -Sum return $x.Sum }
}</lang>
PureBasic
<lang PureBasic>Procedure SumOfSquares(List base())
ForEach base() Sum + base()*base() Next ProcedureReturn Sum
EndProcedure</lang>
Python
<lang python>sum(x*x for x in [1, 2, 3, 4, 5])</lang>
Functional version: <lang python>sum(map(lambda x: x*x, [1, 2, 3, 4, 5]))</lang>
Functional version (using reduce): <lang python>def mySumSquare(n):
return reduce(lambda x,y : x + y, map(lambda x : x*x, range(n+1)))</lang>
Prolog
sum([],0). sum([H|T],S) :- sum(T, S1), S is S1 + (H * H).
R
<lang r>arr <- c(1,2,3,4,5) result <- sum(arr^2)</lang>
Racket
<lang racket>
- lang racket
(for/sum ([x #(3 1 4 1 5 9)]) (* x x)) </lang>
Raven
<lang Raven>define sumOfSqrs use $lst
0 $lst each dup * +
[ 1 2 3 4] sumOfSqrs "Sum of squares: %d\n" print</lang>
- Output:
Sum of squares: 30
REXX
input from pgm
<lang rexx>numeric digits 100 /*allow 100─digit numbers; default is 9*/ v= -100 9 8 7 6 0 3 4 5 2 1 .5 10 11 12 /*define a vector with fifteen numbers.*/
- =words(v) /*obtain number of words in the V list.*/
$= 0 /*initialize the sum ($) to zero. */
do k=1 for # /*process each number in the V vector. */ $=$ + word(v,k)**2 /*add a squared element to the ($) sum.*/ end /*k*/ /* [↑] if vector is empty, then sum=0.*/ /*stick a fork in it, we're all done. */
say 'The sum of ' # " squared elements for the V vector is: " $</lang> output using an internal vector (list) of numbers:
The sum of 15 squared elements for the V vector is: 10650.25
input from C.L.
<lang rexx>/*REXX program sums the squares of the numbers in a (numeric) vector of 15 numbers. */ numeric digits 100 /*allow 100─digit numbers; default is 9*/ parse arg v /*get optional numbers from the C.L. */ if v= then v= -100 9 8 7 6 0 3 4 5 2 1 .5 10 11 12 /*Not specified? Use default*/
- =words(v) /*obtain number of words in V*/
say 'The vector of ' # " elements is: " space(v) /*display the vector numbers.*/ $= 0 /*initialize the sum ($) to zero. */
do until v==; parse var v x v /*process each number in the V vector. */ $=$ + x**2 /*add a squared element to the ($) sum.*/ end /*until*/ /* [↑] if vector is empty, then sum=0.*/
say /*stick a fork in it, we're all done. */ say 'The sum of ' # " squared elements for the V vector is: " $</lang> output using a vector (list) of numbers from the command line:
The vector of 10 elements is: -1000 -100 -10 -1 0 +1 +10 100 1000 1e20 The sum of 10 squared elements for the V vector is: 10000000000000000000000000000000002020202
Ring
<lang ring> aList = [1,2,3,4,5] see sumOfSquares(aList)
func sumOfSquares sos sumOfSquares = 0 for i=1 to len(sos)
sumOfSquares = sumOfSquares + pow(sos[i],2)
next return sumOfSquares </lang>
Ruby
<lang ruby>[3,1,4,1,5,9].reduce(0){|sum,x| sum + x*x}</lang>
or
<lang ruby>[3,1,4,1,5,9].map{|x| x*x}.reduce :+</lang>
Run BASIC
<lang runbasic>list$ = "1,2,3,4,5" print sumOfSquares(list$)
FUNCTION sumOfSquares(sos$)
while word$(sos$,i+1,",") <> "" i = i + 1 sumOfSquares = sumOfSquares + val(word$(sos$,i,","))^2 wend
END FUNCTION</lang>
Rust
<lang rust>fn sq_sum(v: &[f64]) -> f64 {
v.iter().fold(0., |sum, &num| sum + num*num)
}
fn main() {
let v = vec![3.0, 1.0, 4.0, 1.0, 5.5, 9.7]; println!("{}", sq_sum(&v));
let u : Vec<f64> = vec![]; println!("{}", sq_sum(&u));
}</lang>
Sather
<lang sather>class MAIN is
sqsum(s, e:FLT):FLT is return s + e*e; end;
sum_of_squares(v :ARRAY{FLT}):FLT is return (#ARRAY{FLT}(|0.0|).append(v)).reduce(bind(sqsum(_,_))); end;
main is v :ARRAY{FLT} := |3.0, 1.0, 4.0, 1.0, 5.0, 9.0|; #OUT + sum_of_squares(v) + "\n"; end;
end;</lang>
Scala
Unfortunately there is no common "Numeric" class that Int and Double both extend, since Scala's number representation maps closely to Java's. Those concerned about precision can define a similar procedure for integers.
<lang scala>def sum_of_squares(xs: Seq[Double]) = xs.foldLeft(0) {(a,x) => a + x*x}</lang>
Scheme
<lang scheme>(define (sum-of-squares l)
(apply + (map * l l)))</lang>
> (sum-of-squares (list 3 1 4 1 5 9)) 133
Seed7
<lang seed7>$ include "seed7_05.s7i";
include "float.s7i";
const array float: list1 is [] (3.0, 1.0, 4.0, 1.0, 5.0, 9.0); const array float: list2 is 0 times 0.0;
const func float: squaredSum (in array float: floatList) is func
result var float: sum is 0.0; local var float: number is 0.0; begin for number range floatList do sum +:= number ** 2; end for; end func;
const proc: main is func
begin writeln(squaredSum(list1)); writeln(squaredSum(list2)); end func;</lang>
Sidef
<lang ruby>func sum_of_squares(vector) {
var sum = 0; vector.each { |n| sum += n**2 }; return sum;
}
say sum_of_squares([]); # 0 say sum_of_squares([1,2,3]); # 14</lang>
Slate
<lang slate>{1. 2. 3} reduce: [|:x :y| y squared + x]. {} reduce: [|:x :y| y squared + x] ifEmpty: [0].</lang>
Smalltalk
<lang smalltalk>#(3 1 4 1 5 9) inject: 0 into: [:sum :aNumber | sum + aNumber squared]</lang>
SNOBOL4
<lang SNOBOL4> define('ssq(a)i') :(ssq_end) ssq i = i + 1; ssq = ssq + (a * a) :s(sumsq)f(return) ssq_end
- # Fill array, test and display
str = '1 2 3 5 7 11 13 17 19 23'; a = array(10)
loop i = i + 1; str len(p) span('0123456789') . a @p :s(loop)
output = str ' -> ' sumsq(a)
end</lang>
- Output:
1 2 3 5 7 11 13 17 19 23 -> 1557
Standard ML
<lang sml>foldl (fn (a, sum) => sum + a * a) 0 ints</lang>
<lang sml>foldl (fn (a, sum) => sum + a * a) 0.0 reals</lang>
SQL
<lang sql>select sum(x*x) from vector</lang>
Note that this assumes that the values in our vector are named x
.
Swift
<lang swift>func sumSq(s: [Int]) -> Int {
return s.map{$0 * $0}.reduce(0, +)
}</lang>
Tcl
<lang tcl>proc sumOfSquares {nums} {
set sum 0 foreach num $nums { set sum [expr {$sum + $num**2}] } return $sum
} sumOfSquares {1 2 3 4 5} ;# ==> 55 sumOfSquares {} ;# ==> 0</lang>
<lang tcl>package require struct::list
proc square x {expr {$x * $x}} proc + {a b} {expr {$a + $b}} proc sumOfSquares {nums} {
struct::list fold [struct::list map $nums square] 0 +
} sumOfSquares {1 2 3 4 5} ;# ==> 55 sumOfSquares {} ;# ==> 0</lang> Generic "sum of function" <lang tcl>package require Tcl 8.5 package require struct::list namespace path ::tcl::mathop
proc sum_of {lambda nums} {
struct::list fold [struct::list map $nums [list apply $lambda]] 0 +
}
sum_of {x {* $x $x}} {1 2 3 4 5} ;# ==> 55</lang>
Trith
<lang trith>[3 1 4 1 5 9] 0 [dup * +] foldl</lang>
TUSCRIPT
<lang tuscript> $$ MODE TUSCRIPT array="3'1'4'1'5'9",sum=0 LOOP a=array sum=sum+(a*a) ENDLOOP PRINT sum </lang>
- Output:
133
UnixPipes
<lang bash>folder() {
(read B; res=$( expr $1 \* $1 ) ; test -n "$B" && expr $res + $B || echo $res)
}
fold() {
(while read a ; do fold | folder $a done)
}
(echo 3; echo 1; echo 4;echo 1;echo 5; echo 9) | fold</lang>
Ursala
The ssq function defined below zips two copies of its argument together, maps the product function to all pairs, and then sums the result by way of the reduction operator, -:. <lang Ursala>#import nat
ssq = sum:-0+ product*iip
- cast %n
main = ssq <21,12,77,0,94,23,96,93,72,72,79,24,8,50,9,93></lang>
- Output:
62223
V
<lang v>[sumsq [dup *] map 0 [+] fold].
[] sumsq =0 [1 2 3] sumsq</lang>
=14
VBScript
<lang vb> Function sum_of_squares(arr) If UBound(arr) = -1 Then sum_of_squares = 0 End If For i = 0 To UBound(arr) sum_of_squares = sum_of_squares + (arr(i)^2) Next End Function
WScript.StdOut.WriteLine sum_of_squares(Array(1,2,3,4,5)) WScript.StdOut.WriteLine sum_of_squares(Array()) </lang>
- Output:
55 0
Visual Basic .NET
<lang vbnet>
Private Shared Function sumsq(ByVal i As ICollection(Of Integer)) As Integer If i Is Nothing OrElse i.Count = 0 Then Return 0 End If Return i.[Select](Function(x) x * x).Sum() End Function
Private Shared Sub Main() Dim a As Integer() = New Integer() {1, 2, 3, 4, 5} ' 55 Console.WriteLine(sumsq(a)) For K As Integer = 0 To 16 Console.WriteLine("SumOfSquares({0}) = {1}", K, SumOfSquares(K)) Next End Sub Function SumOfSquares(ByVal Max As Integer) Dim Square As Integer = 0 Dim Add As Integer = 1 Dim Sum As Integer = 0 For J As Integer = 0 To Max - 1 Square += Add Add += 2 Sum += Square Next Return Sum End Function
Function SumOfSquaresByMult(ByVal Max As Integer) Dim Sum As Integer = 0 For J As Integer = 1 To Max Sum += J * J Next Return Sum End Function
</lang>
- Output:
55 SumOfSquares(0) = 0 SumOfSquares(1) = 1 SumOfSquares(2) = 5 SumOfSquares(3) = 14 SumOfSquares(4) = 30 SumOfSquares(5) = 55 SumOfSquares(6) = 91 SumOfSquares(7) = 140 SumOfSquares(8) = 204 SumOfSquares(9) = 285 SumOfSquares(10) = 385 SumOfSquares(11) = 506 SumOfSquares(12) = 650 SumOfSquares(13) = 819 SumOfSquares(14) = 1015 SumOfSquares(15) = 1240 SumOfSquares(16) = 1496
Wortel
<lang wortel>@sum !*^@sq [3 1 4 1 5 9] ; returns 133</lang> <lang wortel>@sum !*^@sq [] ; returns 0</lang> As a function: <lang wortel>^(@sum *^@sq)</lang> Iterative function: <lang wortel>&a [@var sum 0 @for x of a :!+sum *x x sum]</lang>
XLISP
The task specification calls for a function that takes a numeric vector. If you want a function that takes a linked list (which would be more idiomatic), just extract the inner function SUMSQ and use that instead of SUM-OF-SQUARES. <lang lisp>(defun sum-of-squares (vec)
(defun sumsq (xs) (if (null xs) 0 (+ (expt (car xs) 2) (sumsq (cdr xs))))) (sumsq (vector->list vec)))
(define first-seven-primes #(2 3 5 7 11 13 17))
(define zero-length-vector #())
(print `(the sum of the squares of the first seven prime numbers is ,(sum-of-squares first-seven-primes)))
(print `(the sum of the squares of no numbers at all is ,(sum-of-squares zero-length-vector)))</lang>
- Output:
(THE SUM OF THE SQUARES OF THE FIRST SEVEN PRIME NUMBERS IS 666) (THE SUM OF THE SQUARES OF NO NUMBERS AT ALL IS 0)
XPL0
<lang XPL0>include c:\cxpl\codes; \intrinsic 'code' declarations
func SumSq(V, L); int V, L; int S, I; [S:= 0; for I:= 0 to L-1 do S:= S+sq(V(I)); return S; ]; \SumSq
[IntOut(0, SumSq([1,2,3,4,5,6,7,8,9,10], 10)); CrLf(0);
IntOut(0, SumSq([0], 0)); CrLf(0); \zero-length vector "[]" doesn't compile
]</lang>
- Output:
385 0
zkl
<lang zkl>T(3,1,4,1,5,9).reduce(fcn(p,n){p+n*n},0) //-->55 T().reduce(fcn(p,n){p+n*n},0) //-->0 T(3,1,4,1,5,9).reduce(fcn(p,n){p+n*n},0.0) //-->133.0</lang>
- Programming Tasks
- Arithmetic operations
- 0815
- 360 Assembly
- ACL2
- ActionScript
- Ada
- Aime
- ALGOL 68
- ALGOL W
- Alore
- APL
- AutoHotkey
- AWK
- BASIC
- BBC BASIC
- Bc
- Bracmat
- Brat
- C
- C++
- Boost.Lambda
- C sharp
- Chef
- Clojure
- CoffeeScript
- Common Lisp
- D
- Dart
- Delphi
- E
- Eiffel
- Elixir
- Emacs Lisp
- Erlang
- Euphoria
- Excel
- Factor
- FALSE
- Fantom
- Fish
- Forth
- Fortran
- FreeBASIC
- Frink
- F Sharp
- GAP
- GEORGE
- Go
- Golfscript
- Groovy
- Haskell
- IDL
- Icon
- Unicon
- Inform 7
- Io
- J
- Java
- JavaScript
- Functional
- Jq
- Julia
- K
- Lang5
- Lasso
- LFE
- Liberty BASIC
- LiveCode
- Logo
- Logtalk
- Lua
- Maple
- Mathematica
- MATLAB
- Maxima
- Mercury
- МК-61/52
- Modula-3
- MOO
- MUMPS
- Nemerle
- NetRexx
- NewLISP
- Nim
- Objeck
- OCaml
- Oforth
- Octave
- Order
- Oz
- PARI/GP
- Pascal
- Math
- Perl
- Perl 6
- Phix
- PHP
- PicoLisp
- PL/I
- Pop11
- PostScript
- Initlib
- PowerShell
- PureBasic
- Python
- Prolog
- R
- Racket
- Raven
- REXX
- Ring
- Ruby
- Run BASIC
- Rust
- Sather
- Scala
- Scheme
- Seed7
- Sidef
- Slate
- Smalltalk
- SNOBOL4
- Standard ML
- SQL
- Swift
- Tcl
- Tcllib
- Trith
- TUSCRIPT
- UnixPipes
- Ursala
- V
- VBScript
- Visual Basic .NET
- Wortel
- XLISP
- XPL0
- Zkl