task_url
stringlengths
30
116
task_name
stringlengths
2
86
task_description
stringlengths
0
14.4k
language_url
stringlengths
2
53
language_name
stringlengths
1
52
code
stringlengths
0
61.9k
http://rosettacode.org/wiki/Averages/Root_mean_square
Averages/Root mean square
Task[edit] Compute the   Root mean square   of the numbers 1..10. The   root mean square   is also known by its initials RMS (or rms), and as the quadratic mean. The RMS is calculated as the mean of the squares of the numbers, square-rooted: x r m s = x 1 2 + x 2 2 + ⋯ + x n 2 n . {\displaystyle x_{\mathrm {rms} }={\sqrt {{{x_{1}}^{2}+{x_{2}}^{2}+\cdots +{x_{n}}^{2}} \over n}}.} See also Tasks for calculating statistical measures in one go moving (sliding window) moving (cumulative) Mean Arithmetic Statistics/Basic Averages/Arithmetic mean Averages/Pythagorean means Averages/Simple moving average Geometric Averages/Pythagorean means Harmonic Averages/Pythagorean means Quadratic Averages/Root mean square Circular Averages/Mean angle Averages/Mean time of day Median Averages/Median Mode Averages/Mode Standard deviation Statistics/Basic Cumulative standard deviation
#Common_Lisp
Common Lisp
(loop for x from 1 to 10 for xx = (* x x) for n from 1 summing xx into xx-sum finally (return (sqrt (/ xx-sum n))))
http://rosettacode.org/wiki/Base64_decode_data
Base64 decode data
See Base64 encode data. Now write a program that takes the output of the Base64 encode data task as input and regenerate the original file. When working on the VBA implementation I found several 'solutions' on the net, including one from the software maker himself, that showed output with incorrect padding. Obviously with incorrect padding in the output you can not decode correctly to the original file again.
#Raku
Raku
my $e64 = ' VG8gZXJyIGlzIGh1bWFuLCBidXQgdG8gcmVhbGx5IGZvdWwgdGhpbmdzIHVwIHlvdSBuZWVkIGEgY2 9tcHV0ZXIuCiAgICAtLSBQYXVsIFIuIEVocmxpY2g= ';   my @base64map = flat 'A' .. 'Z', 'a' .. 'z', ^10, '+', '/'; my %base64 is default(0) = @base64map.pairs.invert;   sub base64-decode-slow ($enc) { my $buf = Buf.new; for $enc.subst(/\s/, '', :g).comb(4) -> $chunck { $buf.append: |(sprintf "%06d%06d%06d%06d", |$chunck.comb.map: {%base64{$_}.base(2)}).comb(8).map: {:2($_)}; } $buf }   say 'Slow:'; say base64-decode-slow($e64).decode('utf8');     # Of course, the above routine is slow and is only for demonstration purposes. # For real code you should use a module, which is MUCH faster and heavily tested. say "\nFast:"; use Base64::Native; say base64-decode($e64).decode('utf8');
http://rosettacode.org/wiki/Averages/Root_mean_square
Averages/Root mean square
Task[edit] Compute the   Root mean square   of the numbers 1..10. The   root mean square   is also known by its initials RMS (or rms), and as the quadratic mean. The RMS is calculated as the mean of the squares of the numbers, square-rooted: x r m s = x 1 2 + x 2 2 + ⋯ + x n 2 n . {\displaystyle x_{\mathrm {rms} }={\sqrt {{{x_{1}}^{2}+{x_{2}}^{2}+\cdots +{x_{n}}^{2}} \over n}}.} See also Tasks for calculating statistical measures in one go moving (sliding window) moving (cumulative) Mean Arithmetic Statistics/Basic Averages/Arithmetic mean Averages/Pythagorean means Averages/Simple moving average Geometric Averages/Pythagorean means Harmonic Averages/Pythagorean means Quadratic Averages/Root mean square Circular Averages/Mean angle Averages/Mean time of day Median Averages/Median Mode Averages/Mode Standard deviation Statistics/Basic Cumulative standard deviation
#Crystal
Crystal
def rms(seq) Math.sqrt(seq.sum { |x| x*x } / seq.size) end   puts rms (1..10).to_a
http://rosettacode.org/wiki/Averages/Root_mean_square
Averages/Root mean square
Task[edit] Compute the   Root mean square   of the numbers 1..10. The   root mean square   is also known by its initials RMS (or rms), and as the quadratic mean. The RMS is calculated as the mean of the squares of the numbers, square-rooted: x r m s = x 1 2 + x 2 2 + ⋯ + x n 2 n . {\displaystyle x_{\mathrm {rms} }={\sqrt {{{x_{1}}^{2}+{x_{2}}^{2}+\cdots +{x_{n}}^{2}} \over n}}.} See also Tasks for calculating statistical measures in one go moving (sliding window) moving (cumulative) Mean Arithmetic Statistics/Basic Averages/Arithmetic mean Averages/Pythagorean means Averages/Simple moving average Geometric Averages/Pythagorean means Harmonic Averages/Pythagorean means Quadratic Averages/Root mean square Circular Averages/Mean angle Averages/Mean time of day Median Averages/Median Mode Averages/Mode Standard deviation Statistics/Basic Cumulative standard deviation
#D
D
import std.stdio, std.math, std.algorithm, std.range;   real rms(R)(R d) pure { return sqrt(d.reduce!((a, b) => a + b * b) / real(d.length)); }   void main() { writefln("%.19f", iota(1, 11).rms); }
http://rosettacode.org/wiki/Base64_decode_data
Base64 decode data
See Base64 encode data. Now write a program that takes the output of the Base64 encode data task as input and regenerate the original file. When working on the VBA implementation I found several 'solutions' on the net, including one from the software maker himself, that showed output with incorrect padding. Obviously with incorrect padding in the output you can not decode correctly to the original file again.
#Red
Red
Red [Source: https://github.com/vazub/rosetta-red]   print to-string debase "VG8gZXJyIGlzIGh1bWFuLCBidXQgdG8gcmVhbGx5IGZvdWwgdGhpbmdzIHVwIHlvdSBuZWVkIGEgY29tcHV0ZXIuCiAgICAtLVBhdWwgUi5FaHJsaWNo"  
http://rosettacode.org/wiki/Base64_decode_data
Base64 decode data
See Base64 encode data. Now write a program that takes the output of the Base64 encode data task as input and regenerate the original file. When working on the VBA implementation I found several 'solutions' on the net, including one from the software maker himself, that showed output with incorrect padding. Obviously with incorrect padding in the output you can not decode correctly to the original file again.
#Ring
Ring
  #======================================# # Sample: Base64 decode data # Author: Gal Zsolt, Mansour Ayouni #======================================#   load "guilib.ring"   oQByteArray = new QByteArray() oQByteArray.append("Rosetta Code Base64 decode data task") oba = oQByteArray.toBase64().data() see oba + nl   oQByteArray = new QByteArray() oQByteArray.append(oba) see oQByteArray.fromBase64(oQByteArray).data()  
http://rosettacode.org/wiki/Base64_decode_data
Base64 decode data
See Base64 encode data. Now write a program that takes the output of the Base64 encode data task as input and regenerate the original file. When working on the VBA implementation I found several 'solutions' on the net, including one from the software maker himself, that showed output with incorrect padding. Obviously with incorrect padding in the output you can not decode correctly to the original file again.
#Ruby
Ruby
require 'base64'   raku_example =' VG8gZXJyIGlzIGh1bWFuLCBidXQgdG8gcmVhbGx5IGZvdWwgdGhpbmdzIHVwIHlvdSBuZWVkIGEgY2 9tcHV0ZXIuCiAgICAtLSBQYXVsIFIuIEVocmxpY2g= ' puts Base64.decode64 raku_example
http://rosettacode.org/wiki/Averages/Root_mean_square
Averages/Root mean square
Task[edit] Compute the   Root mean square   of the numbers 1..10. The   root mean square   is also known by its initials RMS (or rms), and as the quadratic mean. The RMS is calculated as the mean of the squares of the numbers, square-rooted: x r m s = x 1 2 + x 2 2 + ⋯ + x n 2 n . {\displaystyle x_{\mathrm {rms} }={\sqrt {{{x_{1}}^{2}+{x_{2}}^{2}+\cdots +{x_{n}}^{2}} \over n}}.} See also Tasks for calculating statistical measures in one go moving (sliding window) moving (cumulative) Mean Arithmetic Statistics/Basic Averages/Arithmetic mean Averages/Pythagorean means Averages/Simple moving average Geometric Averages/Pythagorean means Harmonic Averages/Pythagorean means Quadratic Averages/Root mean square Circular Averages/Mean angle Averages/Mean time of day Median Averages/Median Mode Averages/Mode Standard deviation Statistics/Basic Cumulative standard deviation
#Delphi.2FPascal
Delphi/Pascal
program AveragesMeanSquare;   {$APPTYPE CONSOLE}   uses Types;   function MeanSquare(aArray: TDoubleDynArray): Double; var lValue: Double; begin Result := 0;   for lValue in aArray do Result := Result + (lValue * lValue); if Result > 0 then Result := Sqrt(Result / Length(aArray)); end;   begin Writeln(MeanSquare(TDoubleDynArray.Create())); Writeln(MeanSquare(TDoubleDynArray.Create(1,2,3,4,5,6,7,8,9,10))); end.
http://rosettacode.org/wiki/Base64_decode_data
Base64 decode data
See Base64 encode data. Now write a program that takes the output of the Base64 encode data task as input and regenerate the original file. When working on the VBA implementation I found several 'solutions' on the net, including one from the software maker himself, that showed output with incorrect padding. Obviously with incorrect padding in the output you can not decode correctly to the original file again.
#Rust
Rust
use std::str;   const INPUT: &str = "VG8gZXJyIGlzIGh1bWFuLCBidXQgdG8gcmVhbGx5IGZvdWwgdGhpbmdzIHVwIHlvdSBuZWVkIGEgY29tcHV0ZXIuCiAgICAtLVBhdWwgUi5FaHJsaWNo"; const UPPERCASE_OFFSET: i8 = -65; const LOWERCASE_OFFSET: i8 = 26 - 97; const NUM_OFFSET: i8 = 52 - 48;   fn main() { println!("Input: {}", INPUT);   let result = INPUT.chars() .filter(|&ch| ch != '=') //Filter '=' chars .map(|ch| { //Map char values using Base64 Characters Table let ascii = ch as i8; let convert = match ch { '0' ... '9' => ascii + NUM_OFFSET, 'a' ... 'z' => ascii + LOWERCASE_OFFSET, 'A' ... 'Z' => ascii + UPPERCASE_OFFSET, '+' => 62, '/' => 63, _ => panic!("Not a valid base64 encoded string") }; format!("{:#08b}", convert)[2..].to_string() //convert indices to binary format and remove the two first digits }) .collect::<String>() //concatenate the resulting binary values .chars() .collect::<Vec<char>>() .chunks(8) //split into 8 character chunks .map(|chunk| { let num_str = chunk.iter().collect::<String>(); usize::from_str_radix(&num_str, 2).unwrap() as u8 //convert the binary string into its u8 value }) .collect::<Vec<_>>();   let result = str::from_utf8(&result).unwrap(); //convert into UTF-8 string   println!("Output: {}", result); }
http://rosettacode.org/wiki/Base64_decode_data
Base64 decode data
See Base64 encode data. Now write a program that takes the output of the Base64 encode data task as input and regenerate the original file. When working on the VBA implementation I found several 'solutions' on the net, including one from the software maker himself, that showed output with incorrect padding. Obviously with incorrect padding in the output you can not decode correctly to the original file again.
#Scala
Scala
import java.util.Base64   object Base64Decode extends App {   def text2BinaryDecoding(encoded: String): String = { val decoded = Base64.getDecoder.decode(encoded) new String(decoded, "UTF-8") }   def data = "VG8gZXJyIGlzIGh1bWFuLCBidXQgdG8gcmVhbGx5IGZvdWwgdGhpbmdzIHVwIHlvdSBuZWVkIGEgY29tcHV0ZXIuCiAgICAtLSBQYXVsIFIuIEVocmxpY2g="   println(text2BinaryDecoding(data)) }
http://rosettacode.org/wiki/Barnsley_fern
Barnsley fern
A Barnsley fern is a fractal named after British mathematician Michael Barnsley and can be created using an iterated function system (IFS). Task Create this fractal fern, using the following transformations: ƒ1   (chosen 1% of the time) xn + 1 = 0 yn + 1 = 0.16 yn ƒ2   (chosen 85% of the time) xn + 1 = 0.85 xn + 0.04 yn yn + 1 = −0.04 xn + 0.85 yn + 1.6 ƒ3   (chosen 7% of the time) xn + 1 = 0.2 xn − 0.26 yn yn + 1 = 0.23 xn + 0.22 yn + 1.6 ƒ4   (chosen 7% of the time) xn + 1 = −0.15 xn + 0.28 yn yn + 1 = 0.26 xn + 0.24 yn + 0.44. Starting position: x = 0, y = 0
#Action.21
Action!
INCLUDE "H6:REALMATH.ACT"   BYTE CH=$02FC,COLOR1=$02C5,COLOR2=$02C6 REAL r0,r4,r15,r16,r20,r22,r23,r24,r26,r28,r44,r85,r160   PROC Init() ValR("0",r0) ValR("0.04",r4) ValR("0.15",r16) ValR("0.16",r16) ValR("0.2",r20) ValR("0.22",r22) ValR("0.23",r23) ValR("0.24",r24) ValR("0.26",r26) ValR("0.28",r28) ValR("0.44",r44) ValR("0.85",r85) ValR("1.6",r160) RETURN   PROC Fern(REAL POINTER scale) BYTE r REAL x,y,xp,yp,tmp1,tmp2 INT i,ix,iy   RealAssign(r0,x) RealAssign(r0,y)   DO RealMult(x,scale,tmp1) RealMult(y,scale,tmp2) ix=Round(tmp2) ;fern is rotated to fit the screen size iy=Round(tmp1)+85   IF (ix>=0) AND (ix<=319) AND (iy>=0) AND (iy<=191) THEN Plot(ix,iy) FI r=Rand(100) RealAssign(x,xp) ;xp=x RealAssign(y,yp) ;yp=y IF r<1 THEN RealAssign(r0,x)  ;x=0 RealMult(r16,yp,y) ;y=0.16*yp ELSEIF r<86 THEN RealMult(r85,xp,tmp1) ;tmp1=0.85*xp RealMult(r4,yp,tmp2)  ;tmp2=0.4*yp RealAdd(tmp1,tmp2,x)  ;x=0.85*xp+0.4*yp   RealMult(r4,xp,tmp1)  ;tmp1=0.04*xp RealSub(r160,tmp1,tmp2) ;tmp2=-0.04*xp+1.6 RealMult(r85,yp,tmp1)  ;tmp1=0.85*yp RealAdd(tmp1,tmp2,y)  ;y=-0.04*xp+0.85*yp+1.6 ELSEIF r<93 THEN RealMult(r20,xp,tmp1) ;tmp1=0.2*xp RealMult(r26,yp,tmp2) ;tmp2=0.26*yp RealSub(tmp1,tmp2,x)  ;x=0.2*xp-0.26*yp   RealMult(r23,xp,tmp1)  ;tmp1=0.23*xp RealAdd(r160,tmp1,tmp2) ;tmp2=0.23*xp+1.6 RealMult(r22,yp,tmp1)  ;tmp1=0.22*yp RealAdd(tmp1,tmp2,y)  ;y=0.23*xp+0.22*yp+1.6 ELSE RealMult(r15,xp,tmp1) ;tmp1=0.15*xp RealMult(r28,yp,tmp2) ;tmp2=0.28*yp RealSub(tmp2,tmp1,x)  ;x=-0.15*xp+0.28*yp   RealMult(r26,xp,tmp1)  ;tmp1=0.26*xp RealAdd(r44,tmp1,tmp2) ;tmp2=0.26*xp+0.44 RealMult(r24,yp,tmp1)  ;tmp1=0.24*yp RealAdd(tmp1,tmp2,y)  ;y=0.26*xp+0.44*yp+0.44 FI   Poke(77,0) ;turn off the attract mode UNTIL CH#$FF ;until key pressed OD CH=$FF RETURN   PROC Main() REAL scale   Graphics(8+16) Color=1 COLOR1=$BA COLOR2=$B2   Init() ValR("30",scale) Fern(scale) RETURN
http://rosettacode.org/wiki/Averages/Root_mean_square
Averages/Root mean square
Task[edit] Compute the   Root mean square   of the numbers 1..10. The   root mean square   is also known by its initials RMS (or rms), and as the quadratic mean. The RMS is calculated as the mean of the squares of the numbers, square-rooted: x r m s = x 1 2 + x 2 2 + ⋯ + x n 2 n . {\displaystyle x_{\mathrm {rms} }={\sqrt {{{x_{1}}^{2}+{x_{2}}^{2}+\cdots +{x_{n}}^{2}} \over n}}.} See also Tasks for calculating statistical measures in one go moving (sliding window) moving (cumulative) Mean Arithmetic Statistics/Basic Averages/Arithmetic mean Averages/Pythagorean means Averages/Simple moving average Geometric Averages/Pythagorean means Harmonic Averages/Pythagorean means Quadratic Averages/Root mean square Circular Averages/Mean angle Averages/Mean time of day Median Averages/Median Mode Averages/Mode Standard deviation Statistics/Basic Cumulative standard deviation
#E
E
def makeMean(base, include, finish) { return def mean(numbers) { var count := 0 var acc := base for x in numbers { acc := include(acc, x) count += 1 } return finish(acc, count) } }   def RMS := makeMean(0, fn b,x { b+x**2 }, fn acc,n { (acc/n).sqrt() })
http://rosettacode.org/wiki/Averages/Root_mean_square
Averages/Root mean square
Task[edit] Compute the   Root mean square   of the numbers 1..10. The   root mean square   is also known by its initials RMS (or rms), and as the quadratic mean. The RMS is calculated as the mean of the squares of the numbers, square-rooted: x r m s = x 1 2 + x 2 2 + ⋯ + x n 2 n . {\displaystyle x_{\mathrm {rms} }={\sqrt {{{x_{1}}^{2}+{x_{2}}^{2}+\cdots +{x_{n}}^{2}} \over n}}.} See also Tasks for calculating statistical measures in one go moving (sliding window) moving (cumulative) Mean Arithmetic Statistics/Basic Averages/Arithmetic mean Averages/Pythagorean means Averages/Simple moving average Geometric Averages/Pythagorean means Harmonic Averages/Pythagorean means Quadratic Averages/Root mean square Circular Averages/Mean angle Averages/Mean time of day Median Averages/Median Mode Averages/Mode Standard deviation Statistics/Basic Cumulative standard deviation
#EchoLisp
EchoLisp
  (define (rms xs) (sqrt (// (for/sum ((x xs)) (* x x)) (length xs))))   (rms (range 1 11)) → 6.2048368229954285  
http://rosettacode.org/wiki/Base64_decode_data
Base64 decode data
See Base64 encode data. Now write a program that takes the output of the Base64 encode data task as input and regenerate the original file. When working on the VBA implementation I found several 'solutions' on the net, including one from the software maker himself, that showed output with incorrect padding. Obviously with incorrect padding in the output you can not decode correctly to the original file again.
#Seed7
Seed7
$ include "seed7_05.s7i"; include "gethttp.s7i"; include "encoding.s7i";   const proc: main is func local var string: original is ""; var string: encoded is ""; begin original := getHttp("rosettacode.org/favicon.ico"); encoded := toBase64(original); writeln("Is the Rosetta Code icon the same (byte for byte) encoded then decoded: " <& fromBase64(encoded) = original); end func;
http://rosettacode.org/wiki/Base64_decode_data
Base64 decode data
See Base64 encode data. Now write a program that takes the output of the Base64 encode data task as input and regenerate the original file. When working on the VBA implementation I found several 'solutions' on the net, including one from the software maker himself, that showed output with incorrect padding. Obviously with incorrect padding in the output you can not decode correctly to the original file again.
#SenseTalk
SenseTalk
    put base64Decode ("VG8gZXJyIGlzIGh1bWFuLCBidXQgdG8gcmVhbGx5IGZvdWwgdGhpbmdzIHVwIHlvdSBuZWVkIGEgY29tcHV0ZXIuIC0tUGF1bCBSLkVocmxpY2g=")    
http://rosettacode.org/wiki/Barnsley_fern
Barnsley fern
A Barnsley fern is a fractal named after British mathematician Michael Barnsley and can be created using an iterated function system (IFS). Task Create this fractal fern, using the following transformations: ƒ1   (chosen 1% of the time) xn + 1 = 0 yn + 1 = 0.16 yn ƒ2   (chosen 85% of the time) xn + 1 = 0.85 xn + 0.04 yn yn + 1 = −0.04 xn + 0.85 yn + 1.6 ƒ3   (chosen 7% of the time) xn + 1 = 0.2 xn − 0.26 yn yn + 1 = 0.23 xn + 0.22 yn + 1.6 ƒ4   (chosen 7% of the time) xn + 1 = −0.15 xn + 0.28 yn yn + 1 = 0.26 xn + 0.24 yn + 0.44. Starting position: x = 0, y = 0
#Ada
Ada
with Ada.Numerics.Discrete_Random;   with SDL.Video.Windows.Makers; with SDL.Video.Renderers.Makers; with SDL.Events.Events;   procedure Barnsley_Fern is   Iterations : constant := 1_000_000; Width  : constant := 500; Height  : constant := 750; Scale  : constant := 70.0;   type Percentage is range 1 .. 100; package Random_Percentages is new Ada.Numerics.Discrete_Random (Percentage);   Gen  : Random_Percentages.Generator; Window  : SDL.Video.Windows.Window; Renderer : SDL.Video.Renderers.Renderer; Event  : SDL.Events.Events.Events;   procedure Draw_Barnsley_Fern is use type SDL.C.int; subtype F1_Range is Percentage range Percentage'First .. Percentage'First; subtype F2_Range is Percentage range F1_Range'Last + 1 .. F1_Range'Last + 85; subtype F3_Range is Percentage range F2_Range'Last + 1 .. F2_Range'Last + 7; subtype F4_Range is Percentage range F3_Range'Last + 1 .. F3_Range'Last + 7;   X0, Y0 : Float := 0.00; X1, Y1 : Float; begin for I in 1 .. Iterations loop case Random_Percentages.Random (Gen) is   when F1_Range => X1 := 0.00; Y1 := 0.16 * Y0;   when F2_Range => X1 := 0.85 * X0 + 0.04 * Y0; Y1 := -0.04 * X0 + 0.85 * Y0 + 1.60;   when F3_Range => X1 := 0.20 * X0 - 0.26 * Y0; Y1 := 0.23 * X0 + 0.22 * Y0 + 1.60;   when F4_Range => X1 := -0.15 * X0 + 0.28 * Y0; Y1 := 0.26 * X0 + 0.24 * Y0 + 0.44;   end case; Renderer.Draw (Point => (X => Width / 2 + SDL.C.int (Scale * X1), Y => Height - SDL.C.int (Scale * Y1))); X0 := X1; Y0 := Y1;   end loop; end Draw_Barnsley_Fern;   procedure Wait is use type SDL.Events.Event_Types; begin loop while SDL.Events.Events.Poll (Event) loop if Event.Common.Event_Type = SDL.Events.Quit then return; end if; end loop; end loop; end Wait;   begin if not SDL.Initialise (Flags => SDL.Enable_Screen) then return; end if;   SDL.Video.Windows.Makers.Create (Win => Window, Title => "Barnsley Fern", Position => SDL.Natural_Coordinates'(X => 10, Y => 10), Size => SDL.Positive_Sizes'(Width, Height), Flags => 0); SDL.Video.Renderers.Makers.Create (Renderer, Window.Get_Surface); Renderer.Set_Draw_Colour ((0, 0, 0, 255)); Renderer.Fill (Rectangle => (0, 0, Width, Height)); Renderer.Set_Draw_Colour ((0, 220, 0, 255));   Random_Percentages.Reset (Gen); Draw_Barnsley_Fern; Window.Update_Surface;   Wait; Window.Finalize; SDL.Finalise; end Barnsley_Fern;
http://rosettacode.org/wiki/Averages/Root_mean_square
Averages/Root mean square
Task[edit] Compute the   Root mean square   of the numbers 1..10. The   root mean square   is also known by its initials RMS (or rms), and as the quadratic mean. The RMS is calculated as the mean of the squares of the numbers, square-rooted: x r m s = x 1 2 + x 2 2 + ⋯ + x n 2 n . {\displaystyle x_{\mathrm {rms} }={\sqrt {{{x_{1}}^{2}+{x_{2}}^{2}+\cdots +{x_{n}}^{2}} \over n}}.} See also Tasks for calculating statistical measures in one go moving (sliding window) moving (cumulative) Mean Arithmetic Statistics/Basic Averages/Arithmetic mean Averages/Pythagorean means Averages/Simple moving average Geometric Averages/Pythagorean means Harmonic Averages/Pythagorean means Quadratic Averages/Root mean square Circular Averages/Mean angle Averages/Mean time of day Median Averages/Median Mode Averages/Mode Standard deviation Statistics/Basic Cumulative standard deviation
#Elena
Elena
import extensions; import system'routines; import system'math;   extension op { get RootMeanSquare() = (self.selectBy:(x => x * x).summarize(Real.new()) / self.Length).sqrt(); }   public program() { console.printLine(new Range(1, 10).RootMeanSquare) }
http://rosettacode.org/wiki/Base64_decode_data
Base64 decode data
See Base64 encode data. Now write a program that takes the output of the Base64 encode data task as input and regenerate the original file. When working on the VBA implementation I found several 'solutions' on the net, including one from the software maker himself, that showed output with incorrect padding. Obviously with incorrect padding in the output you can not decode correctly to the original file again.
#Sidef
Sidef
var data = <<'EOT' VG8gZXJyIGlzIGh1bWFuLCBidXQgdG8gcmVhbGx5IGZvdWwgdGhpbmdzIHVwIHlvdSBuZWVkIGEgY2 9tcHV0ZXIuCiAgICAtLSBQYXVsIFIuIEVocmxpY2g= EOT   say data.decode_base64
http://rosettacode.org/wiki/Base64_decode_data
Base64 decode data
See Base64 encode data. Now write a program that takes the output of the Base64 encode data task as input and regenerate the original file. When working on the VBA implementation I found several 'solutions' on the net, including one from the software maker himself, that showed output with incorrect padding. Obviously with incorrect padding in the output you can not decode correctly to the original file again.
#Smalltalk
Smalltalk
data := ' VG8gZXJyIGlzIGh1bWFuLCBidXQgdG8gcmVhbGx5IGZvdWwgdGhpbmdzIHVwIHlvdSBuZWVkIGEgY2 9tcHV0ZXIuCiAgICAtLSBQYXVsIFIuIEVocmxpY2g= '.   data base64Decoded asString printCR.
http://rosettacode.org/wiki/Barnsley_fern
Barnsley fern
A Barnsley fern is a fractal named after British mathematician Michael Barnsley and can be created using an iterated function system (IFS). Task Create this fractal fern, using the following transformations: ƒ1   (chosen 1% of the time) xn + 1 = 0 yn + 1 = 0.16 yn ƒ2   (chosen 85% of the time) xn + 1 = 0.85 xn + 0.04 yn yn + 1 = −0.04 xn + 0.85 yn + 1.6 ƒ3   (chosen 7% of the time) xn + 1 = 0.2 xn − 0.26 yn yn + 1 = 0.23 xn + 0.22 yn + 1.6 ƒ4   (chosen 7% of the time) xn + 1 = −0.15 xn + 0.28 yn yn + 1 = 0.26 xn + 0.24 yn + 0.44. Starting position: x = 0, y = 0
#ALGOL_68
ALGOL 68
  BEGIN INT iterations = 300000; LONG REAL scale x = 40, scale y = 40; [0:400,-200:200]CHAR canvas;   LONG REAL x := 0, y := 0;   FOR i FROM 1 LWB canvas TO 1 UPB canvas DO FOR j FROM 2 LWB canvas TO 2 UPB canvas DO canvas[i,j] := "0" OD OD;   canvas[0, 0] := "1"; TO iterations DO REAL choice := random; LONG REAL xn = x, yn = y;   IF choice < 0.01 THEN x := 0; y := 0.16 * yn ELIF (choice -:= 0.01) < 0.85 THEN x := 0.85 * xn + 0.04 * yn; y := -0.04 * xn + 0.85 * yn + 1.6 ELIF (choice -:= 0.85) < 0.07 THEN x := 0.2 * xn - 0.26 * yn; y := 0.23 * xn + 0.22 * yn + 1.6 ELSE x := -0.15 * xn + 0.28 * yn; y := 0.26 * xn + 0.24 * yn + 0.44 FI;   INT px = SHORTEN ROUND (x * scale x), py = SHORTEN ROUND (y * scale y); IF px < 2 LWB canvas OR px > 2 UPB canvas OR py < 1 LWB canvas OR py > 1 UPB canvas THEN print(("resize canvas. px=", px, ", py=", py, new line)); leave FI;   canvas[py, px] := "1" OD;   FILE f; IF establish(f, "fern.pbm", stand out channel) /= 0 THEN print("error creating file!"); leave FI; put(f, "P1"); new line(f); put(f, (whole((2 UPB canvas) - (2 LWB canvas) + 1, 0), " ", whole((1 UPB canvas) - (1 LWB canvas) + 1, 0), new line)); FOR i FROM 1 UPB canvas BY -1 TO 1 LWB canvas DO put(f, canvas[i,]); new line(f) OD; close(f); leave: SKIP END  
http://rosettacode.org/wiki/Averages/Root_mean_square
Averages/Root mean square
Task[edit] Compute the   Root mean square   of the numbers 1..10. The   root mean square   is also known by its initials RMS (or rms), and as the quadratic mean. The RMS is calculated as the mean of the squares of the numbers, square-rooted: x r m s = x 1 2 + x 2 2 + ⋯ + x n 2 n . {\displaystyle x_{\mathrm {rms} }={\sqrt {{{x_{1}}^{2}+{x_{2}}^{2}+\cdots +{x_{n}}^{2}} \over n}}.} See also Tasks for calculating statistical measures in one go moving (sliding window) moving (cumulative) Mean Arithmetic Statistics/Basic Averages/Arithmetic mean Averages/Pythagorean means Averages/Simple moving average Geometric Averages/Pythagorean means Harmonic Averages/Pythagorean means Quadratic Averages/Root mean square Circular Averages/Mean angle Averages/Mean time of day Median Averages/Median Mode Averages/Mode Standard deviation Statistics/Basic Cumulative standard deviation
#Elixir
Elixir
  defmodule RC do def root_mean_square(enum) do enum |> square |> mean |> :math.sqrt end   defp mean(enum), do: Enum.sum(enum) / Enum.count(enum)   defp square(enum), do: (for x <- enum, do: x * x) end   IO.puts RC.root_mean_square(1..10)  
http://rosettacode.org/wiki/Averages/Root_mean_square
Averages/Root mean square
Task[edit] Compute the   Root mean square   of the numbers 1..10. The   root mean square   is also known by its initials RMS (or rms), and as the quadratic mean. The RMS is calculated as the mean of the squares of the numbers, square-rooted: x r m s = x 1 2 + x 2 2 + ⋯ + x n 2 n . {\displaystyle x_{\mathrm {rms} }={\sqrt {{{x_{1}}^{2}+{x_{2}}^{2}+\cdots +{x_{n}}^{2}} \over n}}.} See also Tasks for calculating statistical measures in one go moving (sliding window) moving (cumulative) Mean Arithmetic Statistics/Basic Averages/Arithmetic mean Averages/Pythagorean means Averages/Simple moving average Geometric Averages/Pythagorean means Harmonic Averages/Pythagorean means Quadratic Averages/Root mean square Circular Averages/Mean angle Averages/Mean time of day Median Averages/Median Mode Averages/Mode Standard deviation Statistics/Basic Cumulative standard deviation
#Emacs_Lisp
Emacs Lisp
(defun rms (nums) (sqrt (/ (apply '+ (mapcar (lambda (x) (* x x)) nums)) (float (length nums)))))   (rms (number-sequence 1 10))
http://rosettacode.org/wiki/Base64_decode_data
Base64 decode data
See Base64 encode data. Now write a program that takes the output of the Base64 encode data task as input and regenerate the original file. When working on the VBA implementation I found several 'solutions' on the net, including one from the software maker himself, that showed output with incorrect padding. Obviously with incorrect padding in the output you can not decode correctly to the original file again.
#Standard_ML
Standard ML
val debase64 = fn input => let   infix 2 Worb infix 2 Wandb fun (p Worb q ) = Word.orb (p,q); fun (p Wandb q ) = Word.andb (p,q);   fun decode #"/" = 0wx3F | decode #"+" = 0wx3E | decode c = if Char.isDigit c then Word.fromInt (ord c) + 0wx04 else if Char.isLower c then Word.fromInt (ord c) - 0wx047 else if Char.isUpper c then Word.fromInt (ord c) - 0wx041 else 0wx00 ;   fun convert (a::b::c::d::_) = let val w = Word.<< (a,0wx12) Worb Word.<< (b,0wx0c) Worb Word.<< (c,0wx06) Worb d in [Word.>> (w,0wx10), Word.>> ((w Wandb 0wx00ff00),0wx08) , w Wandb 0wx0000ff ] end | convert _ = [] ;   fun decodeLst [] = [] | decodeLst ilist = ( convert o map decode )( List.take (ilist,4) ) @ decodeLst (List.drop (ilist,4))   in   String.implode ( List.map (chr o Word.toInt) ( decodeLst (String.explode input )) )   end handle Subscript => "Invalid code\n" ;
http://rosettacode.org/wiki/Base64_decode_data
Base64 decode data
See Base64 encode data. Now write a program that takes the output of the Base64 encode data task as input and regenerate the original file. When working on the VBA implementation I found several 'solutions' on the net, including one from the software maker himself, that showed output with incorrect padding. Obviously with incorrect padding in the output you can not decode correctly to the original file again.
#Tcl
Tcl
package require tcl 8.6 set data VG8gZXJyIGlzIGh1bWFuLCBidXQgdG8gcmVhbGx5IGZvdWwgdGhpbmdzIHVwIHlvdSBuZWVkIGEgY29tcHV0ZXIuCiAgICAtLSBQYXVsIFIuIEVocmxpY2g=   puts [binary decode base64 $data]
http://rosettacode.org/wiki/Barnsley_fern
Barnsley fern
A Barnsley fern is a fractal named after British mathematician Michael Barnsley and can be created using an iterated function system (IFS). Task Create this fractal fern, using the following transformations: ƒ1   (chosen 1% of the time) xn + 1 = 0 yn + 1 = 0.16 yn ƒ2   (chosen 85% of the time) xn + 1 = 0.85 xn + 0.04 yn yn + 1 = −0.04 xn + 0.85 yn + 1.6 ƒ3   (chosen 7% of the time) xn + 1 = 0.2 xn − 0.26 yn yn + 1 = 0.23 xn + 0.22 yn + 1.6 ƒ4   (chosen 7% of the time) xn + 1 = −0.15 xn + 0.28 yn yn + 1 = 0.26 xn + 0.24 yn + 0.44. Starting position: x = 0, y = 0
#Applesoft_BASIC
Applesoft BASIC
100 LET YY(1) = .16 110 XX(2) = .85:XY(2) = .04 120 YX(2) = - .04:YY(2) = .85 130 LET Y(2) = 1.6 140 XX(3) = .20:XY(3) = - .26 150 YX(3) = .23:YY(3) = .22 160 LET Y(3) = 1.6 170 XX(4) = - .15:XY(4) = .28 180 YX(4) = .26:YY(4) = .24 190 LET Y(4) = .44 200 HGR :I = PEEK (49234) 210 HCOLOR= 1 220 LET X = 0:Y = 0 230 FOR I = 1 TO 100000 240 R = INT ( RND (1) * 100) 250 F = (R < 7) + (R < 14) + 2 260 F = F - (R = 99) 270 X = XX(F) * X + XY(F) * Y 280 Y = YX(F) * X + YY(F) * Y 290 Y = Y + Y(F) 300 X% = 62 + X * 27.9 320 Y% = 192 - Y * 19.1 330 HPLOT X% * 2 + 1,Y% 340 NEXT  
http://rosettacode.org/wiki/Barnsley_fern
Barnsley fern
A Barnsley fern is a fractal named after British mathematician Michael Barnsley and can be created using an iterated function system (IFS). Task Create this fractal fern, using the following transformations: ƒ1   (chosen 1% of the time) xn + 1 = 0 yn + 1 = 0.16 yn ƒ2   (chosen 85% of the time) xn + 1 = 0.85 xn + 0.04 yn yn + 1 = −0.04 xn + 0.85 yn + 1.6 ƒ3   (chosen 7% of the time) xn + 1 = 0.2 xn − 0.26 yn yn + 1 = 0.23 xn + 0.22 yn + 1.6 ƒ4   (chosen 7% of the time) xn + 1 = −0.15 xn + 0.28 yn yn + 1 = 0.26 xn + 0.24 yn + 0.44. Starting position: x = 0, y = 0
#BASIC256
BASIC256
# adjustable window altoght # call the subroutine with the altoght you want # it's possible to have a window that's large than your display call barnsley(800) end   subroutine barnsley(alto) graphsize alto / 2, alto color rgb(0, 255, 0)   f = alto / 10.6 c = alto / 4 - alto / 40 x = 0 : y = 0   for n = 1 to alto * 50 p = rand * 100 begin case case p <= 1 nx = 0 ny = 0.16 * y case p <= 8 nx = 0.2 * x - 0.26 * y ny = 0.23 * x + 0.22 * y + 1.6 case p <= 15 nx = -0.15 * x + 0.28 * y ny = 0.26 * x + 0.24 * y + 0.44 else nx = 0.85 * x + 0.04 * y ny = -0.04 * x + 0.85 * y + 1.6 end case x = nx : y = ny plot(c + x * f, alto - y * f) next n   # remove comment (#) in next line to save window as .png file # imgsave("Barnsley_fern.png") end subroutine
http://rosettacode.org/wiki/Averages/Root_mean_square
Averages/Root mean square
Task[edit] Compute the   Root mean square   of the numbers 1..10. The   root mean square   is also known by its initials RMS (or rms), and as the quadratic mean. The RMS is calculated as the mean of the squares of the numbers, square-rooted: x r m s = x 1 2 + x 2 2 + ⋯ + x n 2 n . {\displaystyle x_{\mathrm {rms} }={\sqrt {{{x_{1}}^{2}+{x_{2}}^{2}+\cdots +{x_{n}}^{2}} \over n}}.} See also Tasks for calculating statistical measures in one go moving (sliding window) moving (cumulative) Mean Arithmetic Statistics/Basic Averages/Arithmetic mean Averages/Pythagorean means Averages/Simple moving average Geometric Averages/Pythagorean means Harmonic Averages/Pythagorean means Quadratic Averages/Root mean square Circular Averages/Mean angle Averages/Mean time of day Median Averages/Median Mode Averages/Mode Standard deviation Statistics/Basic Cumulative standard deviation
#Erlang
Erlang
rms(Nums) -> math:sqrt(lists:foldl(fun(E,S) -> S+E*E end, 0, Nums) / length(Nums)).   rms([1,2,3,4,5,6,7,8,9,10]).
http://rosettacode.org/wiki/Averages/Root_mean_square
Averages/Root mean square
Task[edit] Compute the   Root mean square   of the numbers 1..10. The   root mean square   is also known by its initials RMS (or rms), and as the quadratic mean. The RMS is calculated as the mean of the squares of the numbers, square-rooted: x r m s = x 1 2 + x 2 2 + ⋯ + x n 2 n . {\displaystyle x_{\mathrm {rms} }={\sqrt {{{x_{1}}^{2}+{x_{2}}^{2}+\cdots +{x_{n}}^{2}} \over n}}.} See also Tasks for calculating statistical measures in one go moving (sliding window) moving (cumulative) Mean Arithmetic Statistics/Basic Averages/Arithmetic mean Averages/Pythagorean means Averages/Simple moving average Geometric Averages/Pythagorean means Harmonic Averages/Pythagorean means Quadratic Averages/Root mean square Circular Averages/Mean angle Averages/Mean time of day Median Averages/Median Mode Averages/Mode Standard deviation Statistics/Basic Cumulative standard deviation
#ERRE
ERRE
  PROGRAM ROOT_MEAN_SQUARE BEGIN N=10 FOR I=1 TO N DO S=S+I*I END FOR X=SQR(S/N) PRINT("Root mean square is";X) END PROGRAM  
http://rosettacode.org/wiki/Base64_decode_data
Base64 decode data
See Base64 encode data. Now write a program that takes the output of the Base64 encode data task as input and regenerate the original file. When working on the VBA implementation I found several 'solutions' on the net, including one from the software maker himself, that showed output with incorrect padding. Obviously with incorrect padding in the output you can not decode correctly to the original file again.
#Visual_Basic_.NET
Visual Basic .NET
Module Module1   Sub Main() Dim data = "VG8gZXJyIGlzIGh1bWFuLCBidXQgdG8gcmVhbGx5IGZvdWwgdGhpbmdzIHVwIHlvdSBuZWVkIGEgY29tcHV0ZXIuCiAgICAtLSBQYXVsIFIuIEVocmxpY2g=" Console.WriteLine(data) Console.WriteLine()   Dim decoded = Text.Encoding.ASCII.GetString(Convert.FromBase64String(data)) Console.WriteLine(decoded) End Sub   End Module
http://rosettacode.org/wiki/Base64_decode_data
Base64 decode data
See Base64 encode data. Now write a program that takes the output of the Base64 encode data task as input and regenerate the original file. When working on the VBA implementation I found several 'solutions' on the net, including one from the software maker himself, that showed output with incorrect padding. Obviously with incorrect padding in the output you can not decode correctly to the original file again.
#Vlang
Vlang
import encoding.base64   fn main() { msg := "Rosetta Code Base64 decode data task" println("Original : $msg") encoded := base64.encode_str(msg) println("\nEncoded  : $encoded") decoded := base64.decode_str(encoded) println("\nDecoded  : $decoded") }
http://rosettacode.org/wiki/Barnsley_fern
Barnsley fern
A Barnsley fern is a fractal named after British mathematician Michael Barnsley and can be created using an iterated function system (IFS). Task Create this fractal fern, using the following transformations: ƒ1   (chosen 1% of the time) xn + 1 = 0 yn + 1 = 0.16 yn ƒ2   (chosen 85% of the time) xn + 1 = 0.85 xn + 0.04 yn yn + 1 = −0.04 xn + 0.85 yn + 1.6 ƒ3   (chosen 7% of the time) xn + 1 = 0.2 xn − 0.26 yn yn + 1 = 0.23 xn + 0.22 yn + 1.6 ƒ4   (chosen 7% of the time) xn + 1 = −0.15 xn + 0.28 yn yn + 1 = 0.26 xn + 0.24 yn + 0.44. Starting position: x = 0, y = 0
#BBC_BASIC
BBC BASIC
GCOL 2 : REM Green Graphics Color X=0 : Y=0 FOR I%=1 TO 100000 R%=RND(100) CASE TRUE OF WHEN R% == 1 NewX= 0  : NewY= .16 * Y WHEN R% < 9 NewX= .20 * X - .26 * Y : NewY= .23 * X + .22 * Y + 1.6 WHEN R% < 16 NewX=-.15 * X + .28 * Y : NewY= .26 * X + .24 * Y + .44 OTHERWISE NewX= .85 * X + .04 * Y : NewY=-.04 * X + .85 * Y + 1.6 ENDCASE X=NewX : Y=NewY PLOT 1000 + X * 130 , Y * 130 NEXT END
http://rosettacode.org/wiki/Barnsley_fern
Barnsley fern
A Barnsley fern is a fractal named after British mathematician Michael Barnsley and can be created using an iterated function system (IFS). Task Create this fractal fern, using the following transformations: ƒ1   (chosen 1% of the time) xn + 1 = 0 yn + 1 = 0.16 yn ƒ2   (chosen 85% of the time) xn + 1 = 0.85 xn + 0.04 yn yn + 1 = −0.04 xn + 0.85 yn + 1.6 ƒ3   (chosen 7% of the time) xn + 1 = 0.2 xn − 0.26 yn yn + 1 = 0.23 xn + 0.22 yn + 1.6 ƒ4   (chosen 7% of the time) xn + 1 = −0.15 xn + 0.28 yn yn + 1 = 0.26 xn + 0.24 yn + 0.44. Starting position: x = 0, y = 0
#C
C
  #include<graphics.h> #include<stdlib.h> #include<stdio.h> #include<time.h>   void barnsleyFern(int windowWidth, unsigned long iter){   double x0=0,y0=0,x1,y1; int diceThrow; time_t t; srand((unsigned)time(&t));   while(iter>0){ diceThrow = rand()%100;   if(diceThrow==0){ x1 = 0; y1 = 0.16*y0; }   else if(diceThrow>=1 && diceThrow<=7){ x1 = -0.15*x0 + 0.28*y0; y1 = 0.26*x0 + 0.24*y0 + 0.44; }   else if(diceThrow>=8 && diceThrow<=15){ x1 = 0.2*x0 - 0.26*y0; y1 = 0.23*x0 + 0.22*y0 + 1.6; }   else{ x1 = 0.85*x0 + 0.04*y0; y1 = -0.04*x0 + 0.85*y0 + 1.6; }   putpixel(30*x1 + windowWidth/2.0,30*y1,GREEN);   x0 = x1; y0 = y1;   iter--; }   }   int main() { unsigned long num;   printf("Enter number of iterations : "); scanf("%ld",&num);   initwindow(500,500,"Barnsley Fern");   barnsleyFern(500,num);   getch();   closegraph();   return 0; }  
http://rosettacode.org/wiki/Averages/Root_mean_square
Averages/Root mean square
Task[edit] Compute the   Root mean square   of the numbers 1..10. The   root mean square   is also known by its initials RMS (or rms), and as the quadratic mean. The RMS is calculated as the mean of the squares of the numbers, square-rooted: x r m s = x 1 2 + x 2 2 + ⋯ + x n 2 n . {\displaystyle x_{\mathrm {rms} }={\sqrt {{{x_{1}}^{2}+{x_{2}}^{2}+\cdots +{x_{n}}^{2}} \over n}}.} See also Tasks for calculating statistical measures in one go moving (sliding window) moving (cumulative) Mean Arithmetic Statistics/Basic Averages/Arithmetic mean Averages/Pythagorean means Averages/Simple moving average Geometric Averages/Pythagorean means Harmonic Averages/Pythagorean means Quadratic Averages/Root mean square Circular Averages/Mean angle Averages/Mean time of day Median Averages/Median Mode Averages/Mode Standard deviation Statistics/Basic Cumulative standard deviation
#Euphoria
Euphoria
function rms(sequence s) atom sum if length(s) = 0 then return 0 end if sum = 0 for i = 1 to length(s) do sum += power(s[i],2) end for return sqrt(sum/length(s)) end function   constant s = {1,2,3,4,5,6,7,8,9,10} ? rms(s)
http://rosettacode.org/wiki/Base64_decode_data
Base64 decode data
See Base64 encode data. Now write a program that takes the output of the Base64 encode data task as input and regenerate the original file. When working on the VBA implementation I found several 'solutions' on the net, including one from the software maker himself, that showed output with incorrect padding. Obviously with incorrect padding in the output you can not decode correctly to the original file again.
#Wren
Wren
import "io" for Stdout import "/fmt" for Conv, Fmt import "/str" for Str   var alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"   var decode = Fn.new { |s| if (s == "") return s var d = "" for (b in s) { var ix = alpha.indexOf(b) if (ix >= 0) d = d + Fmt.swrite("$06b", ix) } if (s.endsWith("==")) { d = d[0..-5] } else if (s.endsWith("=")){ d = d[0..-3] } var i = 0 while (i < d.count) { var ch = String.fromByte(Conv.atoi(d[i..i+7], 2)) System.write(ch) i = i + 8 } Stdout.flush() }   var s = "VG8gZXJyIGlzIGh1bWFuLCBidXQgdG8gcmVhbGx5IGZvdWwgdGhpbmdzIHVwIHlvdSBuZWVkIGEgY29tcHV0ZXIuCiAgICAtLSBQYXVsIFIuIEVocmxpY2g=" for (chunk in Str.chunks(s, 4)) decode.call(chunk) System.print()
http://rosettacode.org/wiki/Barnsley_fern
Barnsley fern
A Barnsley fern is a fractal named after British mathematician Michael Barnsley and can be created using an iterated function system (IFS). Task Create this fractal fern, using the following transformations: ƒ1   (chosen 1% of the time) xn + 1 = 0 yn + 1 = 0.16 yn ƒ2   (chosen 85% of the time) xn + 1 = 0.85 xn + 0.04 yn yn + 1 = −0.04 xn + 0.85 yn + 1.6 ƒ3   (chosen 7% of the time) xn + 1 = 0.2 xn − 0.26 yn yn + 1 = 0.23 xn + 0.22 yn + 1.6 ƒ4   (chosen 7% of the time) xn + 1 = −0.15 xn + 0.28 yn yn + 1 = 0.26 xn + 0.24 yn + 0.44. Starting position: x = 0, y = 0
#C.23
C#
using System; using System.Diagnostics; using System.Drawing;   namespace RosettaBarnsleyFern { class Program { static void Main(string[] args) { const int w = 600; const int h = 600; var bm = new Bitmap(w, h); var r = new Random(); double x = 0; double y = 0; for (int count = 0; count < 100000; count++) { bm.SetPixel((int)(300 + 58 * x), (int)(58 * y), Color.ForestGreen); int roll = r.Next(100); double xp = x; if (roll < 1) { x = 0; y = 0.16 * y; } else if (roll < 86) { x = 0.85 * x + 0.04 * y; y = -0.04 * xp + 0.85 * y + 1.6; } else if (roll < 93) { x = 0.2 * x - 0.26 * y; y = 0.23 * xp + 0.22 * y + 1.6; } else { x = -0.15 * x + 0.28 * y; y = 0.26 * xp + 0.24 * y + 0.44; } } const string filename = "Fern.png"; bm.Save(filename); Process.Start(filename); } } }
http://rosettacode.org/wiki/Averages/Root_mean_square
Averages/Root mean square
Task[edit] Compute the   Root mean square   of the numbers 1..10. The   root mean square   is also known by its initials RMS (or rms), and as the quadratic mean. The RMS is calculated as the mean of the squares of the numbers, square-rooted: x r m s = x 1 2 + x 2 2 + ⋯ + x n 2 n . {\displaystyle x_{\mathrm {rms} }={\sqrt {{{x_{1}}^{2}+{x_{2}}^{2}+\cdots +{x_{n}}^{2}} \over n}}.} See also Tasks for calculating statistical measures in one go moving (sliding window) moving (cumulative) Mean Arithmetic Statistics/Basic Averages/Arithmetic mean Averages/Pythagorean means Averages/Simple moving average Geometric Averages/Pythagorean means Harmonic Averages/Pythagorean means Quadratic Averages/Root mean square Circular Averages/Mean angle Averages/Mean time of day Median Averages/Median Mode Averages/Mode Standard deviation Statistics/Basic Cumulative standard deviation
#Excel
Excel
  =SQRT(SUMSQ($A1:$A10)/COUNT($A1:$A10))  
http://rosettacode.org/wiki/Averages/Root_mean_square
Averages/Root mean square
Task[edit] Compute the   Root mean square   of the numbers 1..10. The   root mean square   is also known by its initials RMS (or rms), and as the quadratic mean. The RMS is calculated as the mean of the squares of the numbers, square-rooted: x r m s = x 1 2 + x 2 2 + ⋯ + x n 2 n . {\displaystyle x_{\mathrm {rms} }={\sqrt {{{x_{1}}^{2}+{x_{2}}^{2}+\cdots +{x_{n}}^{2}} \over n}}.} See also Tasks for calculating statistical measures in one go moving (sliding window) moving (cumulative) Mean Arithmetic Statistics/Basic Averages/Arithmetic mean Averages/Pythagorean means Averages/Simple moving average Geometric Averages/Pythagorean means Harmonic Averages/Pythagorean means Quadratic Averages/Root mean square Circular Averages/Mean angle Averages/Mean time of day Median Averages/Median Mode Averages/Mode Standard deviation Statistics/Basic Cumulative standard deviation
#F.23
F#
let RMS (x:float list) : float = List.map (fun y -> y**2.0) x |> List.average |> System.Math.Sqrt   let res = RMS [1.0..10.0]
http://rosettacode.org/wiki/Base64_decode_data
Base64 decode data
See Base64 encode data. Now write a program that takes the output of the Base64 encode data task as input and regenerate the original file. When working on the VBA implementation I found several 'solutions' on the net, including one from the software maker himself, that showed output with incorrect padding. Obviously with incorrect padding in the output you can not decode correctly to the original file again.
#zkl
zkl
var [const] MsgHash=Import("zklMsgHash"), Curl=Import("zklCurl");   icon:=Curl().get("http://rosettacode.org/favicon.ico"); //-->(Data(4,331),693,0) icon=icon[0][icon[1],*]; // remove header iconEncoded:=MsgHash.base64encode(icon); iconDecoded:=MsgHash.base64decode(iconEncoded); File("rosettaCodeIcon.ico","wb").write(iconDecoded); # eyeball checking says good println("Is the Rosetta Code icon the same (byte for byte) encoded then decoded: ", icon==iconDecoded);
http://rosettacode.org/wiki/Barnsley_fern
Barnsley fern
A Barnsley fern is a fractal named after British mathematician Michael Barnsley and can be created using an iterated function system (IFS). Task Create this fractal fern, using the following transformations: ƒ1   (chosen 1% of the time) xn + 1 = 0 yn + 1 = 0.16 yn ƒ2   (chosen 85% of the time) xn + 1 = 0.85 xn + 0.04 yn yn + 1 = −0.04 xn + 0.85 yn + 1.6 ƒ3   (chosen 7% of the time) xn + 1 = 0.2 xn − 0.26 yn yn + 1 = 0.23 xn + 0.22 yn + 1.6 ƒ4   (chosen 7% of the time) xn + 1 = −0.15 xn + 0.28 yn yn + 1 = 0.26 xn + 0.24 yn + 0.44. Starting position: x = 0, y = 0
#C.2B.2B
C++
  #include <windows.h> #include <ctime> #include <string>   const int BMP_SIZE = 600, ITERATIONS = static_cast<int>( 15e5 );   class myBitmap { public: myBitmap() : pen( NULL ), brush( NULL ), clr( 0 ), wid( 1 ) {} ~myBitmap() { DeleteObject( pen ); DeleteObject( brush ); DeleteDC( hdc ); DeleteObject( bmp ); } bool create( int w, int h ) { BITMAPINFO bi; ZeroMemory( &bi, sizeof( bi ) ); bi.bmiHeader.biSize = sizeof( bi.bmiHeader ); bi.bmiHeader.biBitCount = sizeof( DWORD ) * 8; bi.bmiHeader.biCompression = BI_RGB; bi.bmiHeader.biPlanes = 1; bi.bmiHeader.biWidth = w; bi.bmiHeader.biHeight = -h; HDC dc = GetDC( GetConsoleWindow() ); bmp = CreateDIBSection( dc, &bi, DIB_RGB_COLORS, &pBits, NULL, 0 ); if( !bmp ) return false; hdc = CreateCompatibleDC( dc ); SelectObject( hdc, bmp ); ReleaseDC( GetConsoleWindow(), dc ); width = w; height = h; return true; } void clear( BYTE clr = 0 ) { memset( pBits, clr, width * height * sizeof( DWORD ) ); } void setBrushColor( DWORD bClr ) { if( brush ) DeleteObject( brush ); brush = CreateSolidBrush( bClr ); SelectObject( hdc, brush ); } void setPenColor( DWORD c ) { clr = c; createPen(); } void setPenWidth( int w ) { wid = w; createPen(); } void saveBitmap( std::string path ) { BITMAPFILEHEADER fileheader; BITMAPINFO infoheader; BITMAP bitmap; DWORD wb; GetObject( bmp, sizeof( bitmap ), &bitmap ); DWORD* dwpBits = new DWORD[bitmap.bmWidth * bitmap.bmHeight]; ZeroMemory( dwpBits, bitmap.bmWidth * bitmap.bmHeight * sizeof( DWORD ) ); ZeroMemory( &infoheader, sizeof( BITMAPINFO ) ); ZeroMemory( &fileheader, sizeof( BITMAPFILEHEADER ) ); infoheader.bmiHeader.biBitCount = sizeof( DWORD ) * 8; infoheader.bmiHeader.biCompression = BI_RGB; infoheader.bmiHeader.biPlanes = 1; infoheader.bmiHeader.biSize = sizeof( infoheader.bmiHeader ); infoheader.bmiHeader.biHeight = bitmap.bmHeight; infoheader.bmiHeader.biWidth = bitmap.bmWidth; infoheader.bmiHeader.biSizeImage = bitmap.bmWidth * bitmap.bmHeight * sizeof( DWORD ); fileheader.bfType = 0x4D42; fileheader.bfOffBits = sizeof( infoheader.bmiHeader ) + sizeof( BITMAPFILEHEADER ); fileheader.bfSize = fileheader.bfOffBits + infoheader.bmiHeader.biSizeImage; GetDIBits( hdc, bmp, 0, height, ( LPVOID )dwpBits, &infoheader, DIB_RGB_COLORS ); HANDLE file = CreateFile( path.c_str(), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL ); WriteFile( file, &fileheader, sizeof( BITMAPFILEHEADER ), &wb, NULL ); WriteFile( file, &infoheader.bmiHeader, sizeof( infoheader.bmiHeader ), &wb, NULL ); WriteFile( file, dwpBits, bitmap.bmWidth * bitmap.bmHeight * 4, &wb, NULL ); CloseHandle( file ); delete [] dwpBits; } HDC getDC() const { return hdc; } int getWidth() const { return width; } int getHeight() const { return height; } private: void createPen() { if( pen ) DeleteObject( pen ); pen = CreatePen( PS_SOLID, wid, clr ); SelectObject( hdc, pen ); } HBITMAP bmp; HDC hdc; HPEN pen; HBRUSH brush; void *pBits; int width, height, wid; DWORD clr; }; class fern { public: void draw() { bmp.create( BMP_SIZE, BMP_SIZE ); float x = 0, y = 0; HDC dc = bmp.getDC(); int hs = BMP_SIZE >> 1; for( int f = 0; f < ITERATIONS; f++ ) { SetPixel( dc, hs + static_cast<int>( x * 55.f ), BMP_SIZE - 15 - static_cast<int>( y * 55.f ), RGB( static_cast<int>( rnd() * 80.f ) + 20, static_cast<int>( rnd() * 128.f ) + 128, static_cast<int>( rnd() * 80.f ) + 30 ) ); getXY( x, y ); } bmp.saveBitmap( "./bf.bmp" ); } private: void getXY( float& x, float& y ) { float g, xl, yl; g = rnd(); if( g < .01f ) { xl = 0; yl = .16f * y; } else if( g < .07f ) { xl = .2f * x - .26f * y; yl = .23f * x + .22f * y + 1.6f; } else if( g < .14f ) { xl = -.15f * x + .28f * y; yl = .26f * x + .24f * y + .44f; } else { xl = .85f * x + .04f * y; yl = -.04f * x + .85f * y + 1.6f; } x = xl; y = yl; } float rnd() { return static_cast<float>( rand() ) / static_cast<float>( RAND_MAX ); } myBitmap bmp; }; int main( int argc, char* argv[]) { srand( static_cast<unsigned>( time( 0 ) ) ); fern f; f.draw(); return 0; }  
http://rosettacode.org/wiki/Averages/Root_mean_square
Averages/Root mean square
Task[edit] Compute the   Root mean square   of the numbers 1..10. The   root mean square   is also known by its initials RMS (or rms), and as the quadratic mean. The RMS is calculated as the mean of the squares of the numbers, square-rooted: x r m s = x 1 2 + x 2 2 + ⋯ + x n 2 n . {\displaystyle x_{\mathrm {rms} }={\sqrt {{{x_{1}}^{2}+{x_{2}}^{2}+\cdots +{x_{n}}^{2}} \over n}}.} See also Tasks for calculating statistical measures in one go moving (sliding window) moving (cumulative) Mean Arithmetic Statistics/Basic Averages/Arithmetic mean Averages/Pythagorean means Averages/Simple moving average Geometric Averages/Pythagorean means Harmonic Averages/Pythagorean means Quadratic Averages/Root mean square Circular Averages/Mean angle Averages/Mean time of day Median Averages/Median Mode Averages/Mode Standard deviation Statistics/Basic Cumulative standard deviation
#Factor
Factor
: root-mean-square ( seq -- mean ) [ [ sq ] map-sum ] [ length ] bi / sqrt ;
http://rosettacode.org/wiki/Averages/Root_mean_square
Averages/Root mean square
Task[edit] Compute the   Root mean square   of the numbers 1..10. The   root mean square   is also known by its initials RMS (or rms), and as the quadratic mean. The RMS is calculated as the mean of the squares of the numbers, square-rooted: x r m s = x 1 2 + x 2 2 + ⋯ + x n 2 n . {\displaystyle x_{\mathrm {rms} }={\sqrt {{{x_{1}}^{2}+{x_{2}}^{2}+\cdots +{x_{n}}^{2}} \over n}}.} See also Tasks for calculating statistical measures in one go moving (sliding window) moving (cumulative) Mean Arithmetic Statistics/Basic Averages/Arithmetic mean Averages/Pythagorean means Averages/Simple moving average Geometric Averages/Pythagorean means Harmonic Averages/Pythagorean means Quadratic Averages/Root mean square Circular Averages/Mean angle Averages/Mean time of day Median Averages/Median Mode Averages/Mode Standard deviation Statistics/Basic Cumulative standard deviation
#Fantom
Fantom
class Main { static Float averageRms (Float[] nums) { if (nums.size == 0) return 0.0f Float sum := 0f nums.each { sum += it * it } return (sum / nums.size.toFloat).sqrt }   public static Void main () { a := [1f,2f,3f,4f,5f,6f,7f,8f,9f,10f] echo ("RMS Average of $a is: " + averageRms(a)) } }
http://rosettacode.org/wiki/Barnsley_fern
Barnsley fern
A Barnsley fern is a fractal named after British mathematician Michael Barnsley and can be created using an iterated function system (IFS). Task Create this fractal fern, using the following transformations: ƒ1   (chosen 1% of the time) xn + 1 = 0 yn + 1 = 0.16 yn ƒ2   (chosen 85% of the time) xn + 1 = 0.85 xn + 0.04 yn yn + 1 = −0.04 xn + 0.85 yn + 1.6 ƒ3   (chosen 7% of the time) xn + 1 = 0.2 xn − 0.26 yn yn + 1 = 0.23 xn + 0.22 yn + 1.6 ƒ4   (chosen 7% of the time) xn + 1 = −0.15 xn + 0.28 yn yn + 1 = 0.26 xn + 0.24 yn + 0.44. Starting position: x = 0, y = 0
#Common_Lisp
Common Lisp
(defpackage #:barnsley-fern (:use #:cl #:opticl))   (in-package #:barnsley-fern)   (defparameter *width* 800) (defparameter *height* 800) (defparameter *factor* (/ *height* 13)) (defparameter *x-offset* (/ *width* 2)) (defparameter *y-offset* (/ *height* 10))   (defun f1 (x y) (declare (ignore x)) (values 0 (* 0.16 y)))   (defun f2 (x y) (values (+ (* 0.85 x) (* 0.04 y)) (+ (* -0.04 x) (* 0.85 y) 1.6)))   (defun f3 (x y) (values (+ (* 0.2 x) (* -0.26 y)) (+ (* 0.23 x) (* 0.22 y) 1.6)))   (defun f4 (x y) (values (+ (* -0.15 x) (* 0.28 y)) (+ (* 0.26 x) (* 0.24 y) 0.44)))   (defun choose-transform () (let ((r (random 1.0))) (cond ((< r 0.01) #'f1) ((< r 0.86) #'f2) ((< r 0.93) #'f3) (t #'f4))))   (defun set-pixel (image x y) (let ((%x (round (+ (* *factor* x) *x-offset*))) (%y (round (- *height* (* *factor* y) *y-offset*)))) (setf (pixel image %y %x) (values 0 255 0))))   (defun fern (filespec &optional (iterations 10000000)) (let ((image (make-8-bit-rgb-image *height* *width* :initial-element 0)) (x 0) (y 0)) (dotimes (i iterations) (set-pixel image x y) (multiple-value-setq (x y) (funcall (choose-transform) x y))) (write-png-file filespec image)))
http://rosettacode.org/wiki/Averages/Root_mean_square
Averages/Root mean square
Task[edit] Compute the   Root mean square   of the numbers 1..10. The   root mean square   is also known by its initials RMS (or rms), and as the quadratic mean. The RMS is calculated as the mean of the squares of the numbers, square-rooted: x r m s = x 1 2 + x 2 2 + ⋯ + x n 2 n . {\displaystyle x_{\mathrm {rms} }={\sqrt {{{x_{1}}^{2}+{x_{2}}^{2}+\cdots +{x_{n}}^{2}} \over n}}.} See also Tasks for calculating statistical measures in one go moving (sliding window) moving (cumulative) Mean Arithmetic Statistics/Basic Averages/Arithmetic mean Averages/Pythagorean means Averages/Simple moving average Geometric Averages/Pythagorean means Harmonic Averages/Pythagorean means Quadratic Averages/Root mean square Circular Averages/Mean angle Averages/Mean time of day Median Averages/Median Mode Averages/Mode Standard deviation Statistics/Basic Cumulative standard deviation
#Forth
Forth
: rms ( faddr len -- frms ) dup >r 0e floats bounds do i f@ fdup f* f+ float +loop r> s>f f/ fsqrt ;   create test 1e f, 2e f, 3e f, 4e f, 5e f, 6e f, 7e f, 8e f, 9e f, 10e f, test 10 rms f. \ 6.20483682299543
http://rosettacode.org/wiki/Averages/Root_mean_square
Averages/Root mean square
Task[edit] Compute the   Root mean square   of the numbers 1..10. The   root mean square   is also known by its initials RMS (or rms), and as the quadratic mean. The RMS is calculated as the mean of the squares of the numbers, square-rooted: x r m s = x 1 2 + x 2 2 + ⋯ + x n 2 n . {\displaystyle x_{\mathrm {rms} }={\sqrt {{{x_{1}}^{2}+{x_{2}}^{2}+\cdots +{x_{n}}^{2}} \over n}}.} See also Tasks for calculating statistical measures in one go moving (sliding window) moving (cumulative) Mean Arithmetic Statistics/Basic Averages/Arithmetic mean Averages/Pythagorean means Averages/Simple moving average Geometric Averages/Pythagorean means Harmonic Averages/Pythagorean means Quadratic Averages/Root mean square Circular Averages/Mean angle Averages/Mean time of day Median Averages/Median Mode Averages/Mode Standard deviation Statistics/Basic Cumulative standard deviation
#Fortran
Fortran
print *,sqrt( sum(x**2)/size(x) )
http://rosettacode.org/wiki/Barnsley_fern
Barnsley fern
A Barnsley fern is a fractal named after British mathematician Michael Barnsley and can be created using an iterated function system (IFS). Task Create this fractal fern, using the following transformations: ƒ1   (chosen 1% of the time) xn + 1 = 0 yn + 1 = 0.16 yn ƒ2   (chosen 85% of the time) xn + 1 = 0.85 xn + 0.04 yn yn + 1 = −0.04 xn + 0.85 yn + 1.6 ƒ3   (chosen 7% of the time) xn + 1 = 0.2 xn − 0.26 yn yn + 1 = 0.23 xn + 0.22 yn + 1.6 ƒ4   (chosen 7% of the time) xn + 1 = −0.15 xn + 0.28 yn yn + 1 = 0.26 xn + 0.24 yn + 0.44. Starting position: x = 0, y = 0
#D
D
#!/usr/bin/env dub /+ dub.sdl: dependency "dlib" version="~>0.21.0" +/ import std.random;   import dlib.image;   void main() { enum WIDTH = 640; enum HEIGHT = 640; enum ITERATIONS = 2E6;   float x = 0.0f; float y = 0.0f;   auto rng = Random(unpredictableSeed); auto color = Color4f(0.0f, 1.0f, 0.0f); auto img = image(WIDTH, HEIGHT);   foreach (_; 0..ITERATIONS) { auto r = uniform(0, 101, rng);   if (r <= 1) { x = 0.0; y = 0.16 * y; } else { if (r <= 8) { x = 0.20 * x - 0.26 * y; y = 0.23 * x + 0.22 * y + 1.60; } else { if (r <= 15) { x = -0.15 * x + 0.28 * y; y = 0.26 * x + 0.24 * y + 0.44; } else { x = 0.85 * x + 0.04 * y; y = -0.04 * x + 0.85 * y + 1.6; } } } auto X = cast(int) (WIDTH / 2.0 + x * 60); auto Y = HEIGHT - cast(int)(y * 60); img[X, Y] = color; } img.saveImage(`barnsley_dlib.png`); }
http://rosettacode.org/wiki/Averages/Root_mean_square
Averages/Root mean square
Task[edit] Compute the   Root mean square   of the numbers 1..10. The   root mean square   is also known by its initials RMS (or rms), and as the quadratic mean. The RMS is calculated as the mean of the squares of the numbers, square-rooted: x r m s = x 1 2 + x 2 2 + ⋯ + x n 2 n . {\displaystyle x_{\mathrm {rms} }={\sqrt {{{x_{1}}^{2}+{x_{2}}^{2}+\cdots +{x_{n}}^{2}} \over n}}.} See also Tasks for calculating statistical measures in one go moving (sliding window) moving (cumulative) Mean Arithmetic Statistics/Basic Averages/Arithmetic mean Averages/Pythagorean means Averages/Simple moving average Geometric Averages/Pythagorean means Harmonic Averages/Pythagorean means Quadratic Averages/Root mean square Circular Averages/Mean angle Averages/Mean time of day Median Averages/Median Mode Averages/Mode Standard deviation Statistics/Basic Cumulative standard deviation
#FreeBASIC
FreeBASIC
  ' FB 1.05.0 Win64   Function QuadraticMean(array() As Double) As Double Dim length As Integer = Ubound(array) - Lbound(array) + 1 Dim As Double sum = 0.0 For i As Integer = LBound(array) To UBound(array) sum += array(i) * array(i) Next Return Sqr(sum/length) End Function   Dim vector(1 To 10) As Double For i As Integer = 1 To 10 vector(i) = i Next   Print "Quadratic mean (or RMS) is :"; QuadraticMean(vector()) Print Print "Press any key to quit the program" Sleep  
http://rosettacode.org/wiki/Barnsley_fern
Barnsley fern
A Barnsley fern is a fractal named after British mathematician Michael Barnsley and can be created using an iterated function system (IFS). Task Create this fractal fern, using the following transformations: ƒ1   (chosen 1% of the time) xn + 1 = 0 yn + 1 = 0.16 yn ƒ2   (chosen 85% of the time) xn + 1 = 0.85 xn + 0.04 yn yn + 1 = −0.04 xn + 0.85 yn + 1.6 ƒ3   (chosen 7% of the time) xn + 1 = 0.2 xn − 0.26 yn yn + 1 = 0.23 xn + 0.22 yn + 1.6 ƒ4   (chosen 7% of the time) xn + 1 = −0.15 xn + 0.28 yn yn + 1 = 0.26 xn + 0.24 yn + 0.44. Starting position: x = 0, y = 0
#Delphi
Delphi
unit Unit1;   interface   uses Windows, SysUtils, Graphics, Forms, Controls, Classes, ExtCtrls;   type TForm1 = class(TForm) PaintBox1: TPaintBox; procedure FormPaint(Sender: TObject); private { Private declarations } public { Public declarations } end;   var Form1: TForm1;   implementation   {$R *.dfm}   procedure CreateFern(const w, h: integer); var r, x, y: double; tmpx, tmpy: double; i: integer; begin x := 0; y := 0; randomize();   for i := 0 to 200000 do begin r := random(100000000) / 99999989; if r <= 0.01 then begin tmpx := 0; tmpy := 0.16 * y; end else if r <= 0.08 then begin tmpx := 0.2 * x - 0.26 * y; tmpy := 0.23 * x + 0.22 * y + 1.6; end else if r <= 0.15 then begin tmpx := -0.15 * x + 0.28 * y; tmpy := 0.26 * x + 0.24 * y + 0.44; end else begin tmpx := 0.85 * x + 0.04 * y; tmpy := -0.04 * x + 0.85 * y + 1.6; end; x := tmpx; y := tmpy;   Form1.PaintBox1.Canvas.Pixels[round(w / 2 + x * w / 11), round(h - y * h / 11)] := clGreen; end; end;   procedure TForm1.FormPaint(Sender: TObject); begin CreateFern(Form1.ClientWidth, Form1.ClientHeight); end;   end.
http://rosettacode.org/wiki/Averages/Root_mean_square
Averages/Root mean square
Task[edit] Compute the   Root mean square   of the numbers 1..10. The   root mean square   is also known by its initials RMS (or rms), and as the quadratic mean. The RMS is calculated as the mean of the squares of the numbers, square-rooted: x r m s = x 1 2 + x 2 2 + ⋯ + x n 2 n . {\displaystyle x_{\mathrm {rms} }={\sqrt {{{x_{1}}^{2}+{x_{2}}^{2}+\cdots +{x_{n}}^{2}} \over n}}.} See also Tasks for calculating statistical measures in one go moving (sliding window) moving (cumulative) Mean Arithmetic Statistics/Basic Averages/Arithmetic mean Averages/Pythagorean means Averages/Simple moving average Geometric Averages/Pythagorean means Harmonic Averages/Pythagorean means Quadratic Averages/Root mean square Circular Averages/Mean angle Averages/Mean time of day Median Averages/Median Mode Averages/Mode Standard deviation Statistics/Basic Cumulative standard deviation
#Futhark
Futhark
  import "futlib/math"   fun main(as: [n]f64): f64 = f64.sqrt ((reduce (+) 0.0 (map (**2.0) as)) / f64(n))  
http://rosettacode.org/wiki/Averages/Root_mean_square
Averages/Root mean square
Task[edit] Compute the   Root mean square   of the numbers 1..10. The   root mean square   is also known by its initials RMS (or rms), and as the quadratic mean. The RMS is calculated as the mean of the squares of the numbers, square-rooted: x r m s = x 1 2 + x 2 2 + ⋯ + x n 2 n . {\displaystyle x_{\mathrm {rms} }={\sqrt {{{x_{1}}^{2}+{x_{2}}^{2}+\cdots +{x_{n}}^{2}} \over n}}.} See also Tasks for calculating statistical measures in one go moving (sliding window) moving (cumulative) Mean Arithmetic Statistics/Basic Averages/Arithmetic mean Averages/Pythagorean means Averages/Simple moving average Geometric Averages/Pythagorean means Harmonic Averages/Pythagorean means Quadratic Averages/Root mean square Circular Averages/Mean angle Averages/Mean time of day Median Averages/Median Mode Averages/Mode Standard deviation Statistics/Basic Cumulative standard deviation
#GEORGE
GEORGE
  1, 10 rep (i) i i | (v) ; 0 1, 10 rep (i) i dup mult + ] 10 div sqrt print  
http://rosettacode.org/wiki/Barnsley_fern
Barnsley fern
A Barnsley fern is a fractal named after British mathematician Michael Barnsley and can be created using an iterated function system (IFS). Task Create this fractal fern, using the following transformations: ƒ1   (chosen 1% of the time) xn + 1 = 0 yn + 1 = 0.16 yn ƒ2   (chosen 85% of the time) xn + 1 = 0.85 xn + 0.04 yn yn + 1 = −0.04 xn + 0.85 yn + 1.6 ƒ3   (chosen 7% of the time) xn + 1 = 0.2 xn − 0.26 yn yn + 1 = 0.23 xn + 0.22 yn + 1.6 ƒ4   (chosen 7% of the time) xn + 1 = −0.15 xn + 0.28 yn yn + 1 = 0.26 xn + 0.24 yn + 0.44. Starting position: x = 0, y = 0
#EasyLang
EasyLang
color 060 for i range 200000 r = randomf if r < 0.01 nx = 0 ny = 0.16 * y elif r < 0.08 nx = 0.2 * x - 0.26 * y ny = 0.23 * x + 0.22 * y + 1.6 elif r < 0.15 nx = -0.15 * x + 0.28 * y ny = 0.26 * x + 0.24 * y + 0.44 else nx = 0.85 * x + 0.04 * y ny = -0.04 * x + 0.85 * y + 1.6 . x = nx y = ny move 50 + x * 15 100 - y * 10 rect 0.3 0.3 .
http://rosettacode.org/wiki/Barnsley_fern
Barnsley fern
A Barnsley fern is a fractal named after British mathematician Michael Barnsley and can be created using an iterated function system (IFS). Task Create this fractal fern, using the following transformations: ƒ1   (chosen 1% of the time) xn + 1 = 0 yn + 1 = 0.16 yn ƒ2   (chosen 85% of the time) xn + 1 = 0.85 xn + 0.04 yn yn + 1 = −0.04 xn + 0.85 yn + 1.6 ƒ3   (chosen 7% of the time) xn + 1 = 0.2 xn − 0.26 yn yn + 1 = 0.23 xn + 0.22 yn + 1.6 ƒ4   (chosen 7% of the time) xn + 1 = −0.15 xn + 0.28 yn yn + 1 = 0.26 xn + 0.24 yn + 0.44. Starting position: x = 0, y = 0
#Emacs_Lisp
Emacs Lisp
; Barnsley fern   (defun make-array (size) "Create an empty array with size*size elements." (setq m-array (make-vector size nil)) (dotimes (i size) (setf (aref m-array i) (make-vector size 0))) m-array)   (defun barnsley-next (p) "Return the next Barnsley fern coordinates." (let ((r (random 100)) (x (car p)) (y (cdr p))) (cond ((< r 2) (setq nx 0) (setq ny (* 0.16 y))) ((< r 9) (setq nx (- (* 0.2 x) (* 0.26 y))) (setq ny (+ 1.6 (* 0.23 x) (* 0.22 y)))) ((< r 16) (setq nx (+ (* -0.15 x) (* 0.28 y))) (setq ny (+ 0.44 (* 0.26 x) (* 0.24 y)))) (t (setq nx (+ (* 0.85 x) (* 0.04 y))) (setq ny (+ 1.6 (* -0.04 x) (* 0.85 y))))) (cons nx ny)))   (defun barnsley-lines (arr size) "Turn array into a string for XPM conversion." (setq all "") (dotimes (y size) (setq line "") (dotimes (x size) (setq line (concat line (if (= (elt (elt arr y) x) 1) "*" ".")))) (setq all (concat all "\"" line "\",\n"))) all)   (defun barnsley-show (arr size) "Convert size*size array to XPM image and show it." (insert-image (create-image (concat (format "/* XPM */ static char * barnsley[] = { \"%i %i 2 1\", \". c #000000\", \"* c #00ff00\"," size size) (barnsley-lines arr size) "};") 'xpm t)))   (defun barnsley (size scale max-iter) "Plot the Barnsley fern." (let ((arr (make-array size)) (p (cons 0 0))) (dotimes (it max-iter) (setq p (barnsley-next p)) (setq x (round (+ (/ size 2) (* scale (car p))))) (setq y (round (- size (* scale (cdr p)) 1))) (setf (elt (elt arr y) x) 1)) (barnsley-show arr size)))   (barnsley 400 35 100000)
http://rosettacode.org/wiki/Averages/Root_mean_square
Averages/Root mean square
Task[edit] Compute the   Root mean square   of the numbers 1..10. The   root mean square   is also known by its initials RMS (or rms), and as the quadratic mean. The RMS is calculated as the mean of the squares of the numbers, square-rooted: x r m s = x 1 2 + x 2 2 + ⋯ + x n 2 n . {\displaystyle x_{\mathrm {rms} }={\sqrt {{{x_{1}}^{2}+{x_{2}}^{2}+\cdots +{x_{n}}^{2}} \over n}}.} See also Tasks for calculating statistical measures in one go moving (sliding window) moving (cumulative) Mean Arithmetic Statistics/Basic Averages/Arithmetic mean Averages/Pythagorean means Averages/Simple moving average Geometric Averages/Pythagorean means Harmonic Averages/Pythagorean means Quadratic Averages/Root mean square Circular Averages/Mean angle Averages/Mean time of day Median Averages/Median Mode Averages/Mode Standard deviation Statistics/Basic Cumulative standard deviation
#Go
Go
package main   import ( "fmt" "math" )   func main() { const n = 10 sum := 0. for x := 1.; x <= n; x++ { sum += x * x } fmt.Println(math.Sqrt(sum / n)) }
http://rosettacode.org/wiki/Averages/Root_mean_square
Averages/Root mean square
Task[edit] Compute the   Root mean square   of the numbers 1..10. The   root mean square   is also known by its initials RMS (or rms), and as the quadratic mean. The RMS is calculated as the mean of the squares of the numbers, square-rooted: x r m s = x 1 2 + x 2 2 + ⋯ + x n 2 n . {\displaystyle x_{\mathrm {rms} }={\sqrt {{{x_{1}}^{2}+{x_{2}}^{2}+\cdots +{x_{n}}^{2}} \over n}}.} See also Tasks for calculating statistical measures in one go moving (sliding window) moving (cumulative) Mean Arithmetic Statistics/Basic Averages/Arithmetic mean Averages/Pythagorean means Averages/Simple moving average Geometric Averages/Pythagorean means Harmonic Averages/Pythagorean means Quadratic Averages/Root mean square Circular Averages/Mean angle Averages/Mean time of day Median Averages/Median Mode Averages/Mode Standard deviation Statistics/Basic Cumulative standard deviation
#Groovy
Groovy
def quadMean = { list -> list == null \ ? null \  : list.empty \ ? 0 \  : ((list.collect { it*it }.sum()) / list.size()) ** 0.5 }
http://rosettacode.org/wiki/Barnsley_fern
Barnsley fern
A Barnsley fern is a fractal named after British mathematician Michael Barnsley and can be created using an iterated function system (IFS). Task Create this fractal fern, using the following transformations: ƒ1   (chosen 1% of the time) xn + 1 = 0 yn + 1 = 0.16 yn ƒ2   (chosen 85% of the time) xn + 1 = 0.85 xn + 0.04 yn yn + 1 = −0.04 xn + 0.85 yn + 1.6 ƒ3   (chosen 7% of the time) xn + 1 = 0.2 xn − 0.26 yn yn + 1 = 0.23 xn + 0.22 yn + 1.6 ƒ4   (chosen 7% of the time) xn + 1 = −0.15 xn + 0.28 yn yn + 1 = 0.26 xn + 0.24 yn + 0.44. Starting position: x = 0, y = 0
#F.23
F#
  open System.Drawing   let (|F1|F2|F3|F4|) r = if r < 0.01 then F1 else if r < 0.08 then F3 else if r < 0.15 then F4 else F2   let barnsleyFernFunction (x, y) = function | F1 -> (0.0, 0.16*y) | F2 -> ((0.85*x + 0.04*y), (-0.04*x + 0.85*y + 1.6)) | F3 -> ((0.2*x - 0.26*y), (0.23*x + 0.22*y + 1.6)) | F4 -> ((-0.15*x + 0.28*y), (0.26*x + 0.24*y + 0.44))   let barnsleyFern () = let rnd = System.Random() (0.0, 0.0) |> Seq.unfold (fun point -> Some (point, barnsleyFernFunction point (rnd.NextDouble())))   let run width height = let emptyBitmap = new Bitmap(int width,int height) let bitmap = barnsleyFern () |> Seq.take 250000 // calculate points |> Seq.map (fun (x,y) -> (int (width/2.0+(width*x/11.0)), int (height-(height*y/11.0)))) // transform to pixels |> Seq.fold (fun (b:Bitmap) (x,y) -> b.SetPixel(x-1,y-1,Color.ForestGreen); b) emptyBitmap // add pixels to bitmap bitmap.Save("BFFsharp.png")  
http://rosettacode.org/wiki/Averages/Root_mean_square
Averages/Root mean square
Task[edit] Compute the   Root mean square   of the numbers 1..10. The   root mean square   is also known by its initials RMS (or rms), and as the quadratic mean. The RMS is calculated as the mean of the squares of the numbers, square-rooted: x r m s = x 1 2 + x 2 2 + ⋯ + x n 2 n . {\displaystyle x_{\mathrm {rms} }={\sqrt {{{x_{1}}^{2}+{x_{2}}^{2}+\cdots +{x_{n}}^{2}} \over n}}.} See also Tasks for calculating statistical measures in one go moving (sliding window) moving (cumulative) Mean Arithmetic Statistics/Basic Averages/Arithmetic mean Averages/Pythagorean means Averages/Simple moving average Geometric Averages/Pythagorean means Harmonic Averages/Pythagorean means Quadratic Averages/Root mean square Circular Averages/Mean angle Averages/Mean time of day Median Averages/Median Mode Averages/Mode Standard deviation Statistics/Basic Cumulative standard deviation
#Haskell
Haskell
main = print $ mean 2 [1 .. 10]
http://rosettacode.org/wiki/Averages/Root_mean_square
Averages/Root mean square
Task[edit] Compute the   Root mean square   of the numbers 1..10. The   root mean square   is also known by its initials RMS (or rms), and as the quadratic mean. The RMS is calculated as the mean of the squares of the numbers, square-rooted: x r m s = x 1 2 + x 2 2 + ⋯ + x n 2 n . {\displaystyle x_{\mathrm {rms} }={\sqrt {{{x_{1}}^{2}+{x_{2}}^{2}+\cdots +{x_{n}}^{2}} \over n}}.} See also Tasks for calculating statistical measures in one go moving (sliding window) moving (cumulative) Mean Arithmetic Statistics/Basic Averages/Arithmetic mean Averages/Pythagorean means Averages/Simple moving average Geometric Averages/Pythagorean means Harmonic Averages/Pythagorean means Quadratic Averages/Root mean square Circular Averages/Mean angle Averages/Mean time of day Median Averages/Median Mode Averages/Mode Standard deviation Statistics/Basic Cumulative standard deviation
#HicEst
HicEst
sum = 0 DO i = 1, 10 sum = sum + i^2 ENDDO WRITE(ClipBoard) "RMS(1..10) = ", (sum/10)^0.5
http://rosettacode.org/wiki/Averages/Simple_moving_average
Averages/Simple moving average
Computing the simple moving average of a series of numbers. Task[edit] Create a stateful function/class/instance that takes a period and returns a routine that takes a number as argument and returns a simple moving average of its arguments so far. Description A simple moving average is a method for computing an average of a stream of numbers by only averaging the last   P   numbers from the stream,   where   P   is known as the period. It can be implemented by calling an initialing routine with   P   as its argument,   I(P),   which should then return a routine that when called with individual, successive members of a stream of numbers, computes the mean of (up to), the last   P   of them, lets call this   SMA(). The word   stateful   in the task description refers to the need for   SMA()   to remember certain information between calls to it:   The period,   P   An ordered container of at least the last   P   numbers from each of its individual calls. Stateful   also means that successive calls to   I(),   the initializer,   should return separate routines that do   not   share saved state so they could be used on two independent streams of data. Pseudo-code for an implementation of   SMA   is: function SMA(number: N): stateful integer: P stateful list: stream number: average stream.append_last(N) if stream.length() > P: # Only average the last P elements of the stream stream.delete_first() if stream.length() == 0: average = 0 else: average = sum( stream.values() ) / stream.length() return average See also Tasks for calculating statistical measures in one go moving (sliding window) moving (cumulative) Mean Arithmetic Statistics/Basic Averages/Arithmetic mean Averages/Pythagorean means Averages/Simple moving average Geometric Averages/Pythagorean means Harmonic Averages/Pythagorean means Quadratic Averages/Root mean square Circular Averages/Mean angle Averages/Mean time of day Median Averages/Median Mode Averages/Mode Standard deviation Statistics/Basic Cumulative standard deviation
#11l
11l
T SMA [Float] data sum = 0.0 index = 0 n_filled = 0 Int period   F (period) .period = period .data = [0.0] * period   F add(v) .sum += v - .data[.index] .data[.index] = v .index = (.index + 1) % .period .n_filled = min(.period, .n_filled + 1) R .sum / .n_filled   V sma3 = SMA(3) V sma5 = SMA(5)   L(e) [1, 2, 3, 4, 5, 5, 4, 3, 2, 1] print(‘Added #., sma(3) = #.6, sma(5) = #.6’.format(e, sma3.add(e), sma5.add(e)))
http://rosettacode.org/wiki/Barnsley_fern
Barnsley fern
A Barnsley fern is a fractal named after British mathematician Michael Barnsley and can be created using an iterated function system (IFS). Task Create this fractal fern, using the following transformations: ƒ1   (chosen 1% of the time) xn + 1 = 0 yn + 1 = 0.16 yn ƒ2   (chosen 85% of the time) xn + 1 = 0.85 xn + 0.04 yn yn + 1 = −0.04 xn + 0.85 yn + 1.6 ƒ3   (chosen 7% of the time) xn + 1 = 0.2 xn − 0.26 yn yn + 1 = 0.23 xn + 0.22 yn + 1.6 ƒ4   (chosen 7% of the time) xn + 1 = −0.15 xn + 0.28 yn yn + 1 = 0.26 xn + 0.24 yn + 0.44. Starting position: x = 0, y = 0
#Forth
Forth
  s" SDL2" add-lib \c #include <SDL2/SDL.h> c-function sdl-init SDL_Init n -- n c-function sdl-quit SDL_Quit -- void c-function sdl-createwindow SDL_CreateWindow a n n n n n -- a c-function sdl-createrenderer SDL_CreateRenderer a n n -- a c-function sdl-setdrawcolor SDL_SetRenderDrawColor a n n n n -- n c-function sdl-drawpoint SDL_RenderDrawPoint a n n -- n c-function sdl-renderpresent SDL_RenderPresent a -- void c-function sdl-delay SDL_Delay n -- void   require random.fs   0 value window 0 value renderer variable x variable y   : initFern ( -- ) $20 sdl-init drop s\" Rosetta Task : Barnsley fern\x0" drop 0 0 1000 1000 $0 sdl-createwindow to window window -1 $2 sdl-createrenderer to renderer renderer 0 255 0 255 sdl-setdrawcolor drop ;   create coefficients 0 , 0 , 0 , 160 , 0 , \ 1% of the time - f1 200 , -260 , 230 , 220 , 1600 , \ 7% of the time - f3 -150 , 280 , 260 , 240 , 440 , \ 7% of the time - f4 850 , 40 , -40 , 850 , 1600 , \ 85% of the time - f2   : nextcoeff ( n -- n+1 coeff ) coefficients over cells + @ swap 1+ swap ; : transformation ( n -- ) nextcoeff x @ * swap nextcoeff y @ * rot + 1000 / swap nextcoeff x @ * swap nextcoeff y @ * rot + 1000 / swap nextcoeff rot + y ! drop x ! \ x shall be modified after y calculation ; : randomchoice ( -- index ) 100 random dup 0 > swap dup 7 > swap dup 14 > swap drop + + negate 5 * ;   : fern initFern 20000 0 do randomchoice transformation renderer x @ 10 / 500 + y @ 10 / sdl-drawpoint drop loop renderer sdl-renderpresent 5000 sdl-delay sdl-quit ;   fern
http://rosettacode.org/wiki/Averages/Root_mean_square
Averages/Root mean square
Task[edit] Compute the   Root mean square   of the numbers 1..10. The   root mean square   is also known by its initials RMS (or rms), and as the quadratic mean. The RMS is calculated as the mean of the squares of the numbers, square-rooted: x r m s = x 1 2 + x 2 2 + ⋯ + x n 2 n . {\displaystyle x_{\mathrm {rms} }={\sqrt {{{x_{1}}^{2}+{x_{2}}^{2}+\cdots +{x_{n}}^{2}} \over n}}.} See also Tasks for calculating statistical measures in one go moving (sliding window) moving (cumulative) Mean Arithmetic Statistics/Basic Averages/Arithmetic mean Averages/Pythagorean means Averages/Simple moving average Geometric Averages/Pythagorean means Harmonic Averages/Pythagorean means Quadratic Averages/Root mean square Circular Averages/Mean angle Averages/Mean time of day Median Averages/Median Mode Averages/Mode Standard deviation Statistics/Basic Cumulative standard deviation
#Icon_and_Unicon
Icon and Unicon
procedure main() every put(x := [], 1 to 10) writes("x := [ "); every writes(!x," "); write("]") write("Quadratic mean:",q := qmean!x) end
http://rosettacode.org/wiki/Averages/Simple_moving_average
Averages/Simple moving average
Computing the simple moving average of a series of numbers. Task[edit] Create a stateful function/class/instance that takes a period and returns a routine that takes a number as argument and returns a simple moving average of its arguments so far. Description A simple moving average is a method for computing an average of a stream of numbers by only averaging the last   P   numbers from the stream,   where   P   is known as the period. It can be implemented by calling an initialing routine with   P   as its argument,   I(P),   which should then return a routine that when called with individual, successive members of a stream of numbers, computes the mean of (up to), the last   P   of them, lets call this   SMA(). The word   stateful   in the task description refers to the need for   SMA()   to remember certain information between calls to it:   The period,   P   An ordered container of at least the last   P   numbers from each of its individual calls. Stateful   also means that successive calls to   I(),   the initializer,   should return separate routines that do   not   share saved state so they could be used on two independent streams of data. Pseudo-code for an implementation of   SMA   is: function SMA(number: N): stateful integer: P stateful list: stream number: average stream.append_last(N) if stream.length() > P: # Only average the last P elements of the stream stream.delete_first() if stream.length() == 0: average = 0 else: average = sum( stream.values() ) / stream.length() return average See also Tasks for calculating statistical measures in one go moving (sliding window) moving (cumulative) Mean Arithmetic Statistics/Basic Averages/Arithmetic mean Averages/Pythagorean means Averages/Simple moving average Geometric Averages/Pythagorean means Harmonic Averages/Pythagorean means Quadratic Averages/Root mean square Circular Averages/Mean angle Averages/Mean time of day Median Averages/Median Mode Averages/Mode Standard deviation Statistics/Basic Cumulative standard deviation
#360_Assembly
360 Assembly
* Averages/Simple moving average 26/08/2015 AVGSMA CSECT USING AVGSMA,R12 LR R12,R15 ST R14,SAVER14 ZAP II,=P'0' ii=0 LA R7,1 LH R3,NA SRA R3,1 na/2 LOOPA CR R7,R3 do i=1 to na/2 BH ELOOPA AP II,=P'1000' ii=ii+1000 LR R1,R7 i MH R1,=H'6' LA R4,A-6(R1) MVC 0(6,R4),II a(i)=ii LH R1,NA na SR R1,R7 -i MH R1,=H'6' LA R4,A(R1) MVC 0(6,R4),II a(na+1-i)=ii LA R7,1(R7) B LOOPA ELOOPA XPRNT =CL30' n sma3 sma5 ',30 XPRNT =CL30' ----- ----------- -----------',30 LA R7,1 i=1 LOOP CH R7,NA do i=1 to na BH RETURN STH R7,N n=i XDECO R7,C i MVC BUF+1(5),C+7 MVC P,=H'3' p=3 BAL R14,SMA MVC C(13),EDMASK ED C(13),SS sma(3,i) MVC BUF+7(11),C+2 MVC P,=H'5' p=5 BAL R14,SMA MVC C(13),EDMASK ED C(13),SS sma(5,i) MVC BUF+19(11),C+2 XPRNT BUF,30 output i,sma3,sma5 LA R7,1(R7) B LOOP * ***** sub sma(p,n) returns(PL6) SMA LH R5,N SH R5,P A R5,=F'1' ia=n-p+1 C R5,=F'1' BH OKIA LA R5,1 ia=1 OKIA LH R6,NA ib=na CH R6,N BL OKIB LH R6,N ib=n OKIB ZAP II,=P'0' ii=0 ZAP SS,=P'0' ss=0 LR R3,R5 k=ia LOOPK CR R3,R6 do k=ia to ib BH ELOOPK AP II,=P'1' ii=ii+1 LR R1,R3 MH R1,=H'6' LA R4,A-6(R1) MVC C(6),0(R4) ss=ss+a(k) AP SS,C(6) LA R3,1(R3) B LOOPK ELOOPK ZAP C,SS DP C,II ZAP SS,C(10) ss=ss/ii BR R14 RETURN L R14,SAVER14 restore caller address XR R15,R15 BR R14 SAVER14 DS F NN EQU 10 NA DC AL2(NN) A DS (NN)PL6 II DS PL6 SS DS PL6 P DS H N DS H C DS CL16 BUF DC CL30' ' buffer EDMASK DC X'4020202020202021204B202020' CL13 YREGS END AVGSMA
http://rosettacode.org/wiki/Barnsley_fern
Barnsley fern
A Barnsley fern is a fractal named after British mathematician Michael Barnsley and can be created using an iterated function system (IFS). Task Create this fractal fern, using the following transformations: ƒ1   (chosen 1% of the time) xn + 1 = 0 yn + 1 = 0.16 yn ƒ2   (chosen 85% of the time) xn + 1 = 0.85 xn + 0.04 yn yn + 1 = −0.04 xn + 0.85 yn + 1.6 ƒ3   (chosen 7% of the time) xn + 1 = 0.2 xn − 0.26 yn yn + 1 = 0.23 xn + 0.22 yn + 1.6 ƒ4   (chosen 7% of the time) xn + 1 = −0.15 xn + 0.28 yn yn + 1 = 0.26 xn + 0.24 yn + 0.44. Starting position: x = 0, y = 0
#Fortran
Fortran
  !Generates an output file "plot.dat" that contains the x and y coordinates !for a scatter plot that can be visualized with say, GNUPlot program BarnsleyFern implicit none   double precision :: p(4), a(4), b(4), c(4), d(4), e(4), f(4), trx, try, prob integer :: itermax, i   !The probabilites and coefficients can be modified to generate other !fractal ferns, e.g. http://www.home.aone.net.au/~byzantium/ferns/fractal.html !probabilities p(1) = 0.01; p(2) = 0.85; p(3) = 0.07; p(4) = 0.07   !coefficients a(1) = 0.00; a(2) = 0.85; a(3) = 0.20; a(4) = -0.15 b(1) = 0.00; b(2) = 0.04; b(3) = -0.26; b(4) = 0.28 c(1) = 0.00; c(2) = -0.04; c(3) = 0.23; c(4) = 0.26 d(1) = 0.16; d(2) = 0.85; d(3) = 0.22; d(4) = 0.24 e(1) = 0.00; e(2) = 0.00; e(3) = 0.00; e(4) = 0.00 f(1) = 0.00; f(2) = 1.60; f(3) = 1.60; f(4) = 0.44   itermax = 100000   trx = 0.0D0 try = 0.0D0   open(1, file="plot.dat") write(1,*) "#X #Y" write(1,'(2F10.5)') trx, try   do i = 1, itermax call random_number(prob) if (prob < p(1)) then trx = a(1) * trx + b(1) * try + e(1) try = c(1) * trx + d(1) * try + f(1) else if(prob < (p(1) + p(2))) then trx = a(2) * trx + b(2) * try + e(2) try = c(2) * trx + d(2) * try + f(2) else if ( prob < (p(1) + p(2) + p(3))) then trx = a(3) * trx + b(3) * try + e(3) try = c(3) * trx + d(3) * try + f(3) else trx = a(4) * trx + b(4) * try + e(4) try = c(4) * trx + d(4) * try + f(4) end if write(1,'(2F10.5)') trx, try end do close(1) end program BarnsleyFern  
http://rosettacode.org/wiki/Averages/Root_mean_square
Averages/Root mean square
Task[edit] Compute the   Root mean square   of the numbers 1..10. The   root mean square   is also known by its initials RMS (or rms), and as the quadratic mean. The RMS is calculated as the mean of the squares of the numbers, square-rooted: x r m s = x 1 2 + x 2 2 + ⋯ + x n 2 n . {\displaystyle x_{\mathrm {rms} }={\sqrt {{{x_{1}}^{2}+{x_{2}}^{2}+\cdots +{x_{n}}^{2}} \over n}}.} See also Tasks for calculating statistical measures in one go moving (sliding window) moving (cumulative) Mean Arithmetic Statistics/Basic Averages/Arithmetic mean Averages/Pythagorean means Averages/Simple moving average Geometric Averages/Pythagorean means Harmonic Averages/Pythagorean means Quadratic Averages/Root mean square Circular Averages/Mean angle Averages/Mean time of day Median Averages/Median Mode Averages/Mode Standard deviation Statistics/Basic Cumulative standard deviation
#Io
Io
rms := method (figs, (figs map(** 2) reduce(+) / figs size) sqrt)   rms( Range 1 to(10) asList ) println
http://rosettacode.org/wiki/Averages/Root_mean_square
Averages/Root mean square
Task[edit] Compute the   Root mean square   of the numbers 1..10. The   root mean square   is also known by its initials RMS (or rms), and as the quadratic mean. The RMS is calculated as the mean of the squares of the numbers, square-rooted: x r m s = x 1 2 + x 2 2 + ⋯ + x n 2 n . {\displaystyle x_{\mathrm {rms} }={\sqrt {{{x_{1}}^{2}+{x_{2}}^{2}+\cdots +{x_{n}}^{2}} \over n}}.} See also Tasks for calculating statistical measures in one go moving (sliding window) moving (cumulative) Mean Arithmetic Statistics/Basic Averages/Arithmetic mean Averages/Pythagorean means Averages/Simple moving average Geometric Averages/Pythagorean means Harmonic Averages/Pythagorean means Quadratic Averages/Root mean square Circular Averages/Mean angle Averages/Mean time of day Median Averages/Median Mode Averages/Mode Standard deviation Statistics/Basic Cumulative standard deviation
#J
J
rms=: (+/ % #)&.:*:
http://rosettacode.org/wiki/Averages/Simple_moving_average
Averages/Simple moving average
Computing the simple moving average of a series of numbers. Task[edit] Create a stateful function/class/instance that takes a period and returns a routine that takes a number as argument and returns a simple moving average of its arguments so far. Description A simple moving average is a method for computing an average of a stream of numbers by only averaging the last   P   numbers from the stream,   where   P   is known as the period. It can be implemented by calling an initialing routine with   P   as its argument,   I(P),   which should then return a routine that when called with individual, successive members of a stream of numbers, computes the mean of (up to), the last   P   of them, lets call this   SMA(). The word   stateful   in the task description refers to the need for   SMA()   to remember certain information between calls to it:   The period,   P   An ordered container of at least the last   P   numbers from each of its individual calls. Stateful   also means that successive calls to   I(),   the initializer,   should return separate routines that do   not   share saved state so they could be used on two independent streams of data. Pseudo-code for an implementation of   SMA   is: function SMA(number: N): stateful integer: P stateful list: stream number: average stream.append_last(N) if stream.length() > P: # Only average the last P elements of the stream stream.delete_first() if stream.length() == 0: average = 0 else: average = sum( stream.values() ) / stream.length() return average See also Tasks for calculating statistical measures in one go moving (sliding window) moving (cumulative) Mean Arithmetic Statistics/Basic Averages/Arithmetic mean Averages/Pythagorean means Averages/Simple moving average Geometric Averages/Pythagorean means Harmonic Averages/Pythagorean means Quadratic Averages/Root mean square Circular Averages/Mean angle Averages/Mean time of day Median Averages/Median Mode Averages/Mode Standard deviation Statistics/Basic Cumulative standard deviation
#Ada
Ada
generic Max_Elements : Positive; type Number is digits <>; package Moving is procedure Add_Number (N : Number); function Moving_Average (N : Number) return Number; function Get_Average return Number; end Moving;
http://rosettacode.org/wiki/Barnsley_fern
Barnsley fern
A Barnsley fern is a fractal named after British mathematician Michael Barnsley and can be created using an iterated function system (IFS). Task Create this fractal fern, using the following transformations: ƒ1   (chosen 1% of the time) xn + 1 = 0 yn + 1 = 0.16 yn ƒ2   (chosen 85% of the time) xn + 1 = 0.85 xn + 0.04 yn yn + 1 = −0.04 xn + 0.85 yn + 1.6 ƒ3   (chosen 7% of the time) xn + 1 = 0.2 xn − 0.26 yn yn + 1 = 0.23 xn + 0.22 yn + 1.6 ƒ4   (chosen 7% of the time) xn + 1 = −0.15 xn + 0.28 yn yn + 1 = 0.26 xn + 0.24 yn + 0.44. Starting position: x = 0, y = 0
#FreeBASIC
FreeBASIC
' version 10-10-2016 ' compile with: fbc -s console   Sub barnsley(height As UInteger)   Dim As Double x, y, xn, yn Dim As Double f = height / 10.6 Dim As UInteger offset_x = height \ 4 - height \ 40 Dim As UInteger n, r   ScreenRes height \ 2, height, 32   For n = 1 To height * 50   r = Int(Rnd * 100) ' f from 0 to 99   Select Case As Const r Case 0 To 84 xn = 0.85 * x + 0.04 * y yn = -0.04 * x + 0.85 * y + 1.6 Case 85 To 91 xn = 0.2 * x - 0.26 * y yn = 0.23 * x + 0.22 * y + 1.6 Case 92 To 98 xn = -0.15 * x + 0.28 * y yn = 0.26 * x + 0.24 * y + 0.44 Case Else xn = 0 yn = 0.16 * y End Select   x = xn : y = yn PSet( offset_x + x * f, height - y * f), RGB(0, 255, 0)   Next ' remove comment (') in next line to save window as .bmp file ' BSave "barnsley_fern_" + Str(height) + ".bmp", 0   End Sub     ' ------=< MAIN >=------   ' adjustable window height ' call the subroutine with the height you want ' it's possible to have a window that's large than your display barnsley(800)     ' empty keyboard buffer While Inkey <> "" : Wend Windowtitle "hit any key to end program" Sleep End
http://rosettacode.org/wiki/Averages/Root_mean_square
Averages/Root mean square
Task[edit] Compute the   Root mean square   of the numbers 1..10. The   root mean square   is also known by its initials RMS (or rms), and as the quadratic mean. The RMS is calculated as the mean of the squares of the numbers, square-rooted: x r m s = x 1 2 + x 2 2 + ⋯ + x n 2 n . {\displaystyle x_{\mathrm {rms} }={\sqrt {{{x_{1}}^{2}+{x_{2}}^{2}+\cdots +{x_{n}}^{2}} \over n}}.} See also Tasks for calculating statistical measures in one go moving (sliding window) moving (cumulative) Mean Arithmetic Statistics/Basic Averages/Arithmetic mean Averages/Pythagorean means Averages/Simple moving average Geometric Averages/Pythagorean means Harmonic Averages/Pythagorean means Quadratic Averages/Root mean square Circular Averages/Mean angle Averages/Mean time of day Median Averages/Median Mode Averages/Mode Standard deviation Statistics/Basic Cumulative standard deviation
#Java
Java
public class RootMeanSquare {   public static double rootMeanSquare(double... nums) { double sum = 0.0; for (double num : nums) sum += num * num; return Math.sqrt(sum / nums.length); }   public static void main(String[] args) { double[] nums = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0}; System.out.println("The RMS of the numbers from 1 to 10 is " + rootMeanSquare(nums)); } }
http://rosettacode.org/wiki/Averages/Root_mean_square
Averages/Root mean square
Task[edit] Compute the   Root mean square   of the numbers 1..10. The   root mean square   is also known by its initials RMS (or rms), and as the quadratic mean. The RMS is calculated as the mean of the squares of the numbers, square-rooted: x r m s = x 1 2 + x 2 2 + ⋯ + x n 2 n . {\displaystyle x_{\mathrm {rms} }={\sqrt {{{x_{1}}^{2}+{x_{2}}^{2}+\cdots +{x_{n}}^{2}} \over n}}.} See also Tasks for calculating statistical measures in one go moving (sliding window) moving (cumulative) Mean Arithmetic Statistics/Basic Averages/Arithmetic mean Averages/Pythagorean means Averages/Simple moving average Geometric Averages/Pythagorean means Harmonic Averages/Pythagorean means Quadratic Averages/Root mean square Circular Averages/Mean angle Averages/Mean time of day Median Averages/Median Mode Averages/Mode Standard deviation Statistics/Basic Cumulative standard deviation
#JavaScript
JavaScript
function root_mean_square(ary) { var sum_of_squares = ary.reduce(function(s,x) {return (s + x*x)}, 0); return Math.sqrt(sum_of_squares / ary.length); }   print( root_mean_square([1,2,3,4,5,6,7,8,9,10]) ); // ==> 6.2048368229954285
http://rosettacode.org/wiki/Averages/Simple_moving_average
Averages/Simple moving average
Computing the simple moving average of a series of numbers. Task[edit] Create a stateful function/class/instance that takes a period and returns a routine that takes a number as argument and returns a simple moving average of its arguments so far. Description A simple moving average is a method for computing an average of a stream of numbers by only averaging the last   P   numbers from the stream,   where   P   is known as the period. It can be implemented by calling an initialing routine with   P   as its argument,   I(P),   which should then return a routine that when called with individual, successive members of a stream of numbers, computes the mean of (up to), the last   P   of them, lets call this   SMA(). The word   stateful   in the task description refers to the need for   SMA()   to remember certain information between calls to it:   The period,   P   An ordered container of at least the last   P   numbers from each of its individual calls. Stateful   also means that successive calls to   I(),   the initializer,   should return separate routines that do   not   share saved state so they could be used on two independent streams of data. Pseudo-code for an implementation of   SMA   is: function SMA(number: N): stateful integer: P stateful list: stream number: average stream.append_last(N) if stream.length() > P: # Only average the last P elements of the stream stream.delete_first() if stream.length() == 0: average = 0 else: average = sum( stream.values() ) / stream.length() return average See also Tasks for calculating statistical measures in one go moving (sliding window) moving (cumulative) Mean Arithmetic Statistics/Basic Averages/Arithmetic mean Averages/Pythagorean means Averages/Simple moving average Geometric Averages/Pythagorean means Harmonic Averages/Pythagorean means Quadratic Averages/Root mean square Circular Averages/Mean angle Averages/Mean time of day Median Averages/Median Mode Averages/Mode Standard deviation Statistics/Basic Cumulative standard deviation
#ALGOL_68
ALGOL 68
MODE SMAOBJ = STRUCT( LONG REAL sma, LONG REAL sum, INT period, REF[]LONG REAL values, INT lv );   MODE SMARESULT = UNION ( REF SMAOBJ # handle #, LONG REAL # sma #, REF[]LONG REAL # values # );   MODE SMANEW = INT, SMAFREE = STRUCT(REF SMAOBJ free obj), SMAVALUES = STRUCT(REF SMAOBJ values obj), SMAADD = STRUCT(REF SMAOBJ add obj, LONG REAL v), SMAMEAN = STRUCT(REF SMAOBJ mean obj, REF[]LONG REAL v);   MODE ACTION = UNION ( SMANEW, SMAFREE, SMAVALUES, SMAADD, SMAMEAN );   PROC sma = ([]ACTION action)SMARESULT: ( SMARESULT result; REF SMAOBJ obj; LONG REAL v;   FOR i FROM LWB action TO UPB action DO CASE action[i] IN (SMANEW period):( # args: INT period # HEAP SMAOBJ handle; sma OF handle := 0.0; period OF handle := period; values OF handle := HEAP [period OF handle]LONG REAL; lv OF handle := 0; sum OF handle := 0.0; result := handle ), (SMAFREE args):( # args: REF SMAOBJ free obj # free obj OF args := REF SMAOBJ(NIL) # let the garbage collector do it's job # ), (SMAVALUES args):( # args: REF SMAOBJ values obj # result := values OF values obj OF args ), (SMAMEAN args):( # args: REF SMAOBJ mean obj # result := sma OF mean obj OF args ), (SMAADD args):( # args: REF SMAOBJ add obj, LONG REAL v # obj := add obj OF args; v := v OF args; IF lv OF obj < period OF obj THEN (values OF obj)[lv OF obj+:=1] := v; sum OF obj +:= v; sma OF obj := sum OF obj / lv OF obj ELSE sum OF obj -:= (values OF obj)[ 1+ lv OF obj MOD period OF obj]; sum OF obj +:= v; sma OF obj := sum OF obj / period OF obj; (values OF obj)[ 1+ lv OF obj MOD period OF obj ] := v; lv OF obj+:=1 FI; result := sma OF obj ) OUT SKIP ESAC OD; result );   []LONG REAL v = ( 1, 2, 3, 4, 5, 5, 4, 3, 2, 1 );   main: ( INT i;   REF SMAOBJ h3 := ( sma(SMANEW(3)) | (REF SMAOBJ obj):obj ); REF SMAOBJ h5 := ( sma(SMANEW(5)) | (REF SMAOBJ obj):obj );   FOR i FROM LWB v TO UPB v DO printf(($"next number "g(0,6)", SMA_3 = "g(0,6)", SMA_5 = "g(0,6)l$, v[i], (sma(SMAADD(h3, v[i]))|(LONG REAL r):r), ( sma(SMAADD(h5, v[i])) | (LONG REAL r):r ) )) OD#;   sma(SMAFREE(h3)); sma(SMAFREE(h5)) # )
http://rosettacode.org/wiki/Barnsley_fern
Barnsley fern
A Barnsley fern is a fractal named after British mathematician Michael Barnsley and can be created using an iterated function system (IFS). Task Create this fractal fern, using the following transformations: ƒ1   (chosen 1% of the time) xn + 1 = 0 yn + 1 = 0.16 yn ƒ2   (chosen 85% of the time) xn + 1 = 0.85 xn + 0.04 yn yn + 1 = −0.04 xn + 0.85 yn + 1.6 ƒ3   (chosen 7% of the time) xn + 1 = 0.2 xn − 0.26 yn yn + 1 = 0.23 xn + 0.22 yn + 1.6 ƒ4   (chosen 7% of the time) xn + 1 = −0.15 xn + 0.28 yn yn + 1 = 0.26 xn + 0.24 yn + 0.44. Starting position: x = 0, y = 0
#Frink
Frink
  g = new graphics g.backgroundColor[0,0,0] // black g.color[0,0.5,0] // green   x = 0 y = 0   for i = 1 to 100000 { g.fillEllipseCenter[x*10,y*-10,0.25,0.25] z = random[1, 100] if z == 1 { xn = 0 yn = 0.16 * y } if z >= 2 and z <= 86 { xn = 0.85 * x + 0.04 * y yn = -0.04 * x + 0.85 * y + 1.6 } if z >= 87 and z <= 93 { xn = 0.2 * x - 0.26 * y yn = 0.23 * x + 0.22 * y + 1.6 } if z >= 94 and z <= 100 { xn = -0.15 * x + 0.28 * y yn = 0.26 * x + 0.24 * y + 0.44 } x = xn y = yn }   g.show[]  
http://rosettacode.org/wiki/Averages/Root_mean_square
Averages/Root mean square
Task[edit] Compute the   Root mean square   of the numbers 1..10. The   root mean square   is also known by its initials RMS (or rms), and as the quadratic mean. The RMS is calculated as the mean of the squares of the numbers, square-rooted: x r m s = x 1 2 + x 2 2 + ⋯ + x n 2 n . {\displaystyle x_{\mathrm {rms} }={\sqrt {{{x_{1}}^{2}+{x_{2}}^{2}+\cdots +{x_{n}}^{2}} \over n}}.} See also Tasks for calculating statistical measures in one go moving (sliding window) moving (cumulative) Mean Arithmetic Statistics/Basic Averages/Arithmetic mean Averages/Pythagorean means Averages/Simple moving average Geometric Averages/Pythagorean means Harmonic Averages/Pythagorean means Quadratic Averages/Root mean square Circular Averages/Mean angle Averages/Mean time of day Median Averages/Median Mode Averages/Mode Standard deviation Statistics/Basic Cumulative standard deviation
#jq
jq
def rms: length as $length | if $length == 0 then null else map(. * .) | add | sqrt / $length end ;
http://rosettacode.org/wiki/Averages/Root_mean_square
Averages/Root mean square
Task[edit] Compute the   Root mean square   of the numbers 1..10. The   root mean square   is also known by its initials RMS (or rms), and as the quadratic mean. The RMS is calculated as the mean of the squares of the numbers, square-rooted: x r m s = x 1 2 + x 2 2 + ⋯ + x n 2 n . {\displaystyle x_{\mathrm {rms} }={\sqrt {{{x_{1}}^{2}+{x_{2}}^{2}+\cdots +{x_{n}}^{2}} \over n}}.} See also Tasks for calculating statistical measures in one go moving (sliding window) moving (cumulative) Mean Arithmetic Statistics/Basic Averages/Arithmetic mean Averages/Pythagorean means Averages/Simple moving average Geometric Averages/Pythagorean means Harmonic Averages/Pythagorean means Quadratic Averages/Root mean square Circular Averages/Mean angle Averages/Mean time of day Median Averages/Median Mode Averages/Mode Standard deviation Statistics/Basic Cumulative standard deviation
#Julia
Julia
sqrt(sum(A.^2.) / length(A))
http://rosettacode.org/wiki/Averages/Simple_moving_average
Averages/Simple moving average
Computing the simple moving average of a series of numbers. Task[edit] Create a stateful function/class/instance that takes a period and returns a routine that takes a number as argument and returns a simple moving average of its arguments so far. Description A simple moving average is a method for computing an average of a stream of numbers by only averaging the last   P   numbers from the stream,   where   P   is known as the period. It can be implemented by calling an initialing routine with   P   as its argument,   I(P),   which should then return a routine that when called with individual, successive members of a stream of numbers, computes the mean of (up to), the last   P   of them, lets call this   SMA(). The word   stateful   in the task description refers to the need for   SMA()   to remember certain information between calls to it:   The period,   P   An ordered container of at least the last   P   numbers from each of its individual calls. Stateful   also means that successive calls to   I(),   the initializer,   should return separate routines that do   not   share saved state so they could be used on two independent streams of data. Pseudo-code for an implementation of   SMA   is: function SMA(number: N): stateful integer: P stateful list: stream number: average stream.append_last(N) if stream.length() > P: # Only average the last P elements of the stream stream.delete_first() if stream.length() == 0: average = 0 else: average = sum( stream.values() ) / stream.length() return average See also Tasks for calculating statistical measures in one go moving (sliding window) moving (cumulative) Mean Arithmetic Statistics/Basic Averages/Arithmetic mean Averages/Pythagorean means Averages/Simple moving average Geometric Averages/Pythagorean means Harmonic Averages/Pythagorean means Quadratic Averages/Root mean square Circular Averages/Mean angle Averages/Mean time of day Median Averages/Median Mode Averages/Mode Standard deviation Statistics/Basic Cumulative standard deviation
#AutoHotkey
AutoHotkey
MsgBox % MovingAverage(5,3) ; 5, averaging length <- 3 MsgBox % MovingAverage(1) ; 3 MsgBox % MovingAverage(-3) ; 1 MsgBox % MovingAverage(8) ; 2 MsgBox % MovingAverage(7) ; 4   MovingAverage(x,len="") { ; for integers (faster) Static Static sum:=0, n:=0, m:=10 ; default averaging length = 10 If (len>"") ; non-blank 2nd parameter: set length, reset sum := n := i := 0, m := len If (n < m) ; until the buffer is not full sum += x, n++ ; keep summing data Else ; when buffer is full sum += x-v%i% ; add new, subtract oldest v%i% := x, i := mod(i+1,m) ; remember last m inputs, cycle insertion point Return sum/n }
http://rosettacode.org/wiki/Barnsley_fern
Barnsley fern
A Barnsley fern is a fractal named after British mathematician Michael Barnsley and can be created using an iterated function system (IFS). Task Create this fractal fern, using the following transformations: ƒ1   (chosen 1% of the time) xn + 1 = 0 yn + 1 = 0.16 yn ƒ2   (chosen 85% of the time) xn + 1 = 0.85 xn + 0.04 yn yn + 1 = −0.04 xn + 0.85 yn + 1.6 ƒ3   (chosen 7% of the time) xn + 1 = 0.2 xn − 0.26 yn yn + 1 = 0.23 xn + 0.22 yn + 1.6 ƒ4   (chosen 7% of the time) xn + 1 = −0.15 xn + 0.28 yn yn + 1 = 0.26 xn + 0.24 yn + 0.44. Starting position: x = 0, y = 0
#F.C5.8Drmul.C3.A6
Fōrmulæ
  # Put this into a new file 'fern.gmic' and invoke it from the command line, like this: # $ gmic fern.gmic -barnsley_fern   barnsley_fern : 1024,2048 -skip {" f1 = [ 0,0,0,0.16 ]; g1 = [ 0,0 ]; f2 = [ 0.2,-0.26,0.23,0.22 ]; g2 = [ 0,1.6 ]; f3 = [ -0.15,0.28,0.26,0.24 ]; g3 = [ 0,0.44 ]; f4 = [ 0.85,0.04,-0.04,0.85 ]; g4 = [ 0,1.6 ]; xy = [ 0,0 ]; for (n = 0, n<2e6, ++n, r = u(100); xy = r<=1?((f1**xy)+=g1): r<=8?((f2**xy)+=g2): r<=15?((f3**xy)+=g3): ((f4**xy)+=g4); uv = xy*200 + [ 480,0 ]; uv[1] = h - uv[1]; I(uv) = 0.7*I(uv) + 0.3*255; )"} -r 40%,40%,1,1,2  
http://rosettacode.org/wiki/Averages/Root_mean_square
Averages/Root mean square
Task[edit] Compute the   Root mean square   of the numbers 1..10. The   root mean square   is also known by its initials RMS (or rms), and as the quadratic mean. The RMS is calculated as the mean of the squares of the numbers, square-rooted: x r m s = x 1 2 + x 2 2 + ⋯ + x n 2 n . {\displaystyle x_{\mathrm {rms} }={\sqrt {{{x_{1}}^{2}+{x_{2}}^{2}+\cdots +{x_{n}}^{2}} \over n}}.} See also Tasks for calculating statistical measures in one go moving (sliding window) moving (cumulative) Mean Arithmetic Statistics/Basic Averages/Arithmetic mean Averages/Pythagorean means Averages/Simple moving average Geometric Averages/Pythagorean means Harmonic Averages/Pythagorean means Quadratic Averages/Root mean square Circular Averages/Mean angle Averages/Mean time of day Median Averages/Median Mode Averages/Mode Standard deviation Statistics/Basic Cumulative standard deviation
#K
K
  rms:{_sqrt (+/x^2)%#x} rms 1+!10 6.204837  
http://rosettacode.org/wiki/Averages/Root_mean_square
Averages/Root mean square
Task[edit] Compute the   Root mean square   of the numbers 1..10. The   root mean square   is also known by its initials RMS (or rms), and as the quadratic mean. The RMS is calculated as the mean of the squares of the numbers, square-rooted: x r m s = x 1 2 + x 2 2 + ⋯ + x n 2 n . {\displaystyle x_{\mathrm {rms} }={\sqrt {{{x_{1}}^{2}+{x_{2}}^{2}+\cdots +{x_{n}}^{2}} \over n}}.} See also Tasks for calculating statistical measures in one go moving (sliding window) moving (cumulative) Mean Arithmetic Statistics/Basic Averages/Arithmetic mean Averages/Pythagorean means Averages/Simple moving average Geometric Averages/Pythagorean means Harmonic Averages/Pythagorean means Quadratic Averages/Root mean square Circular Averages/Mean angle Averages/Mean time of day Median Averages/Median Mode Averages/Mode Standard deviation Statistics/Basic Cumulative standard deviation
#Kotlin
Kotlin
// version 1.0.5-2   fun quadraticMean(vector: Array<Double>) : Double { val sum = vector.sumByDouble { it * it } return Math.sqrt(sum / vector.size) }   fun main(args: Array<String>) { val vector = Array(10, { (it + 1).toDouble() }) print("Quadratic mean of numbers 1 to 10 is ${quadraticMean(vector)}") }
http://rosettacode.org/wiki/Averages/Simple_moving_average
Averages/Simple moving average
Computing the simple moving average of a series of numbers. Task[edit] Create a stateful function/class/instance that takes a period and returns a routine that takes a number as argument and returns a simple moving average of its arguments so far. Description A simple moving average is a method for computing an average of a stream of numbers by only averaging the last   P   numbers from the stream,   where   P   is known as the period. It can be implemented by calling an initialing routine with   P   as its argument,   I(P),   which should then return a routine that when called with individual, successive members of a stream of numbers, computes the mean of (up to), the last   P   of them, lets call this   SMA(). The word   stateful   in the task description refers to the need for   SMA()   to remember certain information between calls to it:   The period,   P   An ordered container of at least the last   P   numbers from each of its individual calls. Stateful   also means that successive calls to   I(),   the initializer,   should return separate routines that do   not   share saved state so they could be used on two independent streams of data. Pseudo-code for an implementation of   SMA   is: function SMA(number: N): stateful integer: P stateful list: stream number: average stream.append_last(N) if stream.length() > P: # Only average the last P elements of the stream stream.delete_first() if stream.length() == 0: average = 0 else: average = sum( stream.values() ) / stream.length() return average See also Tasks for calculating statistical measures in one go moving (sliding window) moving (cumulative) Mean Arithmetic Statistics/Basic Averages/Arithmetic mean Averages/Pythagorean means Averages/Simple moving average Geometric Averages/Pythagorean means Harmonic Averages/Pythagorean means Quadratic Averages/Root mean square Circular Averages/Mean angle Averages/Mean time of day Median Averages/Median Mode Averages/Mode Standard deviation Statistics/Basic Cumulative standard deviation
#AWK
AWK
#!/usr/bin/awk -f # Moving average over the first column of a data file BEGIN { P = 5; }   { x = $1; i = NR % P; MA += (x - Z[i]) / P; Z[i] = x; print MA; }
http://rosettacode.org/wiki/Barnsley_fern
Barnsley fern
A Barnsley fern is a fractal named after British mathematician Michael Barnsley and can be created using an iterated function system (IFS). Task Create this fractal fern, using the following transformations: ƒ1   (chosen 1% of the time) xn + 1 = 0 yn + 1 = 0.16 yn ƒ2   (chosen 85% of the time) xn + 1 = 0.85 xn + 0.04 yn yn + 1 = −0.04 xn + 0.85 yn + 1.6 ƒ3   (chosen 7% of the time) xn + 1 = 0.2 xn − 0.26 yn yn + 1 = 0.23 xn + 0.22 yn + 1.6 ƒ4   (chosen 7% of the time) xn + 1 = −0.15 xn + 0.28 yn yn + 1 = 0.26 xn + 0.24 yn + 0.44. Starting position: x = 0, y = 0
#G.27MIC
G'MIC
  # Put this into a new file 'fern.gmic' and invoke it from the command line, like this: # $ gmic fern.gmic -barnsley_fern   barnsley_fern : 1024,2048 -skip {" f1 = [ 0,0,0,0.16 ]; g1 = [ 0,0 ]; f2 = [ 0.2,-0.26,0.23,0.22 ]; g2 = [ 0,1.6 ]; f3 = [ -0.15,0.28,0.26,0.24 ]; g3 = [ 0,0.44 ]; f4 = [ 0.85,0.04,-0.04,0.85 ]; g4 = [ 0,1.6 ]; xy = [ 0,0 ]; for (n = 0, n<2e6, ++n, r = u(100); xy = r<=1?((f1**xy)+=g1): r<=8?((f2**xy)+=g2): r<=15?((f3**xy)+=g3): ((f4**xy)+=g4); uv = xy*200 + [ 480,0 ]; uv[1] = h - uv[1]; I(uv) = 0.7*I(uv) + 0.3*255; )"} -r 40%,40%,1,1,2  
http://rosettacode.org/wiki/Averages/Root_mean_square
Averages/Root mean square
Task[edit] Compute the   Root mean square   of the numbers 1..10. The   root mean square   is also known by its initials RMS (or rms), and as the quadratic mean. The RMS is calculated as the mean of the squares of the numbers, square-rooted: x r m s = x 1 2 + x 2 2 + ⋯ + x n 2 n . {\displaystyle x_{\mathrm {rms} }={\sqrt {{{x_{1}}^{2}+{x_{2}}^{2}+\cdots +{x_{n}}^{2}} \over n}}.} See also Tasks for calculating statistical measures in one go moving (sliding window) moving (cumulative) Mean Arithmetic Statistics/Basic Averages/Arithmetic mean Averages/Pythagorean means Averages/Simple moving average Geometric Averages/Pythagorean means Harmonic Averages/Pythagorean means Quadratic Averages/Root mean square Circular Averages/Mean angle Averages/Mean time of day Median Averages/Median Mode Averages/Mode Standard deviation Statistics/Basic Cumulative standard deviation
#Lasso
Lasso
define rms(a::staticarray)::decimal => { return math_sqrt((with n in #a sum #n*#n) / decimal(#a->size)) } rms(generateSeries(1,10)->asStaticArray)
http://rosettacode.org/wiki/Averages/Root_mean_square
Averages/Root mean square
Task[edit] Compute the   Root mean square   of the numbers 1..10. The   root mean square   is also known by its initials RMS (or rms), and as the quadratic mean. The RMS is calculated as the mean of the squares of the numbers, square-rooted: x r m s = x 1 2 + x 2 2 + ⋯ + x n 2 n . {\displaystyle x_{\mathrm {rms} }={\sqrt {{{x_{1}}^{2}+{x_{2}}^{2}+\cdots +{x_{n}}^{2}} \over n}}.} See also Tasks for calculating statistical measures in one go moving (sliding window) moving (cumulative) Mean Arithmetic Statistics/Basic Averages/Arithmetic mean Averages/Pythagorean means Averages/Simple moving average Geometric Averages/Pythagorean means Harmonic Averages/Pythagorean means Quadratic Averages/Root mean square Circular Averages/Mean angle Averages/Mean time of day Median Averages/Median Mode Averages/Mode Standard deviation Statistics/Basic Cumulative standard deviation
#Liberty_BASIC
Liberty BASIC
' [RC] Averages/Root mean square   SourceList$ ="1 2 3 4 5 6 7 8 9 10"   ' 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 ' This holds index to number, and counts number of data. 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 "R.M.S. value is "; ( SumOfSquares /n)^0.5   end
http://rosettacode.org/wiki/Averages/Simple_moving_average
Averages/Simple moving average
Computing the simple moving average of a series of numbers. Task[edit] Create a stateful function/class/instance that takes a period and returns a routine that takes a number as argument and returns a simple moving average of its arguments so far. Description A simple moving average is a method for computing an average of a stream of numbers by only averaging the last   P   numbers from the stream,   where   P   is known as the period. It can be implemented by calling an initialing routine with   P   as its argument,   I(P),   which should then return a routine that when called with individual, successive members of a stream of numbers, computes the mean of (up to), the last   P   of them, lets call this   SMA(). The word   stateful   in the task description refers to the need for   SMA()   to remember certain information between calls to it:   The period,   P   An ordered container of at least the last   P   numbers from each of its individual calls. Stateful   also means that successive calls to   I(),   the initializer,   should return separate routines that do   not   share saved state so they could be used on two independent streams of data. Pseudo-code for an implementation of   SMA   is: function SMA(number: N): stateful integer: P stateful list: stream number: average stream.append_last(N) if stream.length() > P: # Only average the last P elements of the stream stream.delete_first() if stream.length() == 0: average = 0 else: average = sum( stream.values() ) / stream.length() return average See also Tasks for calculating statistical measures in one go moving (sliding window) moving (cumulative) Mean Arithmetic Statistics/Basic Averages/Arithmetic mean Averages/Pythagorean means Averages/Simple moving average Geometric Averages/Pythagorean means Harmonic Averages/Pythagorean means Quadratic Averages/Root mean square Circular Averages/Mean angle Averages/Mean time of day Median Averages/Median Mode Averages/Mode Standard deviation Statistics/Basic Cumulative standard deviation
#BBC_BASIC
BBC BASIC
MAXPERIOD = 10 FOR n = 1 TO 5 PRINT "Number = ";n TAB(12) " SMA3 = ";FNsma(n,3) TAB(30) " SMA5 = ";FNsma(n,5) NEXT FOR n = 5 TO 1 STEP -1 PRINT "Number = ";n TAB(12) " SMA3 = ";FNsma(n,3) TAB(30) " SMA5 = ";FNsma(n,5) NEXT END   DEF FNsma(number, period%) PRIVATE nums(), accum(), index%(), window%() DIM nums(MAXPERIOD,MAXPERIOD), accum(MAXPERIOD) DIM index%(MAXPERIOD), window%(MAXPERIOD) accum(period%) += number - nums(period%,index%(period%)) nums(period%,index%(period%)) = number index%(period%) = (index%(period%) + 1) MOD period% IF window%(period%)<period% window%(period%) += 1 = accum(period%) / window%(period%)
http://rosettacode.org/wiki/Barnsley_fern
Barnsley fern
A Barnsley fern is a fractal named after British mathematician Michael Barnsley and can be created using an iterated function system (IFS). Task Create this fractal fern, using the following transformations: ƒ1   (chosen 1% of the time) xn + 1 = 0 yn + 1 = 0.16 yn ƒ2   (chosen 85% of the time) xn + 1 = 0.85 xn + 0.04 yn yn + 1 = −0.04 xn + 0.85 yn + 1.6 ƒ3   (chosen 7% of the time) xn + 1 = 0.2 xn − 0.26 yn yn + 1 = 0.23 xn + 0.22 yn + 1.6 ƒ4   (chosen 7% of the time) xn + 1 = −0.15 xn + 0.28 yn yn + 1 = 0.26 xn + 0.24 yn + 0.44. Starting position: x = 0, y = 0
#gnuplot
gnuplot
  ## Barnsley fern fractal 2/17/17 aev reset fn="BarnsleyFernGnu"; clr='"green"'; ttl="Barnsley fern fractal" dfn=fn.".dat"; ofn=fn.".png"; set terminal png font arial 12 size 640,640 set print dfn append set output ofn unset border; unset xtics; unset ytics; unset key; set size square set title ttl font "Arial:Bold,12" n=100000; max=100; x=y=xw=yw=p=0; randgp(top) = floor(rand(0)*top) do for [i=1:n] { p=randgp(max); if (p==1) {xw=0;yw=0.16*y;} if (1<p&&p<=8) {xw=0.2*x-0.26*y;yw=0.23*x+0.22*y+1.6;} if (8<p&&p<=15) {xw=-0.15*x+0.28*y;yw=0.26*x+0.24*y+0.44;} if (p>15) {xw=0.85*x+0.04*y;yw=-0.04*x+0.85*y+1.6;} x=xw;y=yw; print x," ",y; } plot dfn using 1:2 with points pt 7 ps 0.5 lc @clr set output unset print  
http://rosettacode.org/wiki/Averages/Root_mean_square
Averages/Root mean square
Task[edit] Compute the   Root mean square   of the numbers 1..10. The   root mean square   is also known by its initials RMS (or rms), and as the quadratic mean. The RMS is calculated as the mean of the squares of the numbers, square-rooted: x r m s = x 1 2 + x 2 2 + ⋯ + x n 2 n . {\displaystyle x_{\mathrm {rms} }={\sqrt {{{x_{1}}^{2}+{x_{2}}^{2}+\cdots +{x_{n}}^{2}} \over n}}.} See also Tasks for calculating statistical measures in one go moving (sliding window) moving (cumulative) Mean Arithmetic Statistics/Basic Averages/Arithmetic mean Averages/Pythagorean means Averages/Simple moving average Geometric Averages/Pythagorean means Harmonic Averages/Pythagorean means Quadratic Averages/Root mean square Circular Averages/Mean angle Averages/Mean time of day Median Averages/Median Mode Averages/Mode Standard deviation Statistics/Basic Cumulative standard deviation
#Logo
Logo
to rms :v output sqrt quotient (apply "sum map [? * ?] :v) count :v end   show rms iseq 1 10
http://rosettacode.org/wiki/Averages/Root_mean_square
Averages/Root mean square
Task[edit] Compute the   Root mean square   of the numbers 1..10. The   root mean square   is also known by its initials RMS (or rms), and as the quadratic mean. The RMS is calculated as the mean of the squares of the numbers, square-rooted: x r m s = x 1 2 + x 2 2 + ⋯ + x n 2 n . {\displaystyle x_{\mathrm {rms} }={\sqrt {{{x_{1}}^{2}+{x_{2}}^{2}+\cdots +{x_{n}}^{2}} \over n}}.} See also Tasks for calculating statistical measures in one go moving (sliding window) moving (cumulative) Mean Arithmetic Statistics/Basic Averages/Arithmetic mean Averages/Pythagorean means Averages/Simple moving average Geometric Averages/Pythagorean means Harmonic Averages/Pythagorean means Quadratic Averages/Root mean square Circular Averages/Mean angle Averages/Mean time of day Median Averages/Median Mode Averages/Mode Standard deviation Statistics/Basic Cumulative standard deviation
#Lua
Lua
function sumsq(a, ...) return a and a^2 + sumsq(...) or 0 end function rms(t) return (sumsq(unpack(t)) / #t)^.5 end   print(rms{1, 2, 3, 4, 5, 6, 7, 8, 9, 10})
http://rosettacode.org/wiki/Averages/Simple_moving_average
Averages/Simple moving average
Computing the simple moving average of a series of numbers. Task[edit] Create a stateful function/class/instance that takes a period and returns a routine that takes a number as argument and returns a simple moving average of its arguments so far. Description A simple moving average is a method for computing an average of a stream of numbers by only averaging the last   P   numbers from the stream,   where   P   is known as the period. It can be implemented by calling an initialing routine with   P   as its argument,   I(P),   which should then return a routine that when called with individual, successive members of a stream of numbers, computes the mean of (up to), the last   P   of them, lets call this   SMA(). The word   stateful   in the task description refers to the need for   SMA()   to remember certain information between calls to it:   The period,   P   An ordered container of at least the last   P   numbers from each of its individual calls. Stateful   also means that successive calls to   I(),   the initializer,   should return separate routines that do   not   share saved state so they could be used on two independent streams of data. Pseudo-code for an implementation of   SMA   is: function SMA(number: N): stateful integer: P stateful list: stream number: average stream.append_last(N) if stream.length() > P: # Only average the last P elements of the stream stream.delete_first() if stream.length() == 0: average = 0 else: average = sum( stream.values() ) / stream.length() return average See also Tasks for calculating statistical measures in one go moving (sliding window) moving (cumulative) Mean Arithmetic Statistics/Basic Averages/Arithmetic mean Averages/Pythagorean means Averages/Simple moving average Geometric Averages/Pythagorean means Harmonic Averages/Pythagorean means Quadratic Averages/Root mean square Circular Averages/Mean angle Averages/Mean time of day Median Averages/Median Mode Averages/Mode Standard deviation Statistics/Basic Cumulative standard deviation
#BQN
BQN
SMA ← {(+´÷≠)¨(1↓𝕨↑↑𝕩)∾<˘𝕨↕𝕩} v ← (⊢∾⌽)1+↕5 •Show 5 SMA v SMA2 ← { 𝕊 size: nums ← ⟨⟩ sum ← 0 { nums ∾↩ 𝕩 gb ← {(≠nums)≤size ? 0 ; a←⊑nums, nums↩1↓nums, a} sum +↩ 𝕩 - gb sum ÷ ≠nums } } fun ← SMA2 5 Fun¨ v
http://rosettacode.org/wiki/Barnsley_fern
Barnsley fern
A Barnsley fern is a fractal named after British mathematician Michael Barnsley and can be created using an iterated function system (IFS). Task Create this fractal fern, using the following transformations: ƒ1   (chosen 1% of the time) xn + 1 = 0 yn + 1 = 0.16 yn ƒ2   (chosen 85% of the time) xn + 1 = 0.85 xn + 0.04 yn yn + 1 = −0.04 xn + 0.85 yn + 1.6 ƒ3   (chosen 7% of the time) xn + 1 = 0.2 xn − 0.26 yn yn + 1 = 0.23 xn + 0.22 yn + 1.6 ƒ4   (chosen 7% of the time) xn + 1 = −0.15 xn + 0.28 yn yn + 1 = 0.26 xn + 0.24 yn + 0.44. Starting position: x = 0, y = 0
#Go
Go
package main   import ( "image" "image/color" "image/draw" "image/png" "log" "math/rand" "os" )   // values from WP const ( xMin = -2.1820 xMax = 2.6558 yMin = 0. yMax = 9.9983 )   // parameters var ( width = 200 n = int(1e6) c = color.RGBA{34, 139, 34, 255} // forest green )   func main() { dx := xMax - xMin dy := yMax - yMin fw := float64(width) fh := fw * dy / dx height := int(fh) r := image.Rect(0, 0, width, height) img := image.NewRGBA(r) draw.Draw(img, r, &image.Uniform{color.White}, image.ZP, draw.Src) var x, y float64 plot := func() { // transform computed float x, y to integer image coordinates ix := int(fw * (x - xMin) / dx) iy := int(fh * (yMax - y) / dy) img.SetRGBA(ix, iy, c) } plot() for i := 0; i < n; i++ { switch s := rand.Intn(100); { case s < 85: x, y = .85*x+.04*y, -.04*x+.85*y+1.6 case s < 85+7: x, y = .2*x-.26*y, .23*x+.22*y+1.6 case s < 85+7+7: x, y = -.15*x+.28*y, .26*x+.24*y+.44 default: x, y = 0, .16*y } plot() } // write img to png file f, err := os.Create("bf.png") if err != nil { log.Fatal(err) } if err := png.Encode(f, img); err != nil { log.Fatal(err) } }
http://rosettacode.org/wiki/Averages/Root_mean_square
Averages/Root mean square
Task[edit] Compute the   Root mean square   of the numbers 1..10. The   root mean square   is also known by its initials RMS (or rms), and as the quadratic mean. The RMS is calculated as the mean of the squares of the numbers, square-rooted: x r m s = x 1 2 + x 2 2 + ⋯ + x n 2 n . {\displaystyle x_{\mathrm {rms} }={\sqrt {{{x_{1}}^{2}+{x_{2}}^{2}+\cdots +{x_{n}}^{2}} \over n}}.} See also Tasks for calculating statistical measures in one go moving (sliding window) moving (cumulative) Mean Arithmetic Statistics/Basic Averages/Arithmetic mean Averages/Pythagorean means Averages/Simple moving average Geometric Averages/Pythagorean means Harmonic Averages/Pythagorean means Quadratic Averages/Root mean square Circular Averages/Mean angle Averages/Mean time of day Median Averages/Median Mode Averages/Mode Standard deviation Statistics/Basic Cumulative standard deviation
#Maple
Maple
y := [ seq(1..10) ]: RMS := proc( x ) return sqrt( Statistics:-Mean( x ^~ 2 ) ); end proc: RMS( y );  
http://rosettacode.org/wiki/Averages/Root_mean_square
Averages/Root mean square
Task[edit] Compute the   Root mean square   of the numbers 1..10. The   root mean square   is also known by its initials RMS (or rms), and as the quadratic mean. The RMS is calculated as the mean of the squares of the numbers, square-rooted: x r m s = x 1 2 + x 2 2 + ⋯ + x n 2 n . {\displaystyle x_{\mathrm {rms} }={\sqrt {{{x_{1}}^{2}+{x_{2}}^{2}+\cdots +{x_{n}}^{2}} \over n}}.} See also Tasks for calculating statistical measures in one go moving (sliding window) moving (cumulative) Mean Arithmetic Statistics/Basic Averages/Arithmetic mean Averages/Pythagorean means Averages/Simple moving average Geometric Averages/Pythagorean means Harmonic Averages/Pythagorean means Quadratic Averages/Root mean square Circular Averages/Mean angle Averages/Mean time of day Median Averages/Median Mode Averages/Mode Standard deviation Statistics/Basic Cumulative standard deviation
#Mathematica_.2F_Wolfram_Language
Mathematica / Wolfram Language
RootMeanSquare@Range[10]
http://rosettacode.org/wiki/Babbage_problem
Babbage problem
Charles Babbage, looking ahead to the sorts of problems his Analytical Engine would be able to solve, gave this example: What is the smallest positive integer whose square ends in the digits 269,696? — Babbage, letter to Lord Bowden, 1837; see Hollingdale and Tootill, Electronic Computers, second edition, 1970, p. 125. He thought the answer might be 99,736, whose square is 9,947,269,696; but he couldn't be certain. Task[edit] The task is to find out if Babbage had the right answer — and to do so, as far as your language allows it, in code that Babbage himself would have been able to read and understand. As Babbage evidently solved the task with pencil and paper, a similar efficient solution is preferred. For these purposes, Charles Babbage may be taken to be an intelligent person, familiar with mathematics and with the idea of a computer; he has written the first drafts of simple computer programmes in tabular form. [Babbage Archive Series L]. Motivation The aim of the task is to write a program that is sufficiently clear and well-documented for such a person to be able to read it and be confident that it does indeed solve the specified problem.
#11l
11l
V n = 1 L n ^ 2 % 1000000 != 269696 n++ print(n)
http://rosettacode.org/wiki/Averages/Simple_moving_average
Averages/Simple moving average
Computing the simple moving average of a series of numbers. Task[edit] Create a stateful function/class/instance that takes a period and returns a routine that takes a number as argument and returns a simple moving average of its arguments so far. Description A simple moving average is a method for computing an average of a stream of numbers by only averaging the last   P   numbers from the stream,   where   P   is known as the period. It can be implemented by calling an initialing routine with   P   as its argument,   I(P),   which should then return a routine that when called with individual, successive members of a stream of numbers, computes the mean of (up to), the last   P   of them, lets call this   SMA(). The word   stateful   in the task description refers to the need for   SMA()   to remember certain information between calls to it:   The period,   P   An ordered container of at least the last   P   numbers from each of its individual calls. Stateful   also means that successive calls to   I(),   the initializer,   should return separate routines that do   not   share saved state so they could be used on two independent streams of data. Pseudo-code for an implementation of   SMA   is: function SMA(number: N): stateful integer: P stateful list: stream number: average stream.append_last(N) if stream.length() > P: # Only average the last P elements of the stream stream.delete_first() if stream.length() == 0: average = 0 else: average = sum( stream.values() ) / stream.length() return average See also Tasks for calculating statistical measures in one go moving (sliding window) moving (cumulative) Mean Arithmetic Statistics/Basic Averages/Arithmetic mean Averages/Pythagorean means Averages/Simple moving average Geometric Averages/Pythagorean means Harmonic Averages/Pythagorean means Quadratic Averages/Root mean square Circular Averages/Mean angle Averages/Mean time of day Median Averages/Median Mode Averages/Mode Standard deviation Statistics/Basic Cumulative standard deviation
#Bracmat
Bracmat
( ( I = buffer . (new$=):?freshEmptyBuffer & ' ( buffer avg . ( avg = L S n . 0:?L:?S & whl ' ( !arg:%?n ?arg & !n+!S:?S & 1+!L:?L ) & (!L:0&0|!S*!L^-1) ) & (buffer=$freshEmptyBuffer) & !arg !(buffer.):?(buffer.) & ( !(buffer.):?(buffer.) [($arg) ? | ) & avg$!(buffer.) ) ) & ( pad = len w . @(!arg:? [?len) & @(" ":? [!len ?w) & !w !arg ) & I$3:(=?sma3) & I$5:(=?sma5) & 1 2 3 4 5 5 4 3 2 1:?K & whl ' ( !K:%?k ?K & out $ (str$(!k " - sma3:" pad$(sma3$!k) " sma5:" pad$(sma5$!k))) ) );
http://rosettacode.org/wiki/Barnsley_fern
Barnsley fern
A Barnsley fern is a fractal named after British mathematician Michael Barnsley and can be created using an iterated function system (IFS). Task Create this fractal fern, using the following transformations: ƒ1   (chosen 1% of the time) xn + 1 = 0 yn + 1 = 0.16 yn ƒ2   (chosen 85% of the time) xn + 1 = 0.85 xn + 0.04 yn yn + 1 = −0.04 xn + 0.85 yn + 1.6 ƒ3   (chosen 7% of the time) xn + 1 = 0.2 xn − 0.26 yn yn + 1 = 0.23 xn + 0.22 yn + 1.6 ƒ4   (chosen 7% of the time) xn + 1 = −0.15 xn + 0.28 yn yn + 1 = 0.26 xn + 0.24 yn + 0.44. Starting position: x = 0, y = 0
#Groovy
Groovy
import javafx.animation.AnimationTimer import javafx.application.Application import javafx.scene.Group import javafx.scene.Scene import javafx.scene.image.ImageView import javafx.scene.image.WritableImage import javafx.scene.paint.Color import javafx.stage.Stage   class BarnsleyFern extends Application {   @Override void start(Stage primaryStage) { primaryStage.title = 'Barnsley Fern' primaryStage.scene = getScene() primaryStage.show() }   def getScene() { def root = new Group() def scene = new Scene(root, 640, 640) def imageWriter = new WritableImage(640, 640) def imageView = new ImageView(imageWriter) root.children.add imageView   def pixelWriter = imageWriter.pixelWriter   def x = 0, y = 0   ({   50.times { def r = Math.random()   if (r <= 0.01) { x = 0 y = 0.16 * y } else if (r <= 0.08) { x = 0.2 * x - 0.26 * y y = 0.23 * x + 0.22 * y + 1.6 } else if (r <= 0.15) { x = -0.15 * x + 0.28 * y y = 0.26 * x + 0.24 * y + 0.44 } else { x = 0.85 * x + 0.04 * y y = -0.04 * x + 0.85 * y + 1.6 }   pixelWriter.setColor(Math.round(640 / 2 + x * 640 / 11) as Integer, Math.round(640 - y * 640 / 11) as Integer, Color.GREEN) }   } as AnimationTimer).start()   scene }   static void main(args) { launch(BarnsleyFern) } }  
http://rosettacode.org/wiki/Averages/Root_mean_square
Averages/Root mean square
Task[edit] Compute the   Root mean square   of the numbers 1..10. The   root mean square   is also known by its initials RMS (or rms), and as the quadratic mean. The RMS is calculated as the mean of the squares of the numbers, square-rooted: x r m s = x 1 2 + x 2 2 + ⋯ + x n 2 n . {\displaystyle x_{\mathrm {rms} }={\sqrt {{{x_{1}}^{2}+{x_{2}}^{2}+\cdots +{x_{n}}^{2}} \over n}}.} See also Tasks for calculating statistical measures in one go moving (sliding window) moving (cumulative) Mean Arithmetic Statistics/Basic Averages/Arithmetic mean Averages/Pythagorean means Averages/Simple moving average Geometric Averages/Pythagorean means Harmonic Averages/Pythagorean means Quadratic Averages/Root mean square Circular Averages/Mean angle Averages/Mean time of day Median Averages/Median Mode Averages/Mode Standard deviation Statistics/Basic Cumulative standard deviation
#MATLAB
MATLAB
function rms = quadraticMean(list) rms = sqrt(mean(list.^2)); end
http://rosettacode.org/wiki/Averages/Root_mean_square
Averages/Root mean square
Task[edit] Compute the   Root mean square   of the numbers 1..10. The   root mean square   is also known by its initials RMS (or rms), and as the quadratic mean. The RMS is calculated as the mean of the squares of the numbers, square-rooted: x r m s = x 1 2 + x 2 2 + ⋯ + x n 2 n . {\displaystyle x_{\mathrm {rms} }={\sqrt {{{x_{1}}^{2}+{x_{2}}^{2}+\cdots +{x_{n}}^{2}} \over n}}.} See also Tasks for calculating statistical measures in one go moving (sliding window) moving (cumulative) Mean Arithmetic Statistics/Basic Averages/Arithmetic mean Averages/Pythagorean means Averages/Simple moving average Geometric Averages/Pythagorean means Harmonic Averages/Pythagorean means Quadratic Averages/Root mean square Circular Averages/Mean angle Averages/Mean time of day Median Averages/Median Mode Averages/Mode Standard deviation Statistics/Basic Cumulative standard deviation
#Maxima
Maxima
L: makelist(i, i, 10)$   rms(L) := sqrt(lsum(x^2, x, L)/length(L))$   rms(L), numer; /* 6.204836822995429 */
http://rosettacode.org/wiki/Babbage_problem
Babbage problem
Charles Babbage, looking ahead to the sorts of problems his Analytical Engine would be able to solve, gave this example: What is the smallest positive integer whose square ends in the digits 269,696? — Babbage, letter to Lord Bowden, 1837; see Hollingdale and Tootill, Electronic Computers, second edition, 1970, p. 125. He thought the answer might be 99,736, whose square is 9,947,269,696; but he couldn't be certain. Task[edit] The task is to find out if Babbage had the right answer — and to do so, as far as your language allows it, in code that Babbage himself would have been able to read and understand. As Babbage evidently solved the task with pencil and paper, a similar efficient solution is preferred. For these purposes, Charles Babbage may be taken to be an intelligent person, familiar with mathematics and with the idea of a computer; he has written the first drafts of simple computer programmes in tabular form. [Babbage Archive Series L]. Motivation The aim of the task is to write a program that is sufficiently clear and well-documented for such a person to be able to read it and be confident that it does indeed solve the specified problem.
#360_Assembly
360 Assembly
  * Find the lowest positive integer whose square ends in 269696 * The logic of the assembler program is simple : * loop for i=524 step 2 * if (i*i modulo 1000000)=269696 then leave loop * next i * output 'Solution is: i=' i ' (i*i=' i*i ')' BABBAGE CSECT beginning of the control section USING BABBAGE,13 define the base register B 72(15) skip savearea (72=18*4) DC 17F'0' savearea (18 full words (17+1)) STM 14,12,12(13) prolog: save the caller registers ST 13,4(15) prolog: link backwards ST 15,8(13) prolog: link forwards LR 13,15 prolog: establish addressability LA 6,524 let register6 be i and load 524 LOOP LR 5,6 load register5 with i MR 4,6 multiply register5 with i LR 7,5 load register7 with the result i*i D 4,=F'1000000' divide register5 with 1000000 C 4,=F'269696' compare the reminder with 269696 BE ENDLOOP if equal branch to ENDLOOP LA 6,2(6) load register6 (i) with value i+2 B LOOP branch to LOOP ENDLOOP XDECO 6,BUFFER+15 edit registrer6 (i) XDECO 7,BUFFER+34 edit registrer7 (i squared) XPRNT BUFFER,L'BUFFER print buffer L 13,4(0,13) epilog: restore the caller savearea LM 14,12,12(13) epilog: restore the caller registers XR 15,15 epilog: set return code to 0 BR 14 epilog: branch to caller BUFFER DC CL80'Solution is: i=............ (i*i=............)' END BABBAGE end of the control section  
http://rosettacode.org/wiki/Averages/Simple_moving_average
Averages/Simple moving average
Computing the simple moving average of a series of numbers. Task[edit] Create a stateful function/class/instance that takes a period and returns a routine that takes a number as argument and returns a simple moving average of its arguments so far. Description A simple moving average is a method for computing an average of a stream of numbers by only averaging the last   P   numbers from the stream,   where   P   is known as the period. It can be implemented by calling an initialing routine with   P   as its argument,   I(P),   which should then return a routine that when called with individual, successive members of a stream of numbers, computes the mean of (up to), the last   P   of them, lets call this   SMA(). The word   stateful   in the task description refers to the need for   SMA()   to remember certain information between calls to it:   The period,   P   An ordered container of at least the last   P   numbers from each of its individual calls. Stateful   also means that successive calls to   I(),   the initializer,   should return separate routines that do   not   share saved state so they could be used on two independent streams of data. Pseudo-code for an implementation of   SMA   is: function SMA(number: N): stateful integer: P stateful list: stream number: average stream.append_last(N) if stream.length() > P: # Only average the last P elements of the stream stream.delete_first() if stream.length() == 0: average = 0 else: average = sum( stream.values() ) / stream.length() return average See also Tasks for calculating statistical measures in one go moving (sliding window) moving (cumulative) Mean Arithmetic Statistics/Basic Averages/Arithmetic mean Averages/Pythagorean means Averages/Simple moving average Geometric Averages/Pythagorean means Harmonic Averages/Pythagorean means Quadratic Averages/Root mean square Circular Averages/Mean angle Averages/Mean time of day Median Averages/Median Mode Averages/Mode Standard deviation Statistics/Basic Cumulative standard deviation
#Brat
Brat
  SMA = object.new   SMA.init = { period | my.period = period my.list = [] my.average = 0 }   SMA.prototype.add = { num | true? my.list.length >= my.period { my.list.deq }   my.list << num my.average = my.list.reduce(:+) / my.list.length }   sma3 = SMA.new 3 sma5 = SMA.new 5 [1, 2, 3, 4, 5, 5, 4, 3, 2, 1].each { n | p n, " - SMA3: ", sma3.add(n), " SMA5: ", sma5.add(n) }
http://rosettacode.org/wiki/Barnsley_fern
Barnsley fern
A Barnsley fern is a fractal named after British mathematician Michael Barnsley and can be created using an iterated function system (IFS). Task Create this fractal fern, using the following transformations: ƒ1   (chosen 1% of the time) xn + 1 = 0 yn + 1 = 0.16 yn ƒ2   (chosen 85% of the time) xn + 1 = 0.85 xn + 0.04 yn yn + 1 = −0.04 xn + 0.85 yn + 1.6 ƒ3   (chosen 7% of the time) xn + 1 = 0.2 xn − 0.26 yn yn + 1 = 0.23 xn + 0.22 yn + 1.6 ƒ4   (chosen 7% of the time) xn + 1 = −0.15 xn + 0.28 yn yn + 1 = 0.26 xn + 0.24 yn + 0.44. Starting position: x = 0, y = 0
#Haskell
Haskell
import Data.List (scanl') import Diagrams.Backend.Rasterific.CmdLine import Diagrams.Prelude import System.Random   type Pt = (Double, Double)   -- Four affine transformations used to produce a Barnsley fern. f1, f2, f3, f4 :: Pt -> Pt f1 (x, y) = ( 0, 0.16 * y) f2 (x, y) = ( 0.85 * x + 0.04 * y , -0.04 * x + 0.85 * y + 1.60) f3 (x, y) = ( 0.20 * x - 0.26 * y , 0.23 * x + 0.22 * y + 1.60) f4 (x, y) = (-0.15 * x + 0.28 * y , 0.26 * x + 0.24 * y + 0.44)   -- Given a random number in [0, 1) transform an initial point by a randomly -- chosen function. func :: Pt -> Double -> Pt func p r | r < 0.01 = f1 p | r < 0.86 = f2 p | r < 0.93 = f3 p | otherwise = f4 p   -- Using a sequence of uniformly distributed random numbers in [0, 1) return -- the same number of points in the fern. fern :: [Double] -> [Pt] fern = scanl' func (0, 0)   -- Given a supply of random values and a count, generate a diagram of a fern -- composed of that number of points. drawFern :: [Double] -> Int -> Diagram B drawFern rs n = frame 0.5 . diagramFrom . take n $ fern rs where diagramFrom = flip atPoints (repeat dot) . map p2 dot = circle 0.005 # lc green   -- To generate a PNG image of a fern, call this program like: -- -- fern -o fern.png -w 640 -h 640 50000 -- -- where the arguments specify the width, height and number of points in the -- image. main :: IO () main = do rand <- getStdGen mainWith $ drawFern (randomRs (0, 1) rand)
http://rosettacode.org/wiki/Averages/Root_mean_square
Averages/Root mean square
Task[edit] Compute the   Root mean square   of the numbers 1..10. The   root mean square   is also known by its initials RMS (or rms), and as the quadratic mean. The RMS is calculated as the mean of the squares of the numbers, square-rooted: x r m s = x 1 2 + x 2 2 + ⋯ + x n 2 n . {\displaystyle x_{\mathrm {rms} }={\sqrt {{{x_{1}}^{2}+{x_{2}}^{2}+\cdots +{x_{n}}^{2}} \over n}}.} See also Tasks for calculating statistical measures in one go moving (sliding window) moving (cumulative) Mean Arithmetic Statistics/Basic Averages/Arithmetic mean Averages/Pythagorean means Averages/Simple moving average Geometric Averages/Pythagorean means Harmonic Averages/Pythagorean means Quadratic Averages/Root mean square Circular Averages/Mean angle Averages/Mean time of day Median Averages/Median Mode Averages/Mode Standard deviation Statistics/Basic Cumulative standard deviation
#MAXScript
MAXScript
  fn RMS arr = ( local sumSquared = 0 for i in arr do sumSquared += i^2 return (sqrt (sumSquared/arr.count as float)) )  
http://rosettacode.org/wiki/Averages/Root_mean_square
Averages/Root mean square
Task[edit] Compute the   Root mean square   of the numbers 1..10. The   root mean square   is also known by its initials RMS (or rms), and as the quadratic mean. The RMS is calculated as the mean of the squares of the numbers, square-rooted: x r m s = x 1 2 + x 2 2 + ⋯ + x n 2 n . {\displaystyle x_{\mathrm {rms} }={\sqrt {{{x_{1}}^{2}+{x_{2}}^{2}+\cdots +{x_{n}}^{2}} \over n}}.} See also Tasks for calculating statistical measures in one go moving (sliding window) moving (cumulative) Mean Arithmetic Statistics/Basic Averages/Arithmetic mean Averages/Pythagorean means Averages/Simple moving average Geometric Averages/Pythagorean means Harmonic Averages/Pythagorean means Quadratic Averages/Root mean square Circular Averages/Mean angle Averages/Mean time of day Median Averages/Median Mode Averages/Mode Standard deviation Statistics/Basic Cumulative standard deviation
#min
min
(dup *) :sq ('sq map sum) :sum-sq (('sum-sq 'size) => cleave / sqrt) :rms   (1 2 3 4 5 6 7 8 9 10) rms puts!
http://rosettacode.org/wiki/Babbage_problem
Babbage problem
Charles Babbage, looking ahead to the sorts of problems his Analytical Engine would be able to solve, gave this example: What is the smallest positive integer whose square ends in the digits 269,696? — Babbage, letter to Lord Bowden, 1837; see Hollingdale and Tootill, Electronic Computers, second edition, 1970, p. 125. He thought the answer might be 99,736, whose square is 9,947,269,696; but he couldn't be certain. Task[edit] The task is to find out if Babbage had the right answer — and to do so, as far as your language allows it, in code that Babbage himself would have been able to read and understand. As Babbage evidently solved the task with pencil and paper, a similar efficient solution is preferred. For these purposes, Charles Babbage may be taken to be an intelligent person, familiar with mathematics and with the idea of a computer; he has written the first drafts of simple computer programmes in tabular form. [Babbage Archive Series L]. Motivation The aim of the task is to write a program that is sufficiently clear and well-documented for such a person to be able to read it and be confident that it does indeed solve the specified problem.
#Ada
Ada
-- The program is written in the programming language Ada. The name "Ada" -- has been chosen in honour of your friend, -- Augusta Ada King-Noel, Countess of Lovelace (née Byron). -- -- This is an program to search for the smallest integer X, such that -- (X*X) mod 1_000_000 = 269_696. -- -- In the Ada language, "*" represents the multiplication symbol, "mod" the -- modulo reduction, and the underscore "_" after every third digit in -- literals is supposed to simplify reading numbers for humans. -- Everything written after "--" in a line is a comment for the human, -- and will be ignored by the computer.   with Ada.Text_IO; -- We need this to tell the computer how it will later output its result.   procedure Babbage_Problem is   -- We know that 99_736*99_736 is 9_947_269_696. This implies: -- 1. The smallest X with X*X mod 1_000_000 = 269_696 is at most 99_736. -- 2. The largest square X*X, which the program may have to deal with, -- will be at most 9_947_269_69.   type Number is range 1 .. 99_736*99_736; X: Number := 1; -- X can store numbers between 1 and 99_736*99_736. Computations -- involving X can handle intermediate results in that range. -- Initially the value stored at X is 1. -- When running the program, the value will become 2, 3, 4, etc.   begin -- The program starts running.   -- The computer first squares X, then it truncates the square, such -- that the result is a six-digit number. -- Finally, the computer checks if this number is 269_696. while not (((X*X) mod 1_000_000) = 269_696) loop   -- When the computer goes here, the number was not 269_696. X := X+1; -- So we replace X by X+1, and then go back and try again.   end loop;   -- When the computer eventually goes here, the number is 269_696. -- E.e., the value stored at X is the value we are searching for. -- We still have to print out this value.   Ada.Text_IO.Put_Line(Number'Image(X)); -- Number'Image(X) converts the value stored at X into a string of -- printable characters (more specifically, of digits). -- Ada.Text_IO.Put_Line(...) prints this string, for humans to read. -- I did already run the program, and it did print out 25264. end Babbage_Problem;
http://rosettacode.org/wiki/Averages/Simple_moving_average
Averages/Simple moving average
Computing the simple moving average of a series of numbers. Task[edit] Create a stateful function/class/instance that takes a period and returns a routine that takes a number as argument and returns a simple moving average of its arguments so far. Description A simple moving average is a method for computing an average of a stream of numbers by only averaging the last   P   numbers from the stream,   where   P   is known as the period. It can be implemented by calling an initialing routine with   P   as its argument,   I(P),   which should then return a routine that when called with individual, successive members of a stream of numbers, computes the mean of (up to), the last   P   of them, lets call this   SMA(). The word   stateful   in the task description refers to the need for   SMA()   to remember certain information between calls to it:   The period,   P   An ordered container of at least the last   P   numbers from each of its individual calls. Stateful   also means that successive calls to   I(),   the initializer,   should return separate routines that do   not   share saved state so they could be used on two independent streams of data. Pseudo-code for an implementation of   SMA   is: function SMA(number: N): stateful integer: P stateful list: stream number: average stream.append_last(N) if stream.length() > P: # Only average the last P elements of the stream stream.delete_first() if stream.length() == 0: average = 0 else: average = sum( stream.values() ) / stream.length() return average See also Tasks for calculating statistical measures in one go moving (sliding window) moving (cumulative) Mean Arithmetic Statistics/Basic Averages/Arithmetic mean Averages/Pythagorean means Averages/Simple moving average Geometric Averages/Pythagorean means Harmonic Averages/Pythagorean means Quadratic Averages/Root mean square Circular Averages/Mean angle Averages/Mean time of day Median Averages/Median Mode Averages/Mode Standard deviation Statistics/Basic Cumulative standard deviation
#C
C
#include <stdio.h> #include <stdlib.h> #include <stdarg.h>   typedef struct sma_obj { double sma; double sum; int period; double *values; int lv; } sma_obj_t;   typedef union sma_result { sma_obj_t *handle; double sma; double *values; } sma_result_t;   enum Action { SMA_NEW, SMA_FREE, SMA_VALUES, SMA_ADD, SMA_MEAN }; sma_result_t sma(enum Action action, ...) { va_list vl; sma_result_t r; sma_obj_t *o; double v;   va_start(vl, action); switch(action) { case SMA_NEW: // args: int period r.handle = malloc(sizeof(sma_obj_t)); r.handle->sma = 0.0; r.handle->period = va_arg(vl, int); r.handle->values = malloc(r.handle->period * sizeof(double)); r.handle->lv = 0; r.handle->sum = 0.0; break; case SMA_FREE: // args: sma_obj_t *handle r.handle = va_arg(vl, sma_obj_t *); free(r.handle->values); free(r.handle); r.handle = NULL; break; case SMA_VALUES: // args: sma_obj_t *handle o = va_arg(vl, sma_obj_t *); r.values = o->values; break; case SMA_MEAN: // args: sma_obj_t *handle o = va_arg(vl, sma_obj_t *); r.sma = o->sma; break; case SMA_ADD: // args: sma_obj_t *handle, double value o = va_arg(vl, sma_obj_t *); v = va_arg(vl, double); if ( o->lv < o->period ) { o->values[o->lv++] = v; o->sum += v; o->sma = o->sum / o->lv; } else { o->sum -= o->values[ o->lv % o->period]; o->sum += v; o->sma = o->sum / o->period; o->values[ o->lv % o->period ] = v; o->lv++; } r.sma = o->sma; break; } va_end(vl); return r; }
http://rosettacode.org/wiki/Barnsley_fern
Barnsley fern
A Barnsley fern is a fractal named after British mathematician Michael Barnsley and can be created using an iterated function system (IFS). Task Create this fractal fern, using the following transformations: ƒ1   (chosen 1% of the time) xn + 1 = 0 yn + 1 = 0.16 yn ƒ2   (chosen 85% of the time) xn + 1 = 0.85 xn + 0.04 yn yn + 1 = −0.04 xn + 0.85 yn + 1.6 ƒ3   (chosen 7% of the time) xn + 1 = 0.2 xn − 0.26 yn yn + 1 = 0.23 xn + 0.22 yn + 1.6 ƒ4   (chosen 7% of the time) xn + 1 = −0.15 xn + 0.28 yn yn + 1 = 0.26 xn + 0.24 yn + 0.44. Starting position: x = 0, y = 0
#IS-BASIC
IS-BASIC
100 PROGRAM "Fern.bas" 110 RANDOMIZE 120 SET VIDEO MODE 1:SET VIDEO COLOR 0:SET VIDEO X 40:SET VIDEO Y 27 130 OPEN #101:"video:" 140 DISPLAY #101:AT 1 FROM 1 TO 27 150 SET PALETTE BLACK,GREEN 160 LET MX=16000:LET X,Y=0 170 FOR N=1 TO MX 180 LET P=RND(100) 190 SELECT CASE P 200 CASE IS<=1 210 LET NX=0:LET NY=.16*Y 220 CASE IS<=8 230 LET NX=.2*X-.26*Y:LET NY=.23*X+.22*Y+1.6 240 CASE IS<=15 250 LET NX=-.15*X+.28*Y:LET NY=.26*X+.24*Y+.44 260 CASE ELSE 270 LET NX=.85*X+.04*Y:LET NY=-.04*X+.85*Y+1.6 280 END SELECT 290 LET X=NX:LET Y=NY 300 PLOT X*96+600,Y*96 310 NEXT