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 ...
#.D0.9C.D0.9A-61.2F52
МК-61/52
0 П0 П1 С/П x^2 ИП0 x^2 ИП1 * + ИП1 1 + П1 / КвКор П0 БП 03
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 ...
#Morfa
Morfa
  import morfa.base; import morfa.functional.base;   template <TRange> func rms(d: TRange): float { var count = 1; return sqrt(reduce( (a: float, b: float) { count += 1; return a + b * b; }, d) / count); }   func main(): void { println(rms(1 .. 11)); }  
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....
#Aime
Aime
integer i;   i = sqrt(269696); while (i * i % 1000000 != 269696) { i += 1; }   o_(i, "\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 avera...
#C.23
C#
using System; using System.Collections.Generic; using System.Linq;   namespace SMA { class Program { static void Main(string[] args) { var nums = Enumerable.Range(1, 5).Select(n => (double)n); nums = nums.Concat(nums.Reverse());   var sma3 = SMA(3); var sma5 =...
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) ...
#J
J
require 'plot'   f=: |: 0 ". ];._2 noun define 0 0 0 0.16 0 0 0.01 0.85 -0.04 0.04 0.85 0 1.60 0.85 0.20 0.23 -0.26 0.22 0 1.60 0.07 -0.15 0.26 0.28 0.24 0 0.44 0.07 )   fm=: {&(|: 2 2 $ f) fa=: {&(|: 4 5 { f) prob=: (+/\ 6 { f) I. ?@0:   ifs=: (fa@] + fm@] +/ .* [) prob getPoin...
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 ...
#Nemerle
Nemerle
using System; using System.Console; using System.Math;   module RMS { RMS(x : list[int]) : double { def sum = x.Map(fun (x) {x*x}).FoldLeft(0, _+_); Sqrt((sum :> double) / x.Length) }   Main() : void { WriteLine("RMS of [1 .. 10]: {0:g6}", RMS($[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 ...
#NetRexx
NetRexx
/* NetRexx */ options replace format comments java crossref symbols nobinary   parse arg maxV . if maxV = '' | maxV = '.' then maxV = 10   sum = 0 loop nr = 1 for maxV sum = sum + nr ** 2 end nr rmsD = Math.sqrt(sum / maxV)   say 'RMS of values from 1 to' maxV':' rmsD   return  
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....
#ALGOL_68
ALGOL 68
COMMENT text between pairs of words 'comment' in capitals are for the human reader's information and are ignored by the machine COMMENT   COMMENT Define s to be the integer value 269 696 COMMENT INT s = 269 696;   COMMENT Name a location in the machine's storage area that will be used to ho...
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 avera...
#C.2B.2B
C++
  #include <iostream> #include <stddef.h> #include <assert.h>   using std::cout; using std::endl;   class SMA { public: SMA(unsigned int period) : period(period), window(new double[period]), head(NULL), tail(NULL), total(0) { assert(period >= 1); } ~SMA() { delete[] window; }   // Adds a value to the ave...
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) ...
#Java
Java
import java.awt.*; import java.awt.image.BufferedImage; import javax.swing.*;   public class BarnsleyFern extends JPanel {   BufferedImage img;   public BarnsleyFern() { final int dim = 640; setPreferredSize(new Dimension(dim, dim)); setBackground(Color.white); img = new Buffered...
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 ...
#Nim
Nim
from math import sqrt, sum from sequtils import mapIt   proc qmean(num: seq[float]): float = result = num.mapIt(it * it).sum result = sqrt(result / float(num.len))   echo qmean(@[1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.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 ...
#Oberon-2
Oberon-2
  MODULE QM; IMPORT ML := MathL, Out; VAR nums: ARRAY 10 OF LONGREAL; i: INTEGER;   PROCEDURE Rms(a: ARRAY OF LONGREAL): LONGREAL; VAR i: INTEGER; s: LONGREAL; BEGIN s := 0.0; FOR i := 0 TO LEN(a) - 1 DO s := s + (a[i] * a[i]) END; RETURN ML.Sqrt(s / LEN(a)) END Rms;   BEGIN FOR i := 0 TO LEN(nums) - 1 DO ...
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....
#APL
APL
⍝ We know that 99,736 is a valid answer, so we only need to test the positive integers from 1 up to there: N←⍳99736 ⍝ The SQUARE OF omega is omega times omega: SQUAREOF←{⍵×⍵} ⍝ To say that alpha ENDS IN the six-digit number omega means that alpha divided by 1,000,000 leaves remainder omega...
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 avera...
#Clojure
Clojure
(import '[clojure.lang PersistentQueue])   (defn enqueue-max [q p n] (let [q (conj q n)] (if (<= (count q) p) q (pop q))))   (defn avg [coll] (/ (reduce + coll) (count coll)))   (defn init-moving-avg [p] (let [state (atom PersistentQueue/EMPTY)] (fn [n] (avg (swap! state enqueue-max p 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) ...
#JavaScript
JavaScript
// Barnsley fern fractal //6/17/16 aev function pBarnsleyFern(canvasId, lim) { // DCLs var canvas = document.getElementById(canvasId); var ctx = canvas.getContext("2d"); var w = canvas.width; var h = canvas.height; var x = 0., y = 0., xw = 0., yw = 0., r; // L...
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 ...
#Objeck
Objeck
bundle Default { class Hello { function : Main(args : String[]) ~ Nil { values := [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0]; RootSquareMean(values)->PrintLine(); }   function : native : RootSquareMean(values : Float[]) ~ Float { sum := 0.0; each(i : values) { x :=...
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....
#AppleScript
AppleScript
-- BABBAGE -------------------------------------------------------------------   -- babbage :: Int -> [Int] on babbage(intTests)   script test on toSquare(x) (x * 1000000) + 269696 end toSquare   on |λ|(x) hasIntRoot(toSquare(x)) end |λ| end script   s...
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 avera...
#CoffeeScript
CoffeeScript
  I = (P) -> # The cryptic name "I" follows the problem description; # it returns a function that computes a moving average # of successive values over the period P, using closure # variables to maintain state. cq = circular_queue(P) num_elems = 0 sum = 0   SMA = (n) -> sum += n if num_elems < P...
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) ...
#Julia
Julia
function barnsleyfern(n::Integer) funs = ( (x, y) -> (0, 0.16y), (x, y) -> (0.85x + 0.04y, -0.04x + 0.85y + 1.6), (x, y) -> (0.2x - 0.26y, 0.23x + 0.22y + 1.6), (x, y) -> (-0.15x + 0,28y, 0.26x + 0.24y + 0.44)) rst = Matrix{Float64}(n, 2) rst[1, :] = 0.0 for row in 2: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 ...
#OCaml
OCaml
let rms a = sqrt (Array.fold_left (fun s x -> s +. x*.x) 0.0 a /. float_of_int (Array.length a)) ;;   rms (Array.init 10 (fun i -> float_of_int (i+1))) ;; (* 6.2048368229954285 *)
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 ...
#Oforth
Oforth
10 seq map(#sq) sum 10.0 / sqrt .
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....
#ARM_Assembly
ARM Assembly
    /* ARM assembly Raspberry PI */ /* program babbage.s */   /************************************/ /* Constantes */ /************************************/ .equ STDOUT, 1 @ Linux output console .equ EXIT, 1 @ Linux syscall .equ WRITE, 4 @ Linux syscall   /**********************...
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 avera...
#Common_Lisp
Common Lisp
(defun simple-moving-average (period &aux (sum 0) (count 0) (values (make-list period)) (pointer values)) (setf (rest (last values)) values) ; construct circularity (lambda (n) (when (first pointer) (decf sum (first pointer))) ; subtract old value (incf sum n) ; add new 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) ...
#Kotlin
Kotlin
// version 1.1.0   import java.awt.* import java.awt.image.BufferedImage import javax.swing.*   class BarnsleyFern(private val dim: Int) : JPanel() { private val img: BufferedImage   init { preferredSize = Dimension(dim, dim) background = Color.black img = BufferedImage(dim, dim, Buffere...
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 ...
#ooRexx
ooRexx
call testAverage .array~of(10, 9, 8, 7, 6, 5, 4, 3, 2, 1) call testAverage .array~of(10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0, 0, 0, .11) call testAverage .array~of(30, 10, 20, 30, 40, 50, -100, 4.7, -11e2)   ::routine testAverage use arg list say "list =" list~toString("l", ", ") say "root mean square =" rootmeansqua...
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 ...
#Oz
Oz
declare fun {Square X} X*X end   fun {RMS Xs} {Sqrt {Int.toFloat {FoldL {Map Xs Square} Number.'+' 0}} / {Int.toFloat {Length Xs}}} end in {Show {RMS {List.number 1 10 1}}}
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....
#Arturo
Arturo
n: new 0 while [269696 <> (n^2) % 1000000] -> inc '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 avera...
#Crystal
Crystal
def sma(n) Proc(Float64, Float64) a = Array(Float64).new ->(x : Float64) { a.shift if a.size == n a.push x a.sum / a.size.to_f } end   sma3, sma5 = sma(3), sma(5)   # Copied from the Ruby solution. (1.upto(5).to_a + 5.downto(1).to_a).each do |n| printf "%d: sma3 = %.3f - sma5 = %.3f\n", n, sma3.call(n.to_f), ...
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) ...
#Lambdatalk
Lambdatalk
  {def fern {lambda {:size :sign} {if {> :size 2} then M:size T{* 70 :sign} {fern {* :size 0.5} {- :sign}} T{* {- 70} :sign} M:size T{* {- 70} :sign} {fern {* :size 0.5} :sign} T{* 70 :sign} T{* 7 :sign} {fern {- :size 1} :sign} ...
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 ...
#PARI.2FGP
PARI/GP
RMS(v)={ sqrt(sum(i=1,#v,v[i]^2)/#v) };   RMS(vector(10,i,i))
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 ...
#Perl
Perl
use v5.10.0; sub rms { my $r = 0; $r += $_**2 for @_; sqrt( $r/@_ ); }   say rms(1..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....
#AutoHotkey
AutoHotkey
  ; Give n an initial value n = 519   ; Loop this action while condition is not satisfied while (Mod(n*n, 1000000) != 269696) { ; Increment n n++ }   ; Display n as value msgbox, %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 avera...
#D
D
import std.stdio, std.traits, std.algorithm;   auto sma(T, int period)() pure nothrow @safe { T[period] data = 0; T sum = 0; int index, nFilled;   return (in T v) nothrow @safe @nogc { sum += -data[index] + v; data[index] = v; index = (index + 1) % period; nFilled = min(p...
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) ...
#Liberty_BASIC
Liberty BASIC
nomainwin WindowWidth=800 WindowHeight=600 open "Barnsley Fern" for graphics_nf_nsb as #1 #1 "trapclose [q];down;fill black;flush;color green"   for n = 1 To WindowHeight * 50 r = int(rnd(1)*100) Select Case Case (r>=0) and (r<=84) xn=0.85*x+0.04*y yn=-0.04*x+0.85*y+1.6 Case (r>84) 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 ...
#Phix
Phix
function rms(sequence s) atom sqsum = 0 for i=1 to length(s) do sqsum += power(s[i],2) end for return sqrt(sqsum/length(s)) end function ?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 ...
#Phixmonti
Phixmonti
def rms 0 swap len for get 2 power rot + swap endfor len rot swap / sqrt enddef   0 tolist 10 for 0 put endfor   rms print
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....
#AWK
AWK
  # A comment starts with a "#" and are ignored by the machine. They can be on a # line by themselves or at the end of an executable line. # # A program consists of multiple lines or statements. This program tests # positive integers starting at 1 and terminates when one is found whose square # ends in 269696. # # Th...
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 avera...
#Delphi
Delphi
  program Simple_moving_average;   {$APPTYPE CONSOLE}   type TMovingAverage = record private buffer: TArray<Double>; head: Integer; Capacity: Integer; Count: Integer; sum, fValue: Double; public constructor Create(aCapacity: Integer); function Add(Value: Double): Double; procedure ...
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) ...
#Locomotive_Basic
Locomotive Basic
10 mode 2:ink 0,0:ink 1,18:randomize time 20 scale=38 30 maxpoints=20000: x=0: y=0 40 for z=1 to maxpoints 50 p=rnd*100 60 if p<=1 then nx=0: ny=0.16*y: goto 100 70 if p<=8 then nx=0.2*x-0.26*y: ny=0.23*x+0.22*y+1.6: goto 100 80 if p<=15 then nx=-0.15*x+0.28*y: ny=0.26*x+0.24*y+0.44: goto 100 90 nx=0.85*x+0.04*y: ny=-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 ...
#PHP
PHP
<?php // Created with PHP 7.0   function rms(array $numbers) { $sum = 0;   foreach ($numbers as $number) { $sum += $number**2; }   return sqrt($sum / count($numbers)); }   echo rms(array(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 ...
#Picat
Picat
  rms(Xs) = Y => Sum = sum_of_squares(Xs), N = length(Xs), Y = sqrt(Sum / N).   sum_of_squares(Xs) = Sum => Sum = 0, foreach (X in Xs) Sum := Sum + X * X end.   main => Y = rms(1..10), printf("The root-mean-square of 1..10 is %f\n", Y).  
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....
#BASIC
BASIC
  100 : 110 REM BABBAGE PROBLEM 120 : 130 DEF FN ST(A) = N - INT (A) * INT (A) 140 N = 269696 150 N = N + 1000000 160 R = SQR (N) 170 IF FN ST(R) < > 0 AND N < 999999999 THEN GOTO 150 180 IF N > 999999999 THEN GOTO 210 190 PRINT "SMALLESt NUMBER WHOSE ...
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 avera...
#Dyalect
Dyalect
func avg(xs) { var acc = 0.0 var c = 0 for x in xs { c += 1 acc += x } acc / c }   func sma(p) { var s = [] x => { if s.Length() >= p { s.RemoveAt(0) } s.Insert(s.Length(), x) avg(s) }; }   var nums = Iterator.Concat(1.0..5.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) ...
#Lua
Lua
  g = love.graphics wid, hei = g.getWidth(), g.getHeight()   function choose( i, j ) local r = math.random() if r < .01 then return 0, .16 * j elseif r < .07 then return .2 * i - .26 * j, .23 * i + .22 * j + 1.6 elseif r < .14 then return -.15 * i + .28 * j, .26 * i + .24 * j + .44 else return .85 * i...
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 ...
#PicoLisp
PicoLisp
(scl 5)   (let Lst (1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0) (prinl (format (sqrt (*/ (sum '((N) (*/ N N 1.0)) Lst) 1.0 (length Lst) ) T ) *Scl ) ) )
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 ...
#PL.2FI
PL/I
atest: Proc Options(main); declare A(10) Dec Float(15) static initial (1,2,3,4,5,6,7,8,9,10); declare (n,RMS) Dec Float(15); n = hbound(A,1); RMS = sqrt(sum(A**2)/n); put Skip Data(rms); End;
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....
#Batch_File
Batch File
:: This line is only required to increase the readability of the output by hiding the lines of code being executed @echo off :: Everything between the lines keeps repeating until the answer is found :: The code works by, starting at 1, checking to see if the last 6 digits of the current number squared is equal to 269...
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 avera...
#E
E
pragma.enable("accumulator") def makeMovingAverage(period) { def values := ([null] * period).diverge() var index := 0 var count := 0   def insert(v) { values[index] := v index := (index + 1) %% period count += 1 }   /** Returns the simple moving average of the inputs so f...
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) ...
#Mathematica_.2F_Wolfram_Language
Mathematica / Wolfram Language
  BarnsleyFern[{x_, y_}] := Module[{}, i = RandomInteger[{1, 100}]; If[i <= 1, {xt = 0, yt = 0.16*y}, If[i <= 8, {xt = 0.2*x - 0.26*y, yt = 0.23*x + 0.22*y + 1.6}, If[i <= 15, {xt = -0.15*x + 0.28*y, yt = 0.26*x + 0.24*y + 0.44}, {xt = 0.85*x + 0.04*y, yt = -0.04*x + 0.85*y + 1.6}]]]; {xt, yt}];...
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 ...
#PostScript
PostScript
/findrms{ /x exch def /sum 0 def /i 0 def x length 0 eq{} { x length{ /sum x i get 2 exp sum add def /i i 1 add def }repeat /sum sum x length div sqrt def }ifelse sum == }def   [1 2 3 4 5 6 7 8 9 10] findrms
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 ...
#Potion
Potion
rms = (series) : total = 0.0 series each (x): total += x * x. total /= series length total sqrt .   rms((1, 2, 3, 4, 5, 6, 7, 8, 9, 10)) print
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....
#Befunge
Befunge
1+  ::* "d"::** % "V8":** -! #v_ > > > > > v increment n n*n modulo 1000000 equal to 269696? v if false, loop to right v v"Smallest number whose square ends in 269696 is "0 < else output...
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 avera...
#EchoLisp
EchoLisp
  (lib 'tree) ;; queues operations     (define (make-sma p) (define Q (queue (gensym))) (lambda (item) (q-push Q item) (when (> (queue-length Q) p) (q-pop Q)) (// (for/sum ((x (queue->list Q))) x) (queue-length Q))))    
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) ...
#MiniScript
MiniScript
clear x = 0 y = 0 for i in range(100000) gfx.setPixel 300 + 58 * x, 58 * y, color.green roll = rnd * 100 xp = x if roll < 1 then x = 0 y = 0.16 * y else if roll < 86 then x = 0.85 * x + 0.04 * y y = -0.04 * xp + 0.85 * y + 1.6 else if roll < 93 then x = 0.2 * x - 0.26 * y y = 0.23 * xp + 0.22 * y + 1....
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 ...
#Powerbuilder
Powerbuilder
long ll_x, ll_y, ll_product decimal ld_rms   ll_x = 1 ll_y = 10 DO WHILE ll_x <= ll_y ll_product += ll_x * ll_x ll_x ++ LOOP ld_rms = Sqrt(ll_product / ll_y)   //ld_rms value is 6.20483682299542849
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 ...
#PowerShell
PowerShell
function get-rms([float[]]$nums){ $sqsum=$nums | foreach-object { $_*$_} | measure-object -sum | select-object -expand Sum return [math]::sqrt($sqsum/$nums.count) }   get-rms @(1..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....
#Bracmat
Bracmat
  ( 500:?number {A child knows that 269696 is larger than 500*500, but not by much. It is safe to start the search with 500.} & whl {'whl' is shorthand for 'while'. It announces the evaluation of an expression that is repeated until it fails.} ' ( @(!number*!number:~(?...
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 avera...
#Elena
Elena
import system'routines; import system'collections; import extensions;   class SMA { object thePeriod; object theList;   constructor new(period) { thePeriod := period; theList :=new List(); }   append(n) { theList.append(n);   var count := theList.Length; ...
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) ...
#Nim
Nim
  import nimPNG, random   randomize()   const width = 640 height = 640 minX = -2.1815 maxX = 2.6556 minY = 0.0 maxY = 9.9982 iterations = 1_000_000   var img: array[width * height * 3, char]   proc floatToPixel(x,y:float): tuple[a:int,b:int] = var px = abs(x - minX) / abs(maxX - minX) var py = abs(y ...
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) ...
#Oberon-2
Oberon-2
  MODULE BarnsleyFern; (** Oxford Oberon-2 **)   IMPORT Random, XYplane;   VAR a1, b1, c1, d1, e1, f1, p1: REAL; a2, b2, c2, d2, e2, f2, p2: REAL; a3, b3, c3, d3, e3, f3, p3: REAL; a4, b4, c4, d4, e4, f4, p4: REAL; X, Y: REAL; x0, y0, e: INTEGER;   PROCEDURE Draw; VAR x, y: REAL; xi, eta: INTEGER; rn:...
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 ...
#Processing
Processing
void setup() { float[] numbers = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; print(rms(numbers)); }   float rms(float[] nums) { float mean = 0; for (float n : nums) { mean += sq(n); } mean = sqrt(mean / nums.length); return mean; }
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 ...
#Prolog
Prolog
  :- initialization(main).   rms(Xs, Y) :- sum_of_squares(Xs, 0, Sum), length(Xs, N), Y is sqrt(Sum / N).   sum_of_squares([], Sum, Sum).   sum_of_squares([X|Xs], A, Sum) :- A1 is A + X * X, sum_of_squares(Xs, A1, Sum).   main :- bagof(X, between(1, 10, X), Xs), rms(Xs, Y), format('The r...
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....
#C
C
  // This code is the implementation of Babbage Problem   #include <stdio.h> #include <stdlib.h> #include <limits.h>   int main() { int current = 0, //the current number square; //the square of the current number   //the strategy of take the rest of division by 1e06 is //to take the a number how 6 last digit...
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 avera...
#Elixir
Elixir
$ cat simple-moving-avg.exs #!/usr/bin/env elixir   defmodule Math do def average([]), do: nil def average(enum) do Enum.sum(enum) / length(enum) end end   defmodule SMA do   def sma(l, p \\ 10) do IO.puts("\nSimple moving average(period=#{p}):") Enum.chunk(l, p, 1) |> Enum.map(&(%{"input": &1, ...
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) ...
#PARI.2FGP
PARI/GP
  \\ Barnsley fern fractal \\ 6/17/16 aev pBarnsleyFern(size,lim)={ my(X=List(),Y=X,x=y=xw=yw=0.0,r); print(" *** Barnsley Fern, size=",size," lim=",lim); plotinit(0); plotcolor(0,6); \\green plotscale(0, -3,3, 0,10); plotmove(0, 0,0); for(i=1, lim, r=random(100); if(r<=1, xw=0;yw=0.16*y, if(r<=8, xw=0.2*x-0.26...
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 ...
#PureBasic
PureBasic
NewList MyList() ; To hold a unknown amount of numbers to calculate   If OpenConsole() Define.d result Define i, sum_of_squares   ;Populate a random amounts of numbers to calculate For i=0 To (Random(45)+5) ; max elements is unknown to the program AddElement(MyList()) MyList()=Random(15) ; Put in a ra...
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....
#C.23
C#
namespace Babbage_Problem { class iterateNumbers { public iterateNumbers() { long baseNumberSquared = 0; //the base number multiplied by itself long baseNumber = 0; //the number to be squared, this one will be iterated   do //this sets up the loop ...
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 avera...
#Erlang
Erlang
main() -> SMA3 = sma(3), SMA5 = sma(5), Ns = [1, 2, 3, 4, 5, 5, 4, 3, 2, 1], lists:foreach( fun (N) -> io:format("Added ~b, sma(3) -> ~f, sma(5) -> ~f~n",[N,next(SMA3,N),next(SMA5,N)]) end, Ns), stop(SMA3), stop(SMA5).   sma(W) -> {sma,spawn(?MODULE,loop,[W,[]])}.  ...
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) ...
#Perl
Perl
use Imager;   my $w = 640; my $h = 640;   my $img = Imager->new(xsize => $w, ysize => $h, channels => 3); my $green = Imager::Color->new('#00FF00');   my ($x, $y) = (0, 0);   foreach (1 .. 2e5) { my $r = rand(100); ($x, $y) = do { if ($r <= 1) { ( 0.00 * $x - 0.00 * $y, 0.00 * $x + 0.16 * $y + 0.00) } ...
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 ...
#Python
Python
>>> from math import sqrt >>> def qmean(num): return sqrt(sum(n*n for n in num)/len(num))   >>> qmean(range(1,11)) 6.2048368229954285
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 ...
#Qi
Qi
(define rms R -> (sqrt (/ (APPLY + (MAPCAR * R R)) (length R))))
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....
#C.2B.2B
C++
#include <iostream>   int main( ) { int current = 0 ; while ( ( current * current ) % 1000000 != 269696 ) current++ ; std::cout << "The square of " << current << " is " << (current * current) << " !\n" ; return 0 ; }
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 avera...
#Euler_Math_Toolbox
Euler Math Toolbox
  >n=1000; m=100; x=random(1,n); >x10=fold(x,ones(1,m)/m); >x10=fftfold(x,ones(1,m)/m)[m:n]; // more efficient  
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) ...
#Phix
Phix
-- -- pwa\phix\BarnsleyFern.exw -- ========================= -- with javascript_semantics include pGUI.e Ihandle dlg, canvas cdCanvas cddbuffer, cdcanvas function redraw_cb(Ihandle /*canvas*/, integer /*posx*/, integer /*posy*/) atom x = 0, y = 0 integer {width, height} = IupGetIntInt(canvas, "DRAWSIZE") ...
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 ...
#Quackery
Quackery
[ $ "bigrat.qky" loadfile ] now!   [ [] swap witheach [ unpack 2dup v* join nested join ] ] is squareall ( [ --> [ )   [ dup size n->v rot 0 n->v rot witheach [ unpack v+ ] 2swap v/ ] is arithmean ( [ --> n/d )   [ dip [ squareall arithmean ] vsqrt drop ] is rms...
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 ...
#R
R
RMS <- function(x, na.rm = F) sqrt(mean(x^2, na.rm = na.rm))   RMS(1:10) # [1] 6.204837   RMS(c(NA, 1:10)) # [1] NA   RMS(c(NA, 1:10), na.rm = T) # [1] 6.204837
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....
#Cach.C3.A9_ObjectScript
Caché ObjectScript
BABBAGE ; start at the integer prior to the square root of 269,696 as it has to be at least that big set i = ($piece($zsqr(269696),".",1,1) - 1)  ; piece 1 of . gets the integer portion   ; loop forever, incrementing by one, until we find a square ending in 269696 for { set i = i + 1  ; this will start us at ...
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 avera...
#F.23
F#
let sma period f (list:float list) = let sma_aux queue v = let q = Seq.truncate period (v :: queue) Seq.average q, Seq.toList q List.fold (fun s v -> let avg,state = sma_aux s v f avg state) [] list   printf "sma3: " [ 1.;2.;3.;4.;5.;5.;4.;3.;2.;1.] |> sma 3 (printf "%.2f...
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) ...
#PicoLisp
PicoLisp
`(== 64 64) (seed (in "/dev/urandom" (rd 8))) (scl 20) (de gridX (X) (*/ (+ 320.0 (*/ X 58.18 1.0)) 1.0) ) (de gridY (Y) (*/ (- 640.0 (*/ Y 58.18 1.0)) 1.0) ) (de calc (R X Y) (cond ((< R 1) (list 0 (*/ Y 0.16 1.0))) ((< R 86) (list (+ (*/ 0.85 X 1.0) (*/ 0.04 Y 1.0)) ...
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) ...
#Processing
Processing
void setup() { size(640, 640); background(0, 0, 0); }   float x = 0; float y = 0;   void draw() { for (int i = 0; i < 100000; i++) {   float xt = 0; float yt = 0;   float r = random(100);   if (r <= 1) { xt = 0; yt = 0.16*y; } else if (r <= 8) { xt = 0.20*x - 0.26*y; yt...
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 ...
#Racket
Racket
  #lang racket (define (rms nums) (sqrt (/ (for/sum ([n nums]) (* n n)) (length 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 ...
#Raku
Raku
sub rms(*@nums) { sqrt [+](@nums X** 2) / @nums }   say rms 1..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....
#Clojure
Clojure
; Defines function named babbage? that returns true if the ; square of the provided number leaves a remainder of 269,696 when divided ; by a million (defn babbage? [n] (let [square (* n n)] (= 269696 (mod square 1000000))))   ; Use the above babbage? to find the first positive integer that returns true ; (We're e...
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 avera...
#Factor
Factor
USING: kernel interpolate io locals math.statistics prettyprint random sequences ; IN: rosetta-code.simple-moving-avg   :: I ( P -- quot ) V{ } clone :> v! [ v swap suffix! P short tail* v! ] ;   : sma-add ( quot n -- quot' ) swap tuck call( x x -- x ) ;   : sma-query ( quot -- avg v ) first concat dup mean swa...
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) ...
#PureBasic
PureBasic
EnableExplicit DisableDebugger   DataSection R84:  : Data.d 0.85,0.04,-0.04,0.85,1.6 R91:  : Data.d 0.2,-0.26,0.23,0.22,1.6 R98:  : Data.d -0.15,0.28,0.26,0.24,0.44 R100: : Data.d 0.0,0.0,0.0,0.16,0.0 EndDataSection   Procedure Barnsley(height.i) Define x.d, y.d, xn.d, yn.d, v1.d, v2.d, v3.d, v4.d, v5.d, ...
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 ...
#REXX
REXX
/*REXX program computes and displays the root mean square (RMS) of a number sequence. */ parse arg nums digs show . /*obtain the optional arguments from CL*/ if nums=='' | nums=="," then nums=10 /*Not specified? Then use the default.*/ if digs=='' | digs=="," then digs=50 ...
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....
#COBOL
COBOL
IDENTIFICATION DIVISION. PROGRAM-ID. BABBAGE-PROGRAM. * A line beginning with an asterisk is an explanatory note. * The machine will disregard any such line. DATA DIVISION. WORKING-STORAGE SECTION. * In this part of the program we reserve the storage space we shall * be using for our variables, using a 'PICTURE' clause...
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 avera...
#Fantom
Fantom
  class MovingAverage { Int period Int[] stream   new make (Int period) { this.period = period stream = [,] }   // add number to end of stream and remove numbers from start if // stream is larger than period public Void addNumber (Int number) { stream.add (number) while (stream.size ...
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) ...
#Python
Python
    import random from PIL import Image     class BarnsleyFern(object): def __init__(self, img_width, img_height, paint_color=(0, 150, 0), bg_color=(255, 255, 255)): self.img_width, self.img_height = img_width, img_height self.paint_color = paint_color self.x, self.y = 0, 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 ...
#Ring
Ring
  nums = [1,2,3,4,5,6,7,8,9,10] sum = 0 decimals(5) see "Average = " + average(nums) + nl   func average number for i = 1 to len(number) sum = sum + pow(number[i],2) next x = sqrt(sum / len(number)) return x  
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 ...
#Ruby
Ruby
class Array def quadratic_mean Math.sqrt( self.inject(0.0) {|s, y| s + y*y} / self.length ) end end   class Range def quadratic_mean self.to_a.quadratic_mean end end   (1..10).quadratic_mean # => 6.2048368229954285
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....
#Common_Lisp
Common Lisp
  (defun babbage-test (n) "A generic function for any ending of a number" (when (> n 0) (do* ((i 0 (1+ i)) (d (expt 10 (1+ (truncate (log n) (log 10))))) ) ((= (mod (* i i) d) n) i) )))    
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 avera...
#Forth
Forth
: f+! ( f addr -- ) dup f@ f+ f! ; : ,f0s ( n -- ) falign 0 do 0e f, loop ;   : period @ ; : used cell+ ; : head 2 cells + ; : sum 3 cells + faligned ; : ring ( addr -- faddr ) dup sum float+ swap head @ floats + ;   : update ( fvalue addr -- addr ) dup ring f@ fnegate dup sum f+! fdup dup ring f! d...
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) ...
#QB64
QB64
_Title "Barnsley Fern" Dim As Integer sw, sh sw = 400: sh = 600 Screen _NewImage(sw, sh, 8)   Dim As Long i, ox, oy Dim As Single sRand Dim As Double x, y, x1, y1, sx, sy sx = 60: sy = 59 ox = 180: oy = 4 Randomize Timer   x = 0 y = 0 For i = 1 To 400000 sRand = Rnd Select Case sRand Case Is < 0.01 ...
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) ...
#R
R
## pBarnsleyFern(fn, n, clr, ttl, psz=600): Plot Barnsley fern fractal. ## Where: fn - file name; n - number of dots; clr - color; ttl - plot title; ## psz - picture size. ## 7/27/16 aev pBarnsleyFern <- function(fn, n, clr, ttl, psz=600) { cat(" *** START:", date(), "n=", n, "clr=", clr, "psz=", psz, "\n"); cat(" ...
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 ...
#Run_BASIC
Run BASIC
valueList$ = "1 2 3 4 5 6 7 8 9 10" while word$(valueList$,i +1) <> "" ' grab values from list thisValue = val(word$(valueList$,i +1)) ' turn values into numbers sumSquares = sumSquares + thisValue ^ 2 ' sum up the squares i = i +1 ' wend print "List of...
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 ...
#Rust
Rust
fn root_mean_square(vec: Vec<i32>) -> f32 { let sum_squares = vec.iter().fold(0, |acc, &x| acc + x.pow(2)); return ((sum_squares as f32)/(vec.len() as f32)).sqrt(); }   fn main() { let vec = (1..11).collect(); println!("The root mean square is: {}", root_mean_square(vec)); }
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....
#Component_Pascal
Component Pascal
  MODULE BabbageProblem; IMPORT StdLog;   PROCEDURE Do*; VAR i: LONGINT; BEGIN i := 2; WHILE (i * i MOD 1000000) # 269696 DO IF i MOD 10 = 4 THEN INC(i,2) ELSE INC(i,8) END END; StdLog.Int(i) END Do;   END BabbageProblem.  
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 avera...
#Fortran
Fortran
program Movavg implicit none   integer :: i   write (*, "(a)") "SIMPLE MOVING AVERAGE: PERIOD = 3"   do i = 1, 5 write (*, "(a, i2, a, f8.6)") "Next number:", i, " sma = ", sma(real(i)) end do do i = 5, 1, -1 write (*, "(a, i2, a, f8.6)") "Next number:", i, " sma = ", sma(real(i)) end do   co...
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) ...
#Racket
Racket
#lang racket   (require racket/draw)   (define fern-green (make-color #x32 #xCD #x32 0.66))   (define (fern dc n-iterations w h) (for/fold ((x #i0) (y #i0)) ((i n-iterations)) (define-values (x′ y′) (let ((r (random))) (cond [(<= r 0.01) (values 0 ...