Averages/Root mean square: Difference between revisions
Content added Content deleted
(→{{header|Vlang}}: Rename "Vlang" in "V (Vlang)") |
(→{{header|AppleScript}}: Added straightforward solution and loopless integer range alternative.) |
||
Line 226: | Line 226: | ||
=={{header|AppleScript}}== |
=={{header|AppleScript}}== |
||
===Functional=== |
|||
{{Trans|JavaScript}}( ES6 version ) |
{{Trans|JavaScript}}( ES6 version ) |
||
<syntaxhighlight lang="applescript">-- rootMeanSquare :: [Num] -> Real |
<syntaxhighlight lang="applescript">-- rootMeanSquare :: [Num] -> Real |
||
Line 275: | Line 276: | ||
{{Out}} |
{{Out}} |
||
<pre>6.204836822995</pre> |
<pre>6.204836822995</pre> |
||
---- |
|||
===Straightforward=== |
|||
<syntaxhighlight lang="applescript">on rootMeanSquare(listOfNumbers) |
|||
script o |
|||
property lst : listOfNumbers |
|||
end script |
|||
set r to 0.0 |
|||
repeat with n in o's lst |
|||
set r to r + (n ^ 2) |
|||
end repeat |
|||
return (r / (count o's lst)) ^ 0.5 |
|||
end rootMeanSquare |
|||
rootMeanSquare({1, 2, 3, 4, 5, 6, 7, 8, 9, 10})</syntaxhighlight> |
|||
{{output}} |
|||
<syntaxhighlight lang="applescript">6.204836822995</syntaxhighlight> |
|||
===Integer range alternative=== |
|||
{{Trans|AutoHotKey}} '''("Avoiding a loop" solution)''' |
|||
<syntaxhighlight lang="applescript"> |
|||
-- RMS of integer range a to b. |
|||
on rootMeanSquare(a, b) |
|||
return ((b * (b + 1) * (2 * b + 1) - a * (a - 1) * (2 * a - 1)) / 6 / (b - a + 1)) ^ 0.5 |
|||
end rootMeanSquare |
|||
rootMeanSquare(1, 10)</syntaxhighlight> |
|||
{{output}} |
|||
<syntaxhighlight lang="applescript">6.204836822995</syntaxhighlight> |
|||
=={{header|Arturo}}== |
=={{header|Arturo}}== |