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/Zero_to_the_zero_power
Zero to the zero power
Some computer programming languages are not exactly consistent   (with other computer programming languages)   when   raising zero to the zeroth power:     00 Task Show the results of raising   zero   to the   zeroth   power. If your computer language objects to     0**0     or     0^0     at compile time, ...
#ALGOL_68
ALGOL 68
print( ( 0 ^ 0, newline ) )  
http://rosettacode.org/wiki/Arithmetic_evaluation
Arithmetic evaluation
Create a program which parses and evaluates arithmetic expressions. Requirements An abstract-syntax tree (AST) for the expression must be created from parsing the input. The AST must be used in evaluation, also, so the input may not be directly evaluated (e.g. by calling eval or a similar language feature.) The ...
#J
J
parse=:parse_parser_ eval=:monad define 'gerund structure'=:y gerund@.structure )   coclass 'parser' classify=: '$()*/+-'&(((>:@#@[ # 2:) #: 2 ^ i.)&;:)   rules=: '' patterns=: ,"0 assert 1   addrule=: dyad define rules=: rules,;:x patterns=: patterns,+./@classify"1 y )   'Term' addrule '$()', '0', '...
http://rosettacode.org/wiki/Archimedean_spiral
Archimedean spiral
The Archimedean spiral is a spiral named after the Greek mathematician Archimedes. An Archimedean spiral can be described by the equation: r = a + b θ {\displaystyle \,r=a+b\theta } with real numbers a and b. Task Draw an Archimedean spiral.
#Nim
Nim
import math   import gintro/[glib, gobject, gtk, gio, cairo]   const   Width = 601 Height = 601   Limit = 12 * math.PI   Origin = (x: float(Width div 2), y: float(Height div 2)) B = floor((Width div 2) / Limit)   #------------------------------------------------------------------------------------------------...
http://rosettacode.org/wiki/Archimedean_spiral
Archimedean spiral
The Archimedean spiral is a spiral named after the Greek mathematician Archimedes. An Archimedean spiral can be described by the equation: r = a + b θ {\displaystyle \,r=a+b\theta } with real numbers a and b. Task Draw an Archimedean spiral.
#PARI.2FGP
PARI/GP
  \\ The Archimedean spiral \\ ArchiSpiral() - Where: lps is a number of loops, c is a direction 0/1 \\ (counter-clockwise/clockwise). 6/6/16 aev \\ Note: cartes2() can be found here on \\ http://rosettacode.org/wiki/Polyspiral#PARI.2FGP page. ArchiSpiral(size,lps,c=0)={ my(a=.0,ai=.1,r=.0,ri=.1,as=lps*2*Pi,n=as/ai,...
http://rosettacode.org/wiki/100_doors
100 doors
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it). The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it. The third...
#Arturo
Arturo
isOpen: map 1..101 => false   loop 1..100 'pass -> loop (range.step:pass pass 100) 'door [ isOpen\[door]: not? isOpen\[door] ]   loop 1..100 'x -> if isOpen\[x] [ print ["Door" x "is open."] ]
http://rosettacode.org/wiki/Arrays
Arrays
This task is about arrays. For hashes or associative arrays, please see Creating an Associative Array. For a definition and in-depth discussion of what an array is, see Array. Task Show basic array syntax in your language. Basically, create an array, assign a value to it, and retrieve an element   (if available,...
#COBOL
COBOL
IDENTIFICATION DIVISION. PROGRAM-ID. arrays.   DATA DIVISION. WORKING-STORAGE SECTION. 01 fixed-length-table. 03 fixed-table-elt PIC X OCCURS 5 TIMES.   01 table-length PIC 9(5) VALUE 1. 01 variable-length-table. 03 variable-ta...
http://rosettacode.org/wiki/Arithmetic/Complex
Arithmetic/Complex
A   complex number   is a number which can be written as: a + b × i {\displaystyle a+b\times i} (sometimes shown as: b + a × i {\displaystyle b+a\times i} where   a {\displaystyle a}   and   b {\displaystyle b}   are real numbers,   and   i {\displaystyle i}   is   √ -1  Typica...
#J
J
x=: 1j1 y=: 3.14159j1.2 x+y NB. addition 4.14159j2.2 x*y NB. multiplication 1.94159j4.34159  %x NB. inversion 0.5j_0.5 -x NB. negation _1j_1 +x NB. (complex) conjugation 1j_1  
http://rosettacode.org/wiki/Arithmetic/Rational
Arithmetic/Rational
Task Create a reasonably complete implementation of rational arithmetic in the particular language using the idioms of the language. Example Define a new type called frac with binary operator "//" of two integers that returns a structure made up of the numerator and the denominator (as per a rational number). Fur...
#Lingo
Lingo
-- parent script "Frac" property num property denom   ---------------------------------------- -- @constructor -- @param {integer} numerator -- @param {integer} [denominator=1] ---------------------------------------- on new (me, numerator, denominator) if voidP(denominator) then denominator = 1 if denominator=0 th...
http://rosettacode.org/wiki/Arithmetic-geometric_mean
Arithmetic-geometric mean
This page uses content from Wikipedia. The original article was at Arithmetic-geometric mean. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) Task Write a function to compute the arithmetic-geomet...
#Nim
Nim
import math   proc agm(a, g: float,delta: float = 1.0e-15): float = var aNew: float = 0 aOld: float = a gOld: float = g while (abs(aOld - gOld) > delta): aNew = 0.5 * (aOld + gOld) gOld = sqrt(aOld * gOld) aOld = aNew result = aOld   echo agm(1.0,1.0/sqrt(2.0))
http://rosettacode.org/wiki/Arithmetic-geometric_mean
Arithmetic-geometric mean
This page uses content from Wikipedia. The original article was at Arithmetic-geometric mean. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) Task Write a function to compute the arithmetic-geomet...
#Oberon-2
Oberon-2
  MODULE Agm; IMPORT Math := LRealMath, Out;   CONST epsilon = 1.0E-15;   PROCEDURE Of*(a,g: LONGREAL): LONGREAL; VAR na,ng,og: LONGREAL; BEGIN na := a; ng := g; LOOP og := ng; ng := Math.sqrt(na * ng); na := (na + og) * 0.5; IF na - ng <= epsilon THEN EXIT END END; RETURN ng; END Of;  ...
http://rosettacode.org/wiki/Zero_to_the_zero_power
Zero to the zero power
Some computer programming languages are not exactly consistent   (with other computer programming languages)   when   raising zero to the zeroth power:     00 Task Show the results of raising   zero   to the   zeroth   power. If your computer language objects to     0**0     or     0^0     at compile time, ...
#APL
APL
0*0 1
http://rosettacode.org/wiki/Zero_to_the_zero_power
Zero to the zero power
Some computer programming languages are not exactly consistent   (with other computer programming languages)   when   raising zero to the zeroth power:     00 Task Show the results of raising   zero   to the   zeroth   power. If your computer language objects to     0**0     or     0^0     at compile time, ...
#AppleScript
AppleScript
return 0 ^ 0
http://rosettacode.org/wiki/Arithmetic_evaluation
Arithmetic evaluation
Create a program which parses and evaluates arithmetic expressions. Requirements An abstract-syntax tree (AST) for the expression must be created from parsing the input. The AST must be used in evaluation, also, so the input may not be directly evaluated (e.g. by calling eval or a similar language feature.) The ...
#Java
Java
import java.util.Stack;   public class ArithmeticEvaluation {   public interface Expression { BigRational eval(); }   public enum Parentheses {LEFT}   public enum BinaryOperator { ADD('+', 1), SUB('-', 1), MUL('*', 2), DIV('/', 2);   public final char symb...
http://rosettacode.org/wiki/Archimedean_spiral
Archimedean spiral
The Archimedean spiral is a spiral named after the Greek mathematician Archimedes. An Archimedean spiral can be described by the equation: r = a + b θ {\displaystyle \,r=a+b\theta } with real numbers a and b. Task Draw an Archimedean spiral.
#Perl
Perl
use Imager; use constant PI => 3.14159265;   my ($w, $h) = (400, 400); my $img = Imager->new(xsize => $w, ysize => $h);   for ($theta = 0; $theta < 52*PI; $theta += 0.025) { $x = $w/2 + $theta * cos($theta/PI); $y = $h/2 + $theta * sin($theta/PI); $img->setpixel(x => $x, y => $y, color => '#FF00FF'); }   $i...
http://rosettacode.org/wiki/Archimedean_spiral
Archimedean spiral
The Archimedean spiral is a spiral named after the Greek mathematician Archimedes. An Archimedean spiral can be described by the equation: r = a + b θ {\displaystyle \,r=a+b\theta } with real numbers a and b. Task Draw an Archimedean spiral.
#Phix
Phix
-- -- demo\rosetta\Archimedean_spiral.exw -- =================================== -- with javascript_semantics include pGUI.e Ihandle dlg, canvas cdCanvas cddbuffer, cdcanvas function redraw_cb(Ihandle /*ih*/) integer {w, h} = IupGetIntInt(canvas, "DRAWSIZE"), a = 0, b = 5, cx = floor(w/2), cy = floor(...
http://rosettacode.org/wiki/100_doors
100 doors
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it). The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it. The third...
#Astro
Astro
var doors = falses(100)   for a in 1..100: for b in a..a..100: doors[b] = not doors[b]   for a in 1..100: print "Door $a is ${(doors[a]) ? 'open.': 'closed.'}"  
http://rosettacode.org/wiki/Arrays
Arrays
This task is about arrays. For hashes or associative arrays, please see Creating an Associative Array. For a definition and in-depth discussion of what an array is, see Array. Task Show basic array syntax in your language. Basically, create an array, assign a value to it, and retrieve an element   (if available,...
#CoffeeScript
CoffeeScript
array1 = [] array1[0] = "Dillenidae" array1[1] = "animus" array1[2] = "Kona" alert "Elements of array1: " + array1 # Dillenidae,animus,Kona   array2 = ["Cepphus", "excreta", "Gansu"] alert "Value of array2[1]: " + array2[1] # excreta
http://rosettacode.org/wiki/Arithmetic/Complex
Arithmetic/Complex
A   complex number   is a number which can be written as: a + b × i {\displaystyle a+b\times i} (sometimes shown as: b + a × i {\displaystyle b+a\times i} where   a {\displaystyle a}   and   b {\displaystyle b}   are real numbers,   and   i {\displaystyle i}   is   √ -1  Typica...
#Java
Java
public class Complex { public final double real; public final double imag;   public Complex() { this(0, 0); }   public Complex(double r, double i) { real = r; imag = i; }   public Complex add(Complex b) { return new Complex(this.real + b.real, this.imag + b.im...
http://rosettacode.org/wiki/Arithmetic/Rational
Arithmetic/Rational
Task Create a reasonably complete implementation of rational arithmetic in the particular language using the idioms of the language. Example Define a new type called frac with binary operator "//" of two integers that returns a structure made up of the numerator and the denominator (as per a rational number). Fur...
#Lua
Lua
function gcd(a,b) return a == 0 and b or gcd(b % a, a) end   do local function coerce(a, b) if type(a) == "number" then return rational(a, 1), b end if type(b) == "number" then return a, rational(b, 1) end return a, b end rational = setmetatable({ __add = function(a, b) local a, b = coerce(a, ...
http://rosettacode.org/wiki/Arithmetic-geometric_mean
Arithmetic-geometric mean
This page uses content from Wikipedia. The original article was at Arithmetic-geometric mean. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) Task Write a function to compute the arithmetic-geomet...
#Objeck
Objeck
  class ArithmeticMean { function : Amg(a : Float, g : Float) ~ Nil { a1 := a; g1 := g; while((a1-g1)->Abs() >= Float->Power(10, -14)) { tmp := (a1+g1)/2.0; g1 := Float->SquareRoot(a1*g1); a1 := tmp; }; a1->PrintLine(); }   function : Main(args : String[]) ~ Nil { A...
http://rosettacode.org/wiki/Arithmetic-geometric_mean
Arithmetic-geometric mean
This page uses content from Wikipedia. The original article was at Arithmetic-geometric mean. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) Task Write a function to compute the arithmetic-geomet...
#OCaml
OCaml
let rec agm a g tol = if tol > abs_float (a -. g) then a else agm (0.5*.(a+.g)) (sqrt (a*.g)) tol   let _ = Printf.printf "%.16f\n" (agm 1.0 (sqrt 0.5) 1e-15)
http://rosettacode.org/wiki/Zero_to_the_zero_power
Zero to the zero power
Some computer programming languages are not exactly consistent   (with other computer programming languages)   when   raising zero to the zeroth power:     00 Task Show the results of raising   zero   to the   zeroth   power. If your computer language objects to     0**0     or     0^0     at compile time, ...
#Applesoft_BASIC
Applesoft BASIC
]? 0^0 1
http://rosettacode.org/wiki/Zero_to_the_zero_power
Zero to the zero power
Some computer programming languages are not exactly consistent   (with other computer programming languages)   when   raising zero to the zeroth power:     00 Task Show the results of raising   zero   to the   zeroth   power. If your computer language objects to     0**0     or     0^0     at compile time, ...
#Arturo
Arturo
print 0 ^ 0 print 0.0 ^ 0
http://rosettacode.org/wiki/Arithmetic_evaluation
Arithmetic evaluation
Create a program which parses and evaluates arithmetic expressions. Requirements An abstract-syntax tree (AST) for the expression must be created from parsing the input. The AST must be used in evaluation, also, so the input may not be directly evaluated (e.g. by calling eval or a similar language feature.) The ...
#JavaScript
JavaScript
function evalArithmeticExp(s) { s = s.replace(/\s/g,'').replace(/^\+/,''); var rePara = /\([^\(\)]*\)/; var exp = s.match(rePara);   while (exp = s.match(rePara)) { s = s.replace(exp[0], evalExp(exp[0])); } return evalExp(s);   function evalExp(s) { s = s.replace(/[\(\)]/g,''); var reMD = /\d+...
http://rosettacode.org/wiki/Archimedean_spiral
Archimedean spiral
The Archimedean spiral is a spiral named after the Greek mathematician Archimedes. An Archimedean spiral can be described by the equation: r = a + b θ {\displaystyle \,r=a+b\theta } with real numbers a and b. Task Draw an Archimedean spiral.
#Processing
Processing
float x, y; float theta; float rotation;   void setup() { size(300, 300); theta = 0; rotation = 0.1; background(255); }   void draw() { translate(width/2.0, height/2.0); x = theta*cos(theta/PI); y = theta*sin(theta/PI); point(x, y); theta = theta + rotation; // check restart if (x>width/2.0) f...
http://rosettacode.org/wiki/Archimedean_spiral
Archimedean spiral
The Archimedean spiral is a spiral named after the Greek mathematician Archimedes. An Archimedean spiral can be described by the equation: r = a + b θ {\displaystyle \,r=a+b\theta } with real numbers a and b. Task Draw an Archimedean spiral.
#PureBasic
PureBasic
#MAXLOOP = 7*360 #XCENTER = 640/2 #YCENTER = 480/2 #SCALAR = 200   If OpenWindow(0, 100, 200, 640, 480, "Archimedean spiral") If CreateImage(0, 640, 480,24,RGB(255,255,255)) If StartDrawing(ImageOutput(0)) i.f=0.0 While i<=#MAXLOOP x.f=#XCENTER+Cos(Radian(i))*#SCALAR*i/#M...
http://rosettacode.org/wiki/Zeckendorf_number_representation
Zeckendorf number representation
Just as numbers can be represented in a positional notation as sums of multiples of the powers of ten (decimal) or two (binary); all the positive integers can be represented as the sum of one or zero times the distinct members of the Fibonacci series. Recall that the first six distinct Fibonacci numbers are: 1, 2, 3, ...
#11l
11l
V n = 20 F z(=n) I n == 0 R [0] V fib = [2, 1] L fib[0] < n fib = [sum(fib[0.<2])] [+] fib [Int] dig L(f) fib I f <= n dig [+]= 1 n -= f E dig [+]= 0 R I dig[0] {dig} E dig[1..]   L(i) 0..n print(‘#3: #8’.format(i, z(i).map(d -> String(d)).join(‘’)...
http://rosettacode.org/wiki/100_doors
100 doors
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it). The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it. The third...
#Asymptote
Asymptote
for(int i = 1; i < 100; ++i) { if (i % i^2 < 11) { write("Door ", i^2, suffix=none); write(" is open"); } }
http://rosettacode.org/wiki/Arrays
Arrays
This task is about arrays. For hashes or associative arrays, please see Creating an Associative Array. For a definition and in-depth discussion of what an array is, see Array. Task Show basic array syntax in your language. Basically, create an array, assign a value to it, and retrieve an element   (if available,...
#ColdFusion
ColdFusion
<cfset arr1 = ArrayNew(1)>
http://rosettacode.org/wiki/Arithmetic/Complex
Arithmetic/Complex
A   complex number   is a number which can be written as: a + b × i {\displaystyle a+b\times i} (sometimes shown as: b + a × i {\displaystyle b+a\times i} where   a {\displaystyle a}   and   b {\displaystyle b}   are real numbers,   and   i {\displaystyle i}   is   √ -1  Typica...
#JavaScript
JavaScript
function Complex(r, i) { this.r = r; this.i = i; }   Complex.add = function() { var num = arguments[0];   for(var i = 1, ilim = arguments.length; i < ilim; i += 1){ num.r += arguments[i].r; num.i += arguments[i].i; }   return num; }   Complex.multiply = function() { var num = arguments[0];   for(var i = 1, ...
http://rosettacode.org/wiki/Arithmetic/Rational
Arithmetic/Rational
Task Create a reasonably complete implementation of rational arithmetic in the particular language using the idioms of the language. Example Define a new type called frac with binary operator "//" of two integers that returns a structure made up of the numerator and the denominator (as per a rational number). Fur...
#M2000_Interpreter
M2000 Interpreter
  Class Rational { \\ this is a compact version for this task numerator as decimal, denominator as decimal gcd=lambda->0 lcm=lambda->0 operator "+" { Read l denom=.lcm(l.denominator, .denominator) .numerator<=denom/l.denominator*l.numerator+denom/.denominat...
http://rosettacode.org/wiki/Arithmetic-geometric_mean
Arithmetic-geometric mean
This page uses content from Wikipedia. The original article was at Arithmetic-geometric mean. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) Task Write a function to compute the arithmetic-geomet...
#Oforth
Oforth
: agm \ a b -- m while( 2dup <> ) [ 2dup + 2 / -rot * sqrt ] drop ;
http://rosettacode.org/wiki/Arithmetic-geometric_mean
Arithmetic-geometric mean
This page uses content from Wikipedia. The original article was at Arithmetic-geometric mean. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) Task Write a function to compute the arithmetic-geomet...
#OOC
OOC
  import math // import for sqrt() function   amean: func (x: Double, y: Double) -> Double { (x + y) / 2. } gmean: func (x: Double, y: Double) -> Double { sqrt(x * y) } agm: func (a: Double, g: Double) -> Double { while ((a - g) abs() > pow(10, -12)) { (a1, g1) := (amean(a, g), gmean(a, g)) (a, g) = (a1, ...
http://rosettacode.org/wiki/Zero_to_the_zero_power
Zero to the zero power
Some computer programming languages are not exactly consistent   (with other computer programming languages)   when   raising zero to the zeroth power:     00 Task Show the results of raising   zero   to the   zeroth   power. If your computer language objects to     0**0     or     0^0     at compile time, ...
#Asymptote
Asymptote
write("0 ^ 0 = ", 0 ** 0);
http://rosettacode.org/wiki/Zero_to_the_zero_power
Zero to the zero power
Some computer programming languages are not exactly consistent   (with other computer programming languages)   when   raising zero to the zeroth power:     00 Task Show the results of raising   zero   to the   zeroth   power. If your computer language objects to     0**0     or     0^0     at compile time, ...
#AutoHotkey
AutoHotkey
MsgBox % 0 ** 0
http://rosettacode.org/wiki/Arithmetic_evaluation
Arithmetic evaluation
Create a program which parses and evaluates arithmetic expressions. Requirements An abstract-syntax tree (AST) for the expression must be created from parsing the input. The AST must be used in evaluation, also, so the input may not be directly evaluated (e.g. by calling eval or a similar language feature.) The ...
#jq
jq
def star(E): (E | star(E)) // .; def plus(E): E | (plus(E) // . ); def optional(E): E // .; def amp(E): . as $in | E | $in; def neg(E): select( [E] == [] );
http://rosettacode.org/wiki/Arithmetic_evaluation
Arithmetic evaluation
Create a program which parses and evaluates arithmetic expressions. Requirements An abstract-syntax tree (AST) for the expression must be created from parsing the input. The AST must be used in evaluation, also, so the input may not be directly evaluated (e.g. by calling eval or a similar language feature.) The ...
#Jsish
Jsish
/* Arithmetic evaluation, in Jsish */ function evalArithmeticExp(s) { s = s.replace(/\s/g,'').replace(/^\+/,''); var rePara = /\([^\(\)]*\)/; var exp;   function evalExp(s) { s = s.replace(/[\(\)]/g,''); var reMD = /[0-9]+\.?[0-9]*\s*[\*\/]\s*[+-]?[0-9]+\.?[0-9]*/; var reM = /\*/...
http://rosettacode.org/wiki/Archimedean_spiral
Archimedean spiral
The Archimedean spiral is a spiral named after the Greek mathematician Archimedes. An Archimedean spiral can be described by the equation: r = a + b θ {\displaystyle \,r=a+b\theta } with real numbers a and b. Task Draw an Archimedean spiral.
#Python
Python
from turtle import * from math import * color("blue") down() for i in range(200): t = i / 20 * pi x = (1 + 5 * t) * cos(t) y = (1 + 5 * t) * sin(t) goto(x, y) up() done()
http://rosettacode.org/wiki/Archimedean_spiral
Archimedean spiral
The Archimedean spiral is a spiral named after the Greek mathematician Archimedes. An Archimedean spiral can be described by the equation: r = a + b θ {\displaystyle \,r=a+b\theta } with real numbers a and b. Task Draw an Archimedean spiral.
#Quackery
Quackery
[ $ "turtleduck.qky" loadfile ] now! turtle 0 n->v 900 times [ 2dup walk 1 20 v+ 1 36 turn ] 2drop
http://rosettacode.org/wiki/Archimedean_spiral
Archimedean spiral
The Archimedean spiral is a spiral named after the Greek mathematician Archimedes. An Archimedean spiral can be described by the equation: r = a + b θ {\displaystyle \,r=a+b\theta } with real numbers a and b. Task Draw an Archimedean spiral.
#R
R
with(list(s=seq(0, 10 * pi, length.out=500)), plot((1 + s) * exp(1i * s), type="l"))
http://rosettacode.org/wiki/Zeckendorf_number_representation
Zeckendorf number representation
Just as numbers can be represented in a positional notation as sums of multiples of the powers of ten (decimal) or two (binary); all the positive integers can be represented as the sum of one or zero times the distinct members of the Fibonacci series. Recall that the first six distinct Fibonacci numbers are: 1, 2, 3, ...
#360_Assembly
360 Assembly
* Zeckendorf number representation 04/04/2017 ZECKEN CSECT USING ZECKEN,R13 base register B 72(R15) skip savearea DC 17F'0' savearea STM R14,R12,12(R13) save previous context ST R13,4(R15) link backward ...
http://rosettacode.org/wiki/Zeckendorf_number_representation
Zeckendorf number representation
Just as numbers can be represented in a positional notation as sums of multiples of the powers of ten (decimal) or two (binary); all the positive integers can be represented as the sum of one or zero times the distinct members of the Fibonacci series. Recall that the first six distinct Fibonacci numbers are: 1, 2, 3, ...
#Action.21
Action!
PROC Encode(INT x CHAR ARRAY s) INT ARRAY fib(22)= [1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765 10946 17711 28657] INT i BYTE append   IF x=0 THEN s(0)=1 s(1)='0 RETURN FI   i=21 append=0 s(0)=0 WHILE i>=0 DO IF x>=fib(i) THEN x==-fib(i) s(0)==+...
http://rosettacode.org/wiki/100_doors
100 doors
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it). The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it. The third...
#ATS
ATS
  #include "share/atspre_staload.hats"   implement main0((*void*)) = let // var A = @[bool][100](false) val A = $UNSAFE.cast{arrayref(bool,100)}(addr@A) // fnx loop ( pass: intGte(0) ) : void = if pass < 100 then loop2 (pass, pass) // end of [if] and loop2 ( pass: natLt(100), door: intGte(0) ) : void = if...
http://rosettacode.org/wiki/Arrays
Arrays
This task is about arrays. For hashes or associative arrays, please see Creating an Associative Array. For a definition and in-depth discussion of what an array is, see Array. Task Show basic array syntax in your language. Basically, create an array, assign a value to it, and retrieve an element   (if available,...
#Common_Lisp
Common Lisp
(let ((array (make-array 10))) (setf (aref array 0) 1 (aref array 1) 3) (print array))
http://rosettacode.org/wiki/Arithmetic/Complex
Arithmetic/Complex
A   complex number   is a number which can be written as: a + b × i {\displaystyle a+b\times i} (sometimes shown as: b + a × i {\displaystyle b+a\times i} where   a {\displaystyle a}   and   b {\displaystyle b}   are real numbers,   and   i {\displaystyle i}   is   √ -1  Typica...
#jq
jq
def real(z): if (z|type) == "number" then z else z[0] end;   def imag(z): if (z|type) == "number" then 0 else z[1] end;   def plus(x; y): if (x|type) == "number" then if (y|type) == "number" then [ x+y, 0 ] else [ x + y[0], y[1]] end elif (y|type) == "number" then plus(y;x) else [ x[0]...
http://rosettacode.org/wiki/Arithmetic/Rational
Arithmetic/Rational
Task Create a reasonably complete implementation of rational arithmetic in the particular language using the idioms of the language. Example Define a new type called frac with binary operator "//" of two integers that returns a structure made up of the numerator and the denominator (as per a rational number). Fur...
#Maple
Maple
  > a := 3 / 5; a := 3/5   > numer( a ); 3   > denom( a ); 5  
http://rosettacode.org/wiki/Arithmetic-geometric_mean
Arithmetic-geometric mean
This page uses content from Wikipedia. The original article was at Arithmetic-geometric mean. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) Task Write a function to compute the arithmetic-geomet...
#ooRexx
ooRexx
numeric digits 20 say agm(1, 1/rxcalcsqrt(2,16))   ::routine agm use strict arg a, g numeric digits 20   a1 = a g1 = g   loop while abs(a1 - g1) >= 1e-14 temp = (a1 + g1)/2 g1 = rxcalcsqrt(a1*g1,16) a1 = temp end return a1+0   ::requires rxmath LIBRARY
http://rosettacode.org/wiki/Arithmetic-geometric_mean
Arithmetic-geometric mean
This page uses content from Wikipedia. The original article was at Arithmetic-geometric mean. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) Task Write a function to compute the arithmetic-geomet...
#PARI.2FGP
PARI/GP
agm(1,1/sqrt(2))
http://rosettacode.org/wiki/Zero_to_the_zero_power
Zero to the zero power
Some computer programming languages are not exactly consistent   (with other computer programming languages)   when   raising zero to the zeroth power:     00 Task Show the results of raising   zero   to the   zeroth   power. If your computer language objects to     0**0     or     0^0     at compile time, ...
#AWK
AWK
  # syntax: GAWK -f ZERO_TO_THE_ZERO_POWER.AWK BEGIN { print(0 ^ 0) exit(0) }  
http://rosettacode.org/wiki/Zero_to_the_zero_power
Zero to the zero power
Some computer programming languages are not exactly consistent   (with other computer programming languages)   when   raising zero to the zeroth power:     00 Task Show the results of raising   zero   to the   zeroth   power. If your computer language objects to     0**0     or     0^0     at compile time, ...
#BaCon
BaCon
PRINT POW(0, 0)
http://rosettacode.org/wiki/Arithmetic_evaluation
Arithmetic evaluation
Create a program which parses and evaluates arithmetic expressions. Requirements An abstract-syntax tree (AST) for the expression must be created from parsing the input. The AST must be used in evaluation, also, so the input may not be directly evaluated (e.g. by calling eval or a similar language feature.) The ...
#Julia
Julia
julia> expr="2 * (3 -1) + 2 * 5" "2 * (3 -1) + 2 * 5"   julia> parsed = parse(expr) #Julia provides low-level access to language parser for AST/Expr creation :(+(*(2,-(3,1)),*(2,5)))   julia> t = typeof(parsed) Expr   julia> names(t) #shows type fields (:head,:args,:typ)   julia> parsed.args #Inspect our 'Expr' type in...
http://rosettacode.org/wiki/Archimedean_spiral
Archimedean spiral
The Archimedean spiral is a spiral named after the Greek mathematician Archimedes. An Archimedean spiral can be described by the equation: r = a + b θ {\displaystyle \,r=a+b\theta } with real numbers a and b. Task Draw an Archimedean spiral.
#Racket
Racket
#lang racket/base (require plot racket/math)   ;; x and y bounds set to centralise the circle (define (archemedian-spiral-renderer2d a b θ/τ-max #:samples (samples (line-samples))) (define (f θ) (+ a (* b θ))) (define max-dim (+ a (* θ/τ-max 2 pi b))) (polar f ...
http://rosettacode.org/wiki/Archimedean_spiral
Archimedean spiral
The Archimedean spiral is a spiral named after the Greek mathematician Archimedes. An Archimedean spiral can be described by the equation: r = a + b θ {\displaystyle \,r=a+b\theta } with real numbers a and b. Task Draw an Archimedean spiral.
#Raku
Raku
use Image::PNG::Portable;   my ($w, $h) = (400, 400);   my $png = Image::PNG::Portable.new: :width($w), :height($h);   (0, .025 ... 52*π).race.map: -> \Θ { $png.set: |((cis( Θ / π ) * Θ).reals »+« ($w/2, $h/2))».Int, 255, 0, 255; }   $png.write: 'Archimedean-spiral-perl6.png';
http://rosettacode.org/wiki/Zeckendorf_number_representation
Zeckendorf number representation
Just as numbers can be represented in a positional notation as sums of multiples of the powers of ten (decimal) or two (binary); all the positive integers can be represented as the sum of one or zero times the distinct members of the Fibonacci series. Recall that the first six distinct Fibonacci numbers are: 1, 2, 3, ...
#Ada
Ada
with Ada.Text_IO, Ada.Strings.Unbounded;   procedure Print_Zeck is   function Zeck_Increment(Z: String) return String is begin if Z="" then return "1"; elsif Z(Z'Last) = '1' then return Zeck_Increment(Z(Z'First .. Z'Last-1)) & '0'; elsif Z(Z'Last-1) = '0' then return Z(Z'First .. Z'Last-1...
http://rosettacode.org/wiki/100_doors
100 doors
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it). The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it. The third...
#AutoHotkey
AutoHotkey
Loop, 100 Door%A_Index% := "closed"   Loop, 100 { x := A_Index, y := A_Index While (x <= 100) { CurrentDoor := Door%x% If CurrentDoor contains closed { Door%x% := "open" x += y } else if CurrentDoor contains open { Door%x% := "closed" x += y } } }   Loop, 10...
http://rosettacode.org/wiki/Arrays
Arrays
This task is about arrays. For hashes or associative arrays, please see Creating an Associative Array. For a definition and in-depth discussion of what an array is, see Array. Task Show basic array syntax in your language. Basically, create an array, assign a value to it, and retrieve an element   (if available,...
#Component_Pascal
Component Pascal
  MODULE TestArray; (* Implemented in BlackBox Component Builder *)   IMPORT Out;   (* Static array *)   PROCEDURE DoOneDim*; CONST M = 5; VAR a: ARRAY M OF INTEGER; BEGIN a[0] := 100; (* set first element's value of array a to 100 *) a[M-1] := -100; (* set M-th element's value of array a to -100 *) Out.I...
http://rosettacode.org/wiki/Arithmetic/Complex
Arithmetic/Complex
A   complex number   is a number which can be written as: a + b × i {\displaystyle a+b\times i} (sometimes shown as: b + a × i {\displaystyle b+a\times i} where   a {\displaystyle a}   and   b {\displaystyle b}   are real numbers,   and   i {\displaystyle i}   is   √ -1  Typica...
#Julia
Julia
julia> z1 = 1.5 + 3im julia> z2 = 1.5 + 1.5im julia> z1 + z2 3.0 + 4.5im julia> z1 - z2 0.0 + 1.5im julia> z1 * z2 -2.25 + 6.75im julia> z1 / z2 1.5 + 0.5im julia> - z1 -1.5 - 3.0im julia> conj(z1), z1' # two ways to conjugate (1.5 - 3.0im,1.5 - 3.0im) julia> abs(z1) 3.3541019662496847 julia> z1^z2 -1.102482955327779...
http://rosettacode.org/wiki/Arithmetic/Rational
Arithmetic/Rational
Task Create a reasonably complete implementation of rational arithmetic in the particular language using the idioms of the language. Example Define a new type called frac with binary operator "//" of two integers that returns a structure made up of the numerator and the denominator (as per a rational number). Fur...
#Mathematica_.2F_Wolfram_Language
Mathematica / Wolfram Language
4/16 3/8 8/4 4Pi/2 16!/10! Sqrt[9/16] Sqrt[3/4] (23/12)^5 2 + 1/(1 + 1/(3 + 1/4))   1/2+1/3+1/5 8/Pi+Pi/8 //Together 13/17 + 7/31 Sum[1/n,{n,1,100}] (*summation of 1/1 + 1/2 + 1/3 + 1/4+ .........+ 1/99 + 1/100*)   1/2-1/3 a=1/3;a+=1/7   1/4==2/8 1/4>3/8 Pi/E >23/20 1/3!=123/370 Sin[3]/Sin[2]>3/20   Numerator[6/...
http://rosettacode.org/wiki/Arithmetic-geometric_mean
Arithmetic-geometric mean
This page uses content from Wikipedia. The original article was at Arithmetic-geometric mean. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) Task Write a function to compute the arithmetic-geomet...
#Pascal
Pascal
Program ArithmeticGeometricMean;   uses gmp;   procedure agm (in1, in2: mpf_t; var out1, out2: mpf_t); begin mpf_add (out1, in1, in2); mpf_div_ui (out1, out1, 2); mpf_mul (out2, in1, in2); mpf_sqrt (out2, out2); end;   const nl = chr(13)+chr(10); var x0, y0, resA, resB: mpf_t; i: integer; begin mpf_se...
http://rosettacode.org/wiki/Zero_to_the_zero_power
Zero to the zero power
Some computer programming languages are not exactly consistent   (with other computer programming languages)   when   raising zero to the zeroth power:     00 Task Show the results of raising   zero   to the   zeroth   power. If your computer language objects to     0**0     or     0^0     at compile time, ...
#BASIC
BASIC
print "0 ^ 0 = "; 0 ^ 0
http://rosettacode.org/wiki/Zero_to_the_zero_power
Zero to the zero power
Some computer programming languages are not exactly consistent   (with other computer programming languages)   when   raising zero to the zeroth power:     00 Task Show the results of raising   zero   to the   zeroth   power. If your computer language objects to     0**0     or     0^0     at compile time, ...
#BBC_BASIC
BBC BASIC
PRINT 0^0
http://rosettacode.org/wiki/Zero_to_the_zero_power
Zero to the zero power
Some computer programming languages are not exactly consistent   (with other computer programming languages)   when   raising zero to the zeroth power:     00 Task Show the results of raising   zero   to the   zeroth   power. If your computer language objects to     0**0     or     0^0     at compile time, ...
#Bc
Bc
  0 ^ 0  
http://rosettacode.org/wiki/Arithmetic_evaluation
Arithmetic evaluation
Create a program which parses and evaluates arithmetic expressions. Requirements An abstract-syntax tree (AST) for the expression must be created from parsing the input. The AST must be used in evaluation, also, so the input may not be directly evaluated (e.g. by calling eval or a similar language feature.) The ...
#Kotlin
Kotlin
// version 1.2.10   /* if string is empty, returns zero */ fun String.toDoubleOrZero() = this.toDoubleOrNull() ?: 0.0   fun multiply(s: String): String { val b = s.split('*').map { it.toDoubleOrZero() } return (b[0] * b[1]).toString() }   fun divide(s: String): String { val b = s.split('/').map { it.toDoubl...
http://rosettacode.org/wiki/Archimedean_spiral
Archimedean spiral
The Archimedean spiral is a spiral named after the Greek mathematician Archimedes. An Archimedean spiral can be described by the equation: r = a + b θ {\displaystyle \,r=a+b\theta } with real numbers a and b. Task Draw an Archimedean spiral.
#REXX
REXX
/*REXX pgm plots several cycles (half a spiral) of the Archimedean spiral (ASCII plot).*/ parse arg cy a b inc chr . /*obtain optional arguments from the CL*/ if cy=='' | cy=="," then cy= 3 /*Not specified? Then use the default.*/ if a=='' | a=="," then a= 1 ...
http://rosettacode.org/wiki/Zeckendorf_number_representation
Zeckendorf number representation
Just as numbers can be represented in a positional notation as sums of multiples of the powers of ten (decimal) or two (binary); all the positive integers can be represented as the sum of one or zero times the distinct members of the Fibonacci series. Recall that the first six distinct Fibonacci numbers are: 1, 2, 3, ...
#ALGOL_68
ALGOL 68
# print some Zeckendorf number representations #   # We handle 32-bit numbers, the maximum fibonacci number that can fit in a # # 32 bit number is F(45) #   # build a table of 32-bit fibonacci numbers # [ 45 ]IN...
http://rosettacode.org/wiki/100_doors
100 doors
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it). The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it. The third...
#AutoIt
AutoIt
  #include <array.au3> $doors = 100   ;door array, 0 = closed, 1 = open Local $door[$doors +1]   For $ii = 1 To $doors For $i = $ii To $doors Step $ii $door[$i] = Not $door[$i] next Next   ;display to screen For $i = 1 To $doors ConsoleWrite (Number($door[$i])& " ") If Mod($i,10) = 0 Then ConsoleWrite(@CRLF) Next...
http://rosettacode.org/wiki/Arrays
Arrays
This task is about arrays. For hashes or associative arrays, please see Creating an Associative Array. For a definition and in-depth discussion of what an array is, see Array. Task Show basic array syntax in your language. Basically, create an array, assign a value to it, and retrieve an element   (if available,...
#Computer.2Fzero_Assembly
Computer/zero Assembly
load: LDA ary ADD sum STA sum   LDA load ADD one STA load   SUB end BRZ done   JMP load   done: LDA sum STP   one: 1 end: LDA ary+10   sum: 0   ary: 1 2 3 4 ...
http://rosettacode.org/wiki/Arithmetic/Complex
Arithmetic/Complex
A   complex number   is a number which can be written as: a + b × i {\displaystyle a+b\times i} (sometimes shown as: b + a × i {\displaystyle b+a\times i} where   a {\displaystyle a}   and   b {\displaystyle b}   are real numbers,   and   i {\displaystyle i}   is   √ -1  Typica...
#Kotlin
Kotlin
class Complex(private val real: Double, private val imag: Double) { operator fun plus(other: Complex) = Complex(real + other.real, imag + other.imag)   operator fun times(other: Complex) = Complex( real * other.real - imag * other.imag, real * other.imag + imag * other.real )   fun inv()...
http://rosettacode.org/wiki/Arithmetic/Rational
Arithmetic/Rational
Task Create a reasonably complete implementation of rational arithmetic in the particular language using the idioms of the language. Example Define a new type called frac with binary operator "//" of two integers that returns a structure made up of the numerator and the denominator (as per a rational number). Fur...
#Maxima
Maxima
/* Rational numbers are builtin */ a: 3 / 11; 3/11   b: 117 / 17; 117/17   a + b; 1338/187   a - b; -1236/187   a * b; 351/187   a / b; 17/429   a^5; 243/161051   num(a); 3   denom(a); 11   ratnump(a); true
http://rosettacode.org/wiki/Arithmetic-geometric_mean
Arithmetic-geometric mean
This page uses content from Wikipedia. The original article was at Arithmetic-geometric mean. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) Task Write a function to compute the arithmetic-geomet...
#Perl
Perl
#!/usr/bin/perl -w   my ($a0, $g0, $a1, $g1);   sub agm($$) { $a0 = shift; $g0 = shift; do { $a1 = ($a0 + $g0)/2; $g1 = sqrt($a0 * $g0); $a0 = ($a1 + $g1)/2; $g0 = sqrt($a1 * $g1); } while ($a0 != $a1); return $a0; }   print agm(1, 1/sqrt(2))."\n";
http://rosettacode.org/wiki/Zero_to_the_zero_power
Zero to the zero power
Some computer programming languages are not exactly consistent   (with other computer programming languages)   when   raising zero to the zeroth power:     00 Task Show the results of raising   zero   to the   zeroth   power. If your computer language objects to     0**0     or     0^0     at compile time, ...
#Befunge
Befunge
"PDPF"4#@(0F0FYP)@
http://rosettacode.org/wiki/Zero_to_the_zero_power
Zero to the zero power
Some computer programming languages are not exactly consistent   (with other computer programming languages)   when   raising zero to the zeroth power:     00 Task Show the results of raising   zero   to the   zeroth   power. If your computer language objects to     0**0     or     0^0     at compile time, ...
#BQN
BQN
0⋆0
http://rosettacode.org/wiki/Arithmetic_evaluation
Arithmetic evaluation
Create a program which parses and evaluates arithmetic expressions. Requirements An abstract-syntax tree (AST) for the expression must be created from parsing the input. The AST must be used in evaluation, also, so the input may not be directly evaluated (e.g. by calling eval or a similar language feature.) The ...
#Liberty_BASIC
Liberty BASIC
  '[RC] Arithmetic evaluation.bas 'Buld the tree (with linked nodes, in array 'cause LB has no pointers) 'applying shunting yard algorythm. 'Then evaluate tree   global stack$ 'operator/brakets stack stack$=""   maxStack = 100 dim stack(maxStack) 'nodes stack global SP 'stack pointer SP = 0   '------------------- glo...
http://rosettacode.org/wiki/Archimedean_spiral
Archimedean spiral
The Archimedean spiral is a spiral named after the Greek mathematician Archimedes. An Archimedean spiral can be described by the equation: r = a + b θ {\displaystyle \,r=a+b\theta } with real numbers a and b. Task Draw an Archimedean spiral.
#Ring
Ring
  /* +--------------------------------------------------------------------------------------------------------- + Program Name : Archimedean spiral +--------------------------------------------------------------------------------------------------------- */ Load "guilib.ring"   horzSize = 400 vertSize = 400  ...
http://rosettacode.org/wiki/Archimedean_spiral
Archimedean spiral
The Archimedean spiral is a spiral named after the Greek mathematician Archimedes. An Archimedean spiral can be described by the equation: r = a + b θ {\displaystyle \,r=a+b\theta } with real numbers a and b. Task Draw an Archimedean spiral.
#Ruby
Ruby
  INCR = 0.1 attr_reader :x, :theta   def setup sketch_title 'Archimedian Spiral' @theta = 0 @x = 0 background(255) translate(width / 2.0, height / 2.0) begin_shape (0..50*PI).step(INCR) do |theta| @x = theta * cos(theta / PI) curve_vertex(x, theta * sin(theta / PI)) end end_shape end   def se...
http://rosettacode.org/wiki/Zeckendorf_number_representation
Zeckendorf number representation
Just as numbers can be represented in a positional notation as sums of multiples of the powers of ten (decimal) or two (binary); all the positive integers can be represented as the sum of one or zero times the distinct members of the Fibonacci series. Recall that the first six distinct Fibonacci numbers are: 1, 2, 3, ...
#AppleScript
AppleScript
--------------------- ZECKENDORF NUMBERS -------------------   -- zeckendorf :: Int -> String on zeckendorf(n) script f on |λ|(n, x) if n < x then [n, 0] else [n - x, 1] end if end |λ| end script   if n = 0 then {0} ...
http://rosettacode.org/wiki/100_doors
100 doors
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it). The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it. The third...
#AWK
AWK
BEGIN { for(i=1; i <= 100; i++) { doors[i] = 0 # close the doors } for(i=1; i <= 100; i++) { for(j=i; j <= 100; j += i) { doors[j] = (doors[j]+1) % 2 } } for(i=1; i <= 100; i++) { print i, doors[i] ? "open" : "close" } }
http://rosettacode.org/wiki/Arrays
Arrays
This task is about arrays. For hashes or associative arrays, please see Creating an Associative Array. For a definition and in-depth discussion of what an array is, see Array. Task Show basic array syntax in your language. Basically, create an array, assign a value to it, and retrieve an element   (if available,...
#Crystal
Crystal
  # create an array with one object in it a = ["foo"]   # Empty array literals always need a type specification: [] of Int32 # => Array(Int32).new   # The array's generic type argument T is inferred from the types of the elements inside the literal. When all elements of the array have the same type, T equals to that. O...
http://rosettacode.org/wiki/Arithmetic/Complex
Arithmetic/Complex
A   complex number   is a number which can be written as: a + b × i {\displaystyle a+b\times i} (sometimes shown as: b + a × i {\displaystyle b+a\times i} where   a {\displaystyle a}   and   b {\displaystyle b}   are real numbers,   and   i {\displaystyle i}   is   √ -1  Typica...
#Lambdatalk
Lambdatalk
  {require lib_complex}   {def z1 {C.new 1 1}} -> z1 = (1 1)   {C.x {z1}} -> 1 {C.y {z1}} -> 1 {C.mod {z1}} -> 1.4142135623730951 {C.arg {z1}} -> 0.7853981633974483 // 45° {C.conj {z1}} -> (1 -1) {C.negat {z1}} -> (-1 -1) {C.invert {z1}} -> (0.5 -0.4999999999999999) {C.sqrt {z1}} -> (1.0986841134...
http://rosettacode.org/wiki/Arithmetic/Rational
Arithmetic/Rational
Task Create a reasonably complete implementation of rational arithmetic in the particular language using the idioms of the language. Example Define a new type called frac with binary operator "//" of two integers that returns a structure made up of the numerator and the denominator (as per a rational number). Fur...
#Modula-2
Modula-2
DEFINITION MODULE Rational; TYPE RAT = RECORD numerator : INTEGER; denominator : INTEGER; END;   PROCEDURE IGCD( i : INTEGER; j : INTEGER ) : INTEGER; PROCEDURE ILCM( i : INTEGER; j : INTEGER ) : INTEGER; PROCEDURE IABS( i : INTEGER ) : INTEGER;  ...
http://rosettacode.org/wiki/Arithmetic-geometric_mean
Arithmetic-geometric mean
This page uses content from Wikipedia. The original article was at Arithmetic-geometric mean. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) Task Write a function to compute the arithmetic-geomet...
#Phix
Phix
function agm(atom a, atom g, atom tolerance=1.0e-15) while abs(a-g)>tolerance do {a,g} = {(a + g)/2,sqrt(a*g)} printf(1,"%0.15g\n",a) end while return a end function ?agm(1,1/sqrt(2)) -- (rounds to 10 d.p.)
http://rosettacode.org/wiki/Arithmetic-geometric_mean
Arithmetic-geometric mean
This page uses content from Wikipedia. The original article was at Arithmetic-geometric mean. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) Task Write a function to compute the arithmetic-geomet...
#Phixmonti
Phixmonti
include ..\Utilitys.pmt   1.0e-15 var tolerance   def test over over - abs tolerance > enddef   def agm /# n1 n2 -- n3 #/ test while over over + 2 / rot rot * sqrt test endwhile enddef   1 1 2 sqrt / agm tostr ?
http://rosettacode.org/wiki/Zero_to_the_zero_power
Zero to the zero power
Some computer programming languages are not exactly consistent   (with other computer programming languages)   when   raising zero to the zeroth power:     00 Task Show the results of raising   zero   to the   zeroth   power. If your computer language objects to     0**0     or     0^0     at compile time, ...
#Bracmat
Bracmat
0^0
http://rosettacode.org/wiki/Zero_to_the_zero_power
Zero to the zero power
Some computer programming languages are not exactly consistent   (with other computer programming languages)   when   raising zero to the zeroth power:     00 Task Show the results of raising   zero   to the   zeroth   power. If your computer language objects to     0**0     or     0^0     at compile time, ...
#Burlesque
Burlesque
  blsq ) 0.0 0.0?^ 1.0 blsq ) 0 0?^ 1  
http://rosettacode.org/wiki/Arithmetic_evaluation
Arithmetic evaluation
Create a program which parses and evaluates arithmetic expressions. Requirements An abstract-syntax tree (AST) for the expression must be created from parsing the input. The AST must be used in evaluation, also, so the input may not be directly evaluated (e.g. by calling eval or a similar language feature.) The ...
#Lua
Lua
require"lpeg"   P, R, C, S, V = lpeg.P, lpeg.R, lpeg.C, lpeg.S, lpeg.V   --matches arithmetic expressions and returns a syntax tree expression = P{"expr"; ws = P" "^0, number = C(R"09"^1) * V"ws", lp = "(" * V"ws", rp = ")" * V"ws", sym = C(S"+-*/") * V"ws", more = (V"sym" * V"expr")^0, expr = V"number" * V"more" + V"l...
http://rosettacode.org/wiki/Zhang-Suen_thinning_algorithm
Zhang-Suen thinning algorithm
This is an algorithm used to thin a black and white i.e. one bit per pixel images. For example, with an input image of: ################# ############# ################## ################ #################...
#11l
11l
V beforeTxt = |‘1100111 1100111 1100111 1100111 1100110 1100110 1100110 1100110 1100110 1100110 1100110 1100110 1111110 ...
http://rosettacode.org/wiki/Archimedean_spiral
Archimedean spiral
The Archimedean spiral is a spiral named after the Greek mathematician Archimedes. An Archimedean spiral can be described by the equation: r = a + b θ {\displaystyle \,r=a+b\theta } with real numbers a and b. Task Draw an Archimedean spiral.
#Rust
Rust
#[macro_use(px)] extern crate bmp;   use bmp::{Image, Pixel}; use std::f64;   fn main() { let width = 600u32; let half_width = (width / 2) as i32; let mut img = Image::new(width, width); let draw_color = px!(255, 128, 128);   // Constants defining the spiral size. let a = 1.0_f64; let b = 9....
http://rosettacode.org/wiki/Archimedean_spiral
Archimedean spiral
The Archimedean spiral is a spiral named after the Greek mathematician Archimedes. An Archimedean spiral can be described by the equation: r = a + b θ {\displaystyle \,r=a+b\theta } with real numbers a and b. Task Draw an Archimedean spiral.
#SAS
SAS
data xy; h=constant('pi')/40; do i=0 to 400; t=i*h; x=(1+t)*cos(t); y=(1+t)*sin(t); output; end; keep x y; run;   proc sgplot; series x=x y=y; run;
http://rosettacode.org/wiki/Zeckendorf_number_representation
Zeckendorf number representation
Just as numbers can be represented in a positional notation as sums of multiples of the powers of ten (decimal) or two (binary); all the positive integers can be represented as the sum of one or zero times the distinct members of the Fibonacci series. Recall that the first six distinct Fibonacci numbers are: 1, 2, 3, ...
#Arturo
Arturo
Z: function [x][ if x=0 -> return "0" fib: new [2 1] n: new x while -> n > first fib -> insert 'fib 0 fib\0 + fib\1   result: new "" loop fib 'f [ if? f =< n [ 'result ++ "1" 'n - f ] else -> 'result ++ "0" ] if result\0 = `0` -> ...
http://rosettacode.org/wiki/100_doors
100 doors
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it). The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it. The third...
#Axiom
Axiom
(open,closed,change,open?) := (true,false,not,test); doors := bits(100,closed); for i in 1..#doors repeat for j in i..#doors by i repeat doors.j := change doors.j [i for i in 1..#doors | open? doors.i]  
http://rosettacode.org/wiki/Arrays
Arrays
This task is about arrays. For hashes or associative arrays, please see Creating an Associative Array. For a definition and in-depth discussion of what an array is, see Array. Task Show basic array syntax in your language. Basically, create an array, assign a value to it, and retrieve an element   (if available,...
#D
D
// All D arrays are capable of bounds checks.   import std.stdio, core.stdc.stdlib; import std.container: Array;   void main() { // GC-managed heap allocated dynamic array: auto array1 = new int[1]; array1[0] = 1; array1 ~= 3; // append a second item // array1[10] = 4; // run-time error writeln(...
http://rosettacode.org/wiki/Arithmetic/Complex
Arithmetic/Complex
A   complex number   is a number which can be written as: a + b × i {\displaystyle a+b\times i} (sometimes shown as: b + a × i {\displaystyle b+a\times i} where   a {\displaystyle a}   and   b {\displaystyle b}   are real numbers,   and   i {\displaystyle i}   is   √ -1  Typica...
#LFE
LFE
  (defrecord complex real img)  
http://rosettacode.org/wiki/Arithmetic/Complex
Arithmetic/Complex
A   complex number   is a number which can be written as: a + b × i {\displaystyle a+b\times i} (sometimes shown as: b + a × i {\displaystyle b+a\times i} where   a {\displaystyle a}   and   b {\displaystyle b}   are real numbers,   and   i {\displaystyle i}   is   √ -1  Typica...
#Liberty_BASIC
Liberty BASIC
mainwin 50 10   print " Adding" call cprint cadd$( complex$( 1, 1), complex$( 3.14159265, 1.2)) print " Multiplying" call cprint cmulti$( complex$( 1, 1), complex$( 3.14159265, 1.2)) print " Inverting" call cprint cinv$( complex$( 1, 1)) print " Negating" call cprint cneg$( complex$( 1, 1))   end   sub cprint cx$...
http://rosettacode.org/wiki/Arithmetic/Rational
Arithmetic/Rational
Task Create a reasonably complete implementation of rational arithmetic in the particular language using the idioms of the language. Example Define a new type called frac with binary operator "//" of two integers that returns a structure made up of the numerator and the denominator (as per a rational number). Fur...
#Modula-3
Modula-3
INTERFACE Frac;   EXCEPTION ZeroDenominator;   TYPE   T <: Public; Public = OBJECT METHODS (* initialization and conversion *) init(a, b: INTEGER): T RAISES { ZeroDenominator }; fromInt(a: INTEGER): T; (* unary operators *) abs(): T; opposite(): T; (* binary operators *) plus(other...
http://rosettacode.org/wiki/Arithmetic-geometric_mean
Arithmetic-geometric mean
This page uses content from Wikipedia. The original article was at Arithmetic-geometric mean. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) Task Write a function to compute the arithmetic-geomet...
#PHP
PHP
  define('PRECISION', 13);   function agm($a0, $g0, $tolerance = 1e-10) { // the bc extension deals in strings and cannot convert // floats in scientific notation by itself - hence // this manual conversion t...
http://rosettacode.org/wiki/Zero_to_the_zero_power
Zero to the zero power
Some computer programming languages are not exactly consistent   (with other computer programming languages)   when   raising zero to the zeroth power:     00 Task Show the results of raising   zero   to the   zeroth   power. If your computer language objects to     0**0     or     0^0     at compile time, ...
#C
C
#include <stdio.h> #include <math.h> #include <complex.h>   int main() { printf("0 ^ 0 = %f\n", pow(0,0)); double complex c = cpow(0,0); printf("0+0i ^ 0+0i = %f+%fi\n", creal(c), cimag(c)); return 0; }
http://rosettacode.org/wiki/Zero_to_the_zero_power
Zero to the zero power
Some computer programming languages are not exactly consistent   (with other computer programming languages)   when   raising zero to the zeroth power:     00 Task Show the results of raising   zero   to the   zeroth   power. If your computer language objects to     0**0     or     0^0     at compile time, ...
#C.23
C#
using System;   namespace ZeroToTheZeroeth { class Program { static void Main(string[] args) { double k = Math.Pow(0, 0); Console.Write("0^0 is {0}", k); } } }
http://rosettacode.org/wiki/Arithmetic_evaluation
Arithmetic evaluation
Create a program which parses and evaluates arithmetic expressions. Requirements An abstract-syntax tree (AST) for the expression must be created from parsing the input. The AST must be used in evaluation, also, so the input may not be directly evaluated (e.g. by calling eval or a similar language feature.) The ...
#M2000_Interpreter
M2000 Interpreter
  y=100 Module CheckEval { A$="1 + 2 * (3 + (4 * 5 + 6 * 7 * 8) - 9) / 10" Print Eval(A$) x=10 Print Eval("x+5")=x+5 Print Eval("A$=A$")=True Try { Print Eval("y") ' error: y is uknown here } } Call CheckEval  
http://rosettacode.org/wiki/Zhang-Suen_thinning_algorithm
Zhang-Suen thinning algorithm
This is an algorithm used to thin a black and white i.e. one bit per pixel images. For example, with an input image of: ################# ############# ################## ################ #################...
#Action.21
Action!
PROC DrawImage(BYTE ARRAY image BYTE x,y,width,height) BYTE i,j BYTE POINTER ptr   Color=2 FOR j=0 TO height-1 DO Plot(x,j+y) DrawTo(x+width-1,j+y) OD Color=1 ptr=image FOR j=0 TO height-1 DO FOR i=0 TO width-1 DO IF ptr^ THEN Plot(i+x,j+y) FI ptr==+1 OD O...
http://rosettacode.org/wiki/Archimedean_spiral
Archimedean spiral
The Archimedean spiral is a spiral named after the Greek mathematician Archimedes. An Archimedean spiral can be described by the equation: r = a + b θ {\displaystyle \,r=a+b\theta } with real numbers a and b. Task Draw an Archimedean spiral.
#Scala
Scala
    object ArchimedeanSpiral extends App {   SwingUtilities.invokeLater(() => new JFrame("Archimedean Spiral") {   class ArchimedeanSpiral extends JPanel { setPreferredSize(new Dimension(640, 640)) setBackground(Color.white)   private def drawGrid(g: Graphics2D): Unit = { v...