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/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, ... | #AutoHotkey | AutoHotkey | Fib := NStepSequence(1, 2, 2, 20)
Loop, 21 {
i := A_Index - 1
, Out .= i ":`t", n := ""
Loop, % Fib.MaxIndex() {
x := Fib.MaxIndex() + 1 - A_Index
if (Fib[x] <= i)
n .= 1, i -= Fib[x]
else
n .= 0
}
Out .= (n ? LTrim(n, "0") : 0) "`n"
}
MsgBox, % Out
NStepSequence(v1, v2, n, k) {
a := [v1, v2]
Lo... |
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... | #B | B | main()
{
auto doors[100]; /* != 0 means open */
auto pass, door;
door = 0;
while( door<100 ) doors[door++] = 0;
pass = 0;
while( pass<100 )
{
door = pass;
while( door<100 )
{
doors[door] = !doors[door];
door =+ pass+1;
}
++pass;
}
door = 0;
while( door<100 )
{... |
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,... | #Dao | Dao | # use [] to create numeric arrays of int, float, double or complex types:
a = [ 1, 2, 3 ] # a vector
b = [ 1, 2; 3, 4 ] # a 2X2 matrix
# use {} to create normal arrays of any types:
c = { 1, 2, 'abc' }
d = a[1]
e = b[0,1] # first row, second column
f = c[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... | #Lua | Lua |
--defines addition, subtraction, negation, multiplication, division, conjugation, norms, and a conversion to strgs.
complex = setmetatable({
__add = function(u, v) return complex(u.real + v.real, u.imag + v.imag) end,
__sub = function(u, v) return complex(u.real - v.real, u.imag - v.imag) end,
__mul = function(u, v... |
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... | #Nim | Nim | import math
proc `^`[T](base, exp: T): T =
var (base, exp) = (base, exp)
result = 1
while exp != 0:
if (exp and 1) != 0:
result *= base
exp = exp shr 1
base *= base
proc gcd[T](u, v: T): T =
if v != 0:
gcd(v, u mod v)
else:
u.abs
proc lcm[T](a, b: T): T =
a div gcd(a, b) * ... |
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... | #PicoLisp | PicoLisp | (scl 80)
(de agm (A G)
(do 7
(prog1 (/ (+ A G) 2)
(setq G (sqrt A G) A @) ) ) )
(round
(agm 1.0 (*/ 1.0 1.0 (sqrt 2.0 1.0)))
70 ) |
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... | #PL.2FI | PL/I |
arithmetic_geometric_mean: /* 31 August 2012 */
procedure options (main);
declare (a, g, t) float (18);
a = 1; g = 1/sqrt(2.0q0);
put skip list ('The arithmetic-geometric mean of ' || a || ' and ' || g || ':');
do until (abs(a-g) < 1e-15*a);
t = (a + g)/2; g = sqrt(a*g);
a = 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.2B.2B | C++ | #include <iostream>
#include <cmath>
#include <complex>
int main()
{
std::cout << "0 ^ 0 = " << std::pow(0,0) << std::endl;
std::cout << "0+0i ^ 0+0i = " <<
std::pow(std::complex<double>(0),std::complex<double>(0)) << std::endl;
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, ... | #Cach.C3.A9_ObjectScript | Caché ObjectScript | ZEROPOW
// default behavior is incorrect:
set (x,y) = 0
w !,"0 to the 0th power (wrong): "_(x**y) ; will output 0
// if one or both of the values is a double, this works
set (x,y) = $DOUBLE(0)
w !,"0 to the 0th power (right): "_(x**y)
quit |
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 ... | #Mathematica_.2F_Wolfram_Language | Mathematica / Wolfram Language | (*parsing:*)
parse[string_] :=
Module[{e},
StringCases[string,
"+" | "-" | "*" | "/" | "(" | ")" |
DigitCharacter ..] //. {a_String?DigitQ :>
e[ToExpression@a], {x___, PatternSequence["(", a_e, ")"],
y___} :> {x, a,
y}, {x :
PatternSequence[] |
PatternSequence... |
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:
################# #############
################## ################
#################... | #AppleScript | AppleScript | -- Params:
-- List of lists (rows) of "pixel" values.
-- Record indicating the values representing black and white.
on ZhangSuen(matrix, {black:black, white:white})
script o
property matrix : missing value
property changePixels : missing value
on A(neighbours) -- Count transitions from whi... |
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.
| #Scheme | Scheme |
(import (scheme base)
(scheme complex)
(rebottled pstk))
; settings for spiral
(define *resolution* 0.01)
(define *count* 2000)
(define *a* 10)
(define *b* 10)
(define *center*
(let ((size 200)) ; change this to alter size of display
(* size 1+i)))
(define (draw-spiral canvas)
(define (c... |
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, ... | #AutoIt | AutoIt |
For $i = 0 To 20
ConsoleWrite($i &": "& Zeckendorf($i)&@CRLF)
Next
Func Zeckendorf($int, $Fibarray = "")
If Not IsArray($Fibarray) Then $Fibarray = Fibonacci($int)
Local $ret = ""
For $i = UBound($Fibarray) - 1 To 1 Step -1
If $Fibarray[$i] > $int And $ret = "" Then ContinueLoop ; dont use Leading Zeros
If... |
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... | #BaCon | BaCon |
OPTION BASE 1
DECLARE doors[100]
FOR size = 1 TO 100
FOR pass = 0 TO 100 STEP size
doors[pass] = NOT(doors[pass])
NEXT
NEXT
FOR which = 1 TO 100
IF doors[which] THEN PRINT which
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,... | #Dart | Dart |
main(){
// Dart uses Lists which dynamically resize by default
final growable = [ 1, 2, 3 ];
// Add to the list using the add method
growable.add(4);
print('growable: $growable');
// You can pass an int to the constructor to create a fixed sized List
final fixed = List(3);
// We must assign eac... |
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... | #Maple | Maple | x := 1+I;
y := Pi+I*1.2; |
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... | #Mathematica_.2F_Wolfram_Language | Mathematica / Wolfram Language | x=1+2I
y=3+4I
x+y => 4 + 6 I
x-y => -2 - 2 I
y x => -5 + 10 I
y/x => 11/5 - (2 I)/5
x^3 => -11 - 2 I
y^4 => -527 - 336 I
x^y => (1 + 2 I)^(3 + 4 I)
N[x^y] => 0.12901 + 0.0339241 I |
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... | #Objective-C | Objective-C | #import <Foundation/Foundation.h>
@interface RCRationalNumber : NSObject
{
@private
int numerator;
int denominator;
BOOL autoSimplify;
BOOL withSign;
}
+(instancetype)valueWithNumerator:(int)num andDenominator: (int)den;
+(instancetype)valueWithDouble: (double)fnum;
+(instancetype)valueWithInteger: (int)inum... |
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... | #Potion | Potion | sqrt = (x) :
xi = 1
7 times :
xi = (xi + x / xi) / 2
.
xi
.
agm = (x, y) :
7 times :
a = (x + y) / 2
g = sqrt(x * y)
x = a
y = g
.
x
. |
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... | #PowerShell | PowerShell |
function agm ([Double]$a, [Double]$g) {
[Double]$eps = 1E-15
[Double]$a1 = [Double]$g1 = 0
while([Math]::Abs($a - $g) -gt $eps) {
$a1, $g1 = $a, $g
$a = ($a1 + $g1)/2
$g = [Math]::Sqrt($a1*$g1)
}
[pscustomobject]@{
a = "$a"
g = "$g"
}
}
agm 1 (1/[Math]::... |
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, ... | #Clojure | Clojure | user=> (use 'clojure.math.numeric-tower)
user=> (expt 0 0)
1
; alternative java-interop route:
user=> (Math/pow 0 0)
1.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, ... | #CLU | CLU | start_up = proc ()
zz_int: int := 0 ** 0
zz_real: real := 0.0 ** 0.0
po: stream := stream$primary_output()
stream$putl(po, "integer 0**0: " || int$unparse(zz_int))
stream$putl(po, "real 0**0: " || f_form(zz_real, 1, 1))
end start_up |
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, ... | #COBOL | COBOL | identification division.
program-id. zero-power-zero-program.
data division.
working-storage section.
77 n pic 9.
procedure division.
compute n = 0**0.
display n upon console.
stop run. |
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 ... | #MiniScript | MiniScript | Expr = {}
Expr.eval = 0
BinaryExpr = new Expr
BinaryExpr.eval = function()
if self.op == "+" then return self.lhs.eval + self.rhs.eval
if self.op == "-" then return self.lhs.eval - self.rhs.eval
if self.op == "*" then return self.lhs.eval * self.rhs.eval
if self.op == "/" then return self.lhs.eval / self.rhs.eval... |
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:
################# #############
################## ################
#################... | #AutoHotkey | AutoHotkey | FileIn := A_ScriptDir "\Zhang-Suen.txt"
FileOut := A_ScriptDir "\NewFile.txt"
if (!FileExist(FileIn)) {
MsgBox, 48, File Not Found, % "File """ FileIn """ not found."
ExitApp
}
S := {}
N := [2,3,4,5,6,7,8,9,2]
Loop, Read, % FileIn
{
LineNum := A_Index
Loop, Parse, A_LoopReadLine
S[LineNum, A_Index] := A_Loop... |
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.
| #Scilab | Scilab | a = 3;
b = 2;
theta = linspace(0,10*%pi,1000);
r = a + b .* theta;
//1. Plot using polar coordinates
scf(1);
polarplot(theta,r);
//2. Plot using rectangular coordinates
//2.1 Convert coordinates using Euler's formula
z = r .* exp(%i .* theta);
x = real(z);
y = imag(z);
scf(2);
plot2d(x,y); |
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.
| #Seed7 | Seed7 | $ include "seed7_05.s7i";
include "draw.s7i";
include "keybd.s7i";
const proc: main is func
local
const float: xCenter is 117.0;
const float: yCenter is 139.0;
const float: maxTheta is 10.0 * PI;
const float: delta is 0.01;
const float: a is 1.0;
const float: b is 7.0;
var float: the... |
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.
| #Sidef | Sidef | require('Imager')
define π = Num.pi
var (w, h) = (400, 400)
var img = %O<Imager>.new(xsize => w, ysize => h)
for Θ in (0 .. 52*π -> by(0.025)) {
img.setpixel(
x => floor(cos(Θ / π)*Θ + w/2),
y => floor(sin(Θ / π)*Θ + h/2),
color => [255, 0, 0]
)
}
img.write(file => 'Archimedean_spi... |
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, ... | #BBC_BASIC | BBC BASIC | FOR n% = 0 TO 20
PRINT n% RIGHT$(" " + FNzeckendorf(n%), 8)
NEXT
PRINT '"Checking numbers up to 10000..."
FOR n% = 21 TO 10000
IF INSTR(FNzeckendorf(n%), "11") STOP
NEXT
PRINT "No Zeckendorf numbers contain consecutive 1's"
END
DEF FNzeckendorf(n%)... |
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, ... | #Befunge | Befunge | 45*83p0>:::.0`"0"v
v53210p 39+!:,,9+<
>858+37 *66g"7Y":v
>3g`#@_^ v\g39$<
^8:+1,+5_5<>-:0\`|
v:-\g39_^#:<*:p39<
>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... | #BASIC | BASIC |
100 :
110 REM 100 DOORS PROBLEM
120 :
130 DIM D(100)
140 FOR P = 1 TO 100
150 FOR T = P TO 100 STEP P
160 D(T) = NOT D(T): NEXT T
170 NEXT P
180 FOR I = 1 TO 100
190 IF D(I) THEN PRINT I;" ";
200 NEXT 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,... | #DBL | DBL | ;
; Arrays for DBL version 4 by Dario B.
;
.DEFINE NR,5
RECORD
VNUM1, 5D8 ;array of number
VNUM2, [5]D8 ;array of number
VNUM3, [5,2]D8 ;two-dimensional array of number
VALP1, 5A10 ;array of strings
VALP2, [5]A10 ;array of strings
VALP3, [5,2... |
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... | #MATLAB | MATLAB | >> a = 1+i
a =
1.000000000000000 + 1.000000000000000i
>> b = 3+7i
b =
3.000000000000000 + 7.000000000000000i
>> a+b
ans =
4.000000000000000 + 8.000000000000000i
>> a-b
ans =
-2.000000000000000 - 6.000000000000000i
>> a*b
ans =
-4.000000000000000 +10.000000000000000i
>> a/b
ans =
... |
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... | #OCaml | OCaml | #load "nums.cma";;
open Num;;
for candidate = 2 to 1 lsl 19 do
let sum = ref (num_of_int 1 // num_of_int candidate) in
for factor = 2 to truncate (sqrt (float candidate)) do
if candidate mod factor = 0 then
sum := !sum +/ num_of_int 1 // num_of_int factor
+/ num_of_int 1 // num_of_int ... |
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... | #Prolog | Prolog |
agm(A,G,A) :- abs(A-G) < 1.0e-15, !.
agm(A,G,Res) :- A1 is (A+G)/2.0, G1 is sqrt(A*G),!, agm(A1,G1,Res).
?- agm(1,1/sqrt(2),Res).
Res = 0.8472130847939792.
|
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... | #PureBasic | PureBasic | Procedure.d AGM(a.d, g.d, ErrLim.d=1e-15)
Protected.d ta=a+1, tg
While ta <> a
ta=a: tg=g
a=(ta+tg)*0.5
g=Sqr(ta*tg)
Wend
ProcedureReturn a
EndProcedure
If OpenConsole()
PrintN(StrD(AGM(1, 1/Sqr(2)), 16))
Input()
CloseConsole()
EndIf |
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, ... | #ColdFusion | ColdFusion |
<cfset zeroPowerTag = 0^0>
<cfoutput>"#zeroPowerTag#"</cfoutput>
|
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, ... | #Commodore_BASIC | Commodore BASIC | ready.
print 0↑0
1
ready.
█ |
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 ... | #Nim | Nim | import strutils
import os
#--
# Lexer
#--
type
TokenKind = enum
tokNumber
tokPlus = "+", tokMinus = "-", tokStar = "*", tokSlash = "/"
tokLPar, tokRPar
tokEnd
Token = object
case kind: TokenKind
of tokNumber: value: float
else: discard
proc lex(input: string): seq[Token] =
# Here... |
http://rosettacode.org/wiki/Zumkeller_numbers | Zumkeller numbers | Zumkeller numbers are the set of numbers whose divisors can be partitioned into two disjoint sets that sum to the same value. Each sum must contain divisor values that are not in the other sum, and all of the divisors must be in one or the other. There are no restrictions on how the divisors are partitioned, only that ... | #11l | 11l | F getDivisors(n)
V divs = [1, n]
V i = 2
L i * i <= n
I n % i == 0
divs [+]= i
V j = n I/ i
I i != j
divs [+]= j
i++
R divs
F isPartSum(divs, sum)
I sum == 0
R 1B
V le = divs.len
I le == 0
R 0B
V last = divs.last
[Int] new... |
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:
################# #############
################## ################
#################... | #C | C | <Rows> <Columns>
<Blank pixel character> <Image Pixel character>
<Image of specified rows and columns made up of the two pixel types specified in the second line.>
|
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:
################# #############
################## ################
#################... | #C.2B.2B | C++ | #include <iostream>
#include <string>
#include <sstream>
#include <valarray>
const std::string input {
"................................"
".#########.......########......."
".###...####.....####..####......"
".###....###.....###....###......"
".###...####.....###............."
".#########......###............."
".###.#... |
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.
| #Stata | Stata | clear all
scalar h=_pi/40
set obs 400
gen t=_n*h
gen x=(1+t)*cos(t)
gen y=(1+t)*sin(t)
line y x |
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.
| #Tcl | Tcl | package require Tk
# create widgets
canvas .canvas
frame .controls
ttk::label .legend -text " r = a + b θ "
ttk::label .label_a -text "a ="
ttk::entry .entry_a -textvariable a
ttk::label .label_b -text "a ="
ttk::entry .entry_b -textvariable b
button .button -text "Redraw" -command draw
# layout
grid .canvas .con... |
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, ... | #C | C | #include <stdio.h>
typedef unsigned long long u64;
#define FIB_INVALID (~(u64)0)
u64 fib[] = {
1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597,
2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418,
317811, 514229, 832040, 1346269, 2178309, 3524578, 5702887, 9227465,
14930352, 2... |
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... | #Batch_File | Batch File |
@echo off
setlocal enableDelayedExpansion
:: 0 = closed
:: 1 = open
:: SET /A treats undefined variable as 0
:: Negation operator ! must be escaped because delayed expansion is enabled
for /l %%p in (1 1 100) do for /l %%d in (%%p %%p 100) do set /a "door%%d=^!door%%d"
for /l %%d in (1 1 100) do if !door%%d!==1 (
e... |
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,... | #Delphi | Delphi |
procedure TForm1.Button1Click(Sender: TObject);
var
StaticArray: array[1..10] of Integer; // static arrays can start at any index
DynamicArray: array of Integer; // dynamic arrays always start at 0
StaticArrayText,
DynamicArrayText: string;
ixS, ixD: Integer;
begin
// Setting the length of the dynamic arr... |
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... | #Maxima | Maxima | z1: 5 + 2 * %i;
2*%i+5
z2: 3 - 7 * %i;
3-7*%i
carg(z1);
atan(2/5)
cabs(z1);
sqrt(29)
rectform(z1 * z2);
29-29*%i
polarform(z1);
sqrt(29)*%e^(%i*atan(2/5))
conjugate(z1);
5-2*%i
z1 + z2;
8-5*%i
z1 - z2;
9*%i+2
z1 * z2;
(3-7*%i)*(2*%i+5)
z1 * z2, rectform;
29-29*%i
z1 / z2;
(2*%i+5)/(3-7*%i)
z1 / ... |
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... | #.D0.9C.D0.9A-61.2F52 | МК-61/52 | ПA С/П ПB С/П ПC С/П ПD С/П ИПC x^2
ИПD x^2 + П3 ИПA ИПC * ИПB ИПD *
+ ИП3 / П1 ИПB ИПC * ИПA ИПD *
- ИП3 / П2 ИП1 С/П ИПA ИПC * ИПB
ИПD * - П1 ИПB ИПC * ИПA ИПD *
+ П2 ИП1 С/П ИПB ИПD + П2 ИПA ИПC
+ ИП1 С/П ИПB ИПD - П2 ИПA ИПC -
П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... | #Ol | Ol |
(define x 3/7)
(define y 9/11)
(define z -2/5)
; demonstrate builtin functions:
(print "(abs " z ") = " (abs z))
(print "- " z " = " (- z))
(print x " + " y " = " (+ x y))
(print x " - " y " = " (- x y))
(print x " * " y " = " (* x y))
(print x " / " y " = " (/ x y))
(print x " < " y " = " (< x y))
(print x " > "... |
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... | #Python | Python | from math import sqrt
def agm(a0, g0, tolerance=1e-10):
"""
Calculating the arithmetic-geometric mean of two numbers a0, g0.
tolerance the tolerance for the converged
value of the arithmetic-geometric mean
(default value = 1e-10)
"""
an, gn = (a0 + g0) / ... |
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... | #Quackery | Quackery | [ $ "bigrat.qky" loadfile ] now!
[ temp put
[ 2over 2over temp share approx=
iff 2drop done
2over 2over v*
temp share vsqrt drop
dip [ dip [ v+ 2 n->v v/ ] ]
again ]
base share temp take ** round ] is agm ( n/d n/d n --> n/d )
1 n->v
2 n->v 125 vsqrt drop 1/v
12... |
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, ... | #Common_Lisp | Common Lisp | > (expt 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, ... | #Crystal | Crystal | puts "Int32: #{0_i32**0_i32}"
puts "Negative Int32: #{-0_i32**-0_i32}"
puts "Float32: #{0_f32**0_f32}"
puts "Negative Float32: #{-0_f32**-0_f32}" |
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 ... | #OCaml | OCaml | type expression =
| Const of float
| Sum of expression * expression (* e1 + e2 *)
| Diff of expression * expression (* e1 - e2 *)
| Prod of expression * expression (* e1 * e2 *)
| Quot of expression * expression (* e1 / e2 *)
let rec eval = function
| Const c -> c
| Sum (f, g) -> eval f +. eval... |
http://rosettacode.org/wiki/Zumkeller_numbers | Zumkeller numbers | Zumkeller numbers are the set of numbers whose divisors can be partitioned into two disjoint sets that sum to the same value. Each sum must contain divisor values that are not in the other sum, and all of the divisors must be in one or the other. There are no restrictions on how the divisors are partitioned, only that ... | #AArch64_Assembly | AArch64 Assembly |
/* ARM assembly AARCH64 Raspberry PI 3B */
/* program zumkellex641.s */
/* REMARK 1 : this program use routines in a include file
see task Include a file language arm assembly
for the routine affichageMess conversion10
see at end of this program the instruction include */
/* REMARK 2 : this program... |
http://rosettacode.org/wiki/Zumkeller_numbers | Zumkeller numbers | Zumkeller numbers are the set of numbers whose divisors can be partitioned into two disjoint sets that sum to the same value. Each sum must contain divisor values that are not in the other sum, and all of the divisors must be in one or the other. There are no restrictions on how the divisors are partitioned, only that ... | #AppleScript | AppleScript | -- Sum n's proper divisors.
on aliquotSum(n)
if (n < 2) then return 0
set sum to 1
set sqrt to n ^ 0.5
set limit to sqrt div 1
if (limit = sqrt) then
set sum to sum + limit
set limit to limit - 1
end if
repeat with i from 2 to limit
if (n mod i is 0) then set sum to s... |
http://rosettacode.org/wiki/Arbitrary-precision_integers_(included) | Arbitrary-precision integers (included) | Using the in-built capabilities of your language, calculate the integer value of:
5
4
3
2
... | #11l | 11l | V y = String(BigInt(5) ^ 4 ^ 3 ^ 2)
print(‘5^4^3^2 = #....#. and has #. digits’.format(y[0.<20], y[(len)-20..], y.len)) |
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:
################# #############
################## ################
#################... | #D | D | import std.stdio, std.algorithm, std.string, std.functional,
std.typecons, std.typetuple, bitmap;
struct BlackWhite {
ubyte c;
alias c this;
static immutable black = typeof(this)(0),
white = typeof(this)(1);
}
alias Neighbours = BlackWhite[9];
alias Img = Image!BlackWhite;
... |
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.
| #VBA | VBA | Private Sub plot_coordinate_pairs(x As Variant, y As Variant)
Dim chrt As Chart
Set chrt = ActiveSheet.Shapes.AddChart.Chart
With chrt
.ChartType = xlXYScatter
.HasLegend = False
.SeriesCollection.NewSeries
.SeriesCollection.Item(1).XValues = x
.SeriesCollection.Item(... |
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.
| #Wren | Wren | import "graphics" for Canvas, Color
import "dome" for Window
class Game {
static init() {
Window.title = "Archimedean Spiral"
__width = 400
__height = 400
Canvas.resize(__width, __height)
Window.resize(__width, __height)
var col = Color.red
spiral(col)
}... |
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, ... | #C.23 | C# |
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Zeckendorf
{
class Program
{
private static uint Fibonacci(uint n)
{
if (n < 2)
{
return n;
}
else
{
ret... |
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... | #BBC_BASIC | BBC BASIC | DIM doors%(100)
FOR pass% = 1 TO 100
FOR door% = pass% TO 100 STEP pass%
doors%(door%) = NOT doors%(door%)
NEXT door%
NEXT pass%
FOR door% = 1 TO 100
IF doors%(door%) PRINT "Door " ; door% " is open"
NEXT door% |
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,... | #Diego | Diego | set_ns(rosettacode);
set_base(0);
// Create a new dynamic array with length zero, variant and/or mixed datatypes
add_array(myEmptyArray);
// Create a new dynamic array with length zero, of integers with no mixed datatypes
add_array({int}, myIntegerArray);
// Create a new fixed-length array with length 5
add_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... | #Modula-2 | Modula-2 | MODULE complex;
IMPORT InOut;
TYPE Complex = RECORD R, Im : REAL END;
VAR z : ARRAY [0..3] OF Complex;
PROCEDURE ShowComplex (str : ARRAY OF CHAR; p : Complex);
BEGIN
InOut.WriteString (str); InOut.WriteString (" = ");
InOut.WriteReal (p.R, 6, 2);
IF... |
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... | #ooRexx | ooRexx |
loop candidate = 6 to 2**19
sum = .fraction~new(1, candidate)
max2 = rxcalcsqrt(candidate)~trunc
loop factor = 2 to max2
if candidate // factor == 0 then do
sum += .fraction~new(1, factor)
sum += .fraction~new(1, candidate / factor)
end
end
if sum == 1 then ... |
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... | #R | R | arithmeticMean <- function(a, b) { (a + b)/2 }
geometricMean <- function(a, b) { sqrt(a * b) }
arithmeticGeometricMean <- function(a, b) {
rel_error <- abs(a - b) / pmax(a, b)
if (all(rel_error < .Machine$double.eps, na.rm=TRUE)) {
agm <- a
return(data.frame(agm, rel_error));
}
Recall(arithmeticMean(... |
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... | #Racket | Racket |
#lang racket
(define (agm a g [ε 1e-15])
(if (<= (- a g) ε)
a
(agm (/ (+ a g) 2) (sqrt (* a g)) ε)))
(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, ... | #D | D | void main() {
import std.stdio, std.math, std.bigint, std.complex;
writeln("Int: ", 0 ^^ 0);
writeln("Ulong: ", 0UL ^^ 0UL);
writeln("Float: ", 0.0f ^^ 0.0f);
writeln("Double: ", 0.0 ^^ 0.0);
writeln("Real: ", 0.0L ^^ 0.0L);
writeln("pow: ", pow(0, 0));
writeln("BigInt:... |
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, ... | #Dc | Dc | 0 0^p
|
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 ... | #ooRexx | ooRexx |
expressions = .array~of("2+3", "2+3/4", "2*3-4", "2*(3+4)+5/6", "2 * (3 + (4 * 5 + (6 * 7) * 8) - 9) * 10", "2*-3--4+-.25")
loop input over expressions
expression = createExpression(input)
if expression \= .nil then
say 'Expression "'input'" parses to "'expression~string'" and evaluates to "'expressio... |
http://rosettacode.org/wiki/Zeckendorf_arithmetic | Zeckendorf arithmetic | This task is a total immersion zeckendorf task; using decimal numbers will attract serious disapprobation.
The task is to implement addition, subtraction, multiplication, and division using Zeckendorf number representation. Optionally provide decrement, increment and comparitive operation functions.
Addition
Like bin... | #11l | 11l | T Zeckendorf
Int dLen
dVal = 0
F (x = ‘0’)
V q = 1
V i = x.len - 1
.dLen = i I/ 2
L i >= 0
.dVal = .dVal + (x[i].code - ‘0’.code) * q
q = q * 2
i = i - 1
F a(n)
V i = n
L
I .dLen < i
.dLen = i
V j = (.dVal >> (i... |
http://rosettacode.org/wiki/Zumkeller_numbers | Zumkeller numbers | Zumkeller numbers are the set of numbers whose divisors can be partitioned into two disjoint sets that sum to the same value. Each sum must contain divisor values that are not in the other sum, and all of the divisors must be in one or the other. There are no restrictions on how the divisors are partitioned, only that ... | #ARM_Assembly | ARM Assembly |
/* ARM assembly Raspberry PI */
/* program zumkeller4.s */
/* new version 10/2020 */
/* REMARK 1 : this program use routines in a include file
see task Include a file language arm assembly
for the routine affichageMess conversion10
see at end of this program the instruction include */
/* for constan... |
http://rosettacode.org/wiki/Arbitrary-precision_integers_(included) | Arbitrary-precision integers (included) | Using the in-built capabilities of your language, calculate the integer value of:
5
4
3
2
... | #8th | 8th |
200000 n#
5 4 3 2 bfloat ^ ^ ^
"%.0f" s:strfmt
dup s:len . " digits" . cr
dup 20 s:lsub . "..." . 20 s:rsub . cr
|
http://rosettacode.org/wiki/Arbitrary-precision_integers_(included) | Arbitrary-precision integers (included) | Using the in-built capabilities of your language, calculate the integer value of:
5
4
3
2
... | #ACL2 | ACL2 | (in-package "ACL2")
(include-book "arithmetic-3/floor-mod/floor-mod" :dir :system)
(set-print-length 0 state)
(defun arbitrary-precision ()
(declare (xargs :mode :program))
(let* ((x (expt 5 (expt 4 (expt 3 2))))
(s (mv-let (col str)
(fmt1-to-string "~xx"
... |
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:
################# #############
################## ################
#################... | #Elena | Elena | import system'collections;
import system'routines;
import extensions;
import extensions'routines;
const string[] image = new string[]{
" ",
" ################# ############# ",
" ################## ... |
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:
################# #############
################## ################
#################... | #Elixir | Elixir | defmodule ZhangSuen do
@neighbours [{-1,0},{-1,1},{0,1},{1,1},{1,0},{1,-1},{0,-1},{-1,-1}] # 8 neighbours
def thinning(str, black \\ ?#) do
s0 = for {line, i} <- (String.split(str, "\n") |> Enum.with_index),
{c, j} <- (to_char_list(line) |> Enum.with_index),
into: Map.new,
... |
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.
| #XPL0 | XPL0 | real A, B, R, T, X, Y;
[SetVid($12); \set 640x480 graphics
A:= 0.0; B:= 3.0; T:= 0.0;
Move(320, 240); \start at center of screen
repeat R:= A + B*T;
X:= R*Cos(T); Y:= R*Sin(T);
Line(fix(X)+320, 240-fix(Y), 4\red\);
T:= T + 0.03; \increase angle (Theta)
until T >= 314.15... |
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.
| #Yabasic | Yabasic | 5 OPEN WINDOW 320, 200 : WINDOW ORIGIN "CC"
10 LET A=1.5
20 LET B=0.7
30 FOR T=0 TO 30*PI STEP 0.05
40 LET R=A+B*T
50 LINE TO R*COS(T),R*SIN(T)
60 NEXT T |
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.
| #zkl | zkl | fcn archimedeanSpiral(a,b,circles){
w,h:=640,640; centerX,centerY:=w/2,h/2;
bitmap:=PPM(w+1,h+1,0xFF|FF|FF); // White background
foreach deg in ([0.0 .. 360*circles]){
rad:=deg.toRad();
r:=rad*b + a;
x,y:=r.toRectangular(rad);
bitmap[centerX + x, centerY + y] = 0x00|FF|00; // Green ... |
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, ... | #C.2B.2B | C++ |
// For a class N which implements Zeckendorf numbers:
// I define an increment operation ++()
// I define a comparison operation <=(other N)
// Nigel Galloway October 22nd., 2012
#include <iostream>
class N {
private:
int dVal = 0, dLen;
public:
N(char const* x = "0"){
int i = 0, q = 1;
for (; x[i] > 0; i... |
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... | #bc | bc | /* 0 means door is closed, 1 means door is open */
for (i = 0; i < 100; i++) {
for (j = i; j < 100; j += (i + 1)) {
d[j] = 1 - d[j] /* Toggle door */
}
}
"Open doors:
"
for (i = 0; i < 100; i++) {
if (d[i] == 1) (i + 1)
} |
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,... | #Dragon | Dragon | array = newarray(3) //optionally, replace "newarray(5)" with a brackets list of values like "[1, 2, 3]"
array[0] = 42
showln array[2] |
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... | #Nanoquery | Nanoquery | import math
class Complex
declare real
declare imag
def Complex()
real = 0.0
imag = 0.0
end
def Complex(r, i)
real = double(r)
imag = double(i)
end
def operator-(b)
return new(... |
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... | #Nemerle | Nemerle | using System;
using System.Console;
using System.Numerics;
using System.Numerics.Complex;
module RCComplex
{
PrettyPrint(this c : Complex) : string
{
mutable sign = '+';
when (c.Imaginary < 0) sign = '-';
$"$(c.Real) $sign $(Math.Abs(c.Imaginary))i"
}
Main() : void
{
... |
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... | #PARI.2FGP | PARI/GP | for(n=2,1<<19,
s=0;
fordiv(n,d,s+=1/d);
if(s==2,print(n))
) |
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... | #Raku | Raku | sub agm( $a is copy, $g is copy ) {
($a, $g) = ($a + $g)/2, sqrt $a * $g until $a ≅ $g;
return $a;
}
say agm 1, 1/sqrt 2; |
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... | #Raven | Raven | define agm use $a, $g, $errlim
# $errlim $g $a "%d %g %d\n" print
$a 1.0 + as $t
repeat $a 1.0 * $g - abs -15 exp10 $a * > while
$a $g + 2 / as $t
$a $g * sqrt as $g
$t as $a
$g $a $t "t: %g a: %g g: %g\n" print
$a
16 1 2 sqrt / 1 agm "agm: %.15g\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, ... | #Delphi | Delphi | print pow 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, ... | #EasyLang | EasyLang | 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 ... | #Oz | Oz | declare
fun {Expr X0 ?X}
choice
[L _ R] = {Do [Term &+ Expr] X0 ?X} in add(L R)
[] [L _ R] = {Do [Term &- Expr] X0 ?X} in sub(L R)
[] {Term X0 X}
end
end
fun {Term X0 ?X}
choice
[L _ R] = {Do [Factor &* Term] X0 ?X} in mul(L R)
[] [L _ R] = {Do [Factor &/ Term] X0... |
http://rosettacode.org/wiki/Zeckendorf_arithmetic | Zeckendorf arithmetic | This task is a total immersion zeckendorf task; using decimal numbers will attract serious disapprobation.
The task is to implement addition, subtraction, multiplication, and division using Zeckendorf number representation. Optionally provide decrement, increment and comparitive operation functions.
Addition
Like bin... | #C | C | #include <stdbool.h>
#include <stdio.h>
#include <string.h>
int inv(int a) {
return a ^ -1;
}
struct Zeckendorf {
int dVal, dLen;
};
void a(struct Zeckendorf *self, int n) {
void b(struct Zeckendorf *, int); // forward declare
int i = n;
while (true) {
if (self->dLen < i) self->dLen ... |
http://rosettacode.org/wiki/Zumkeller_numbers | Zumkeller numbers | Zumkeller numbers are the set of numbers whose divisors can be partitioned into two disjoint sets that sum to the same value. Each sum must contain divisor values that are not in the other sum, and all of the divisors must be in one or the other. There are no restrictions on how the divisors are partitioned, only that ... | #C.23 | C# | using System;
using System.Collections.Generic;
using System.Linq;
namespace ZumkellerNumbers {
class Program {
static List<int> GetDivisors(int n) {
List<int> divs = new List<int> {
1, n
};
for (int i = 2; i * i <= n; i++) {
if (n % i ==... |
http://rosettacode.org/wiki/Arbitrary-precision_integers_(included) | Arbitrary-precision integers (included) | Using the in-built capabilities of your language, calculate the integer value of:
5
4
3
2
... | #Ada | Ada | with Ada.Text_IO; use Ada.Text_IO;
with GNATCOLL.GMP; use GNATCOLL.GMP;
with GNATCOLL.GMP.Integers; use GNATCOLL.GMP.Integers;
procedure ArbitraryInt is
type stracc is access String;
BigInt : Big_Integer;
len : Natural;
str : stracc;
begin
Set (BigInt, 5);
Raise_To_N (BigInt, Unsigned_Long (4**(3**2))... |
http://rosettacode.org/wiki/Arbitrary-precision_integers_(included) | Arbitrary-precision integers (included) | Using the in-built capabilities of your language, calculate the integer value of:
5
4
3
2
... | #ALGOL_68 | ALGOL 68 |
BEGIN
COMMENT
The task specifies
"Strictly speaking, this should not be solved by fixed-precision
numeric libraries where the precision has to be manually set to a
large value; although if this is the only recourse then it may be
used with a note explaining that the precision must be set manually
... |
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:
################# #############
################## ################
#################... | #Fortran | Fortran | FOR ALL (i = 2:n - 1) A(i) = (A(i - 1) + A(i) + A(i + 1))/3 |
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:
################# #############
################## ################
#################... | #FreeBASIC | FreeBASIC | ' version 08-10-2016
' compile with: fbc -s console
Data "00000000000000000000000000000000"
Data "01111111110000000111111110000000"
Data "01110001111000001111001111000000"
Data "01110000111000001110000111000000"
Data "01110001111000001110000000000000"
Data "01111111110000001110000000000000"
Data "01110111100000001110... |
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, ... | #Clojure | Clojure | (def fibs (lazy-cat [1 1] (map + fibs (rest fibs))))
(defn z [n]
(if (zero? n)
"0"
(let [ps (->> fibs (take-while #(<= % n)) rest reverse)
fz (fn [[s n] p]
(if (>= n p)
[(conj s 1) (- n p)]
[(conj s 0) n]))]
(->> ps (reduce fz [[] n]) first... |
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... | #BCPL | BCPL | get "libhdr"
let start() be
$( let doors = vec 100
// close all doors
for n = 1 to 100 do doors!n := 0
// make 100 passes
for pass = 1 to 100 do
$( let n = pass
while n <= 100 do
$( doors!n := ~doors!n
n := n + pass
$)
$)
// report which doors ... |
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,... | #DWScript | DWScript |
// dynamic array, extensible, this a reference type
var d : array of Integer;
d.Add(1); // has various methods to add, delete, etc.
d.Add(2, 3);
// read and write elements by index
item := d[5];
d[6] := item+1;
// static, fixed-size array, arbitrary lower-bound, this is a value type
var s : array [2..4] of In... |
Subsets and Splits
Rosetta Code COBOL Python Hard Tasks
Identifies and retrieves challenging tasks that exist in both COBOL and Python, revealing cross-language programming patterns and difficulty levels for comparative analysis.
Rosetta Code Task Comparisons
Identifies tasks common to both COBOL and Python languages that are described as having difficulty levels, revealing cross-language task similarities and providing useful comparative programming examples.
Select Specific Languages Codes
Retrieves specific programming language names and codes from training data, providing basic filtering but limited analytical value beyond identifying these particular languages.