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/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.
| #C | C |
#include<graphics.h>
#include<stdio.h>
#include<math.h>
#define pi M_PI
int main(){
double a,b,cycles,incr,i;
int steps,x=500,y=500;
printf("Enter the parameters a and b : ");
scanf("%lf%lf",&a,&b);
printf("Enter cycles : ");
scanf("%lf",&cycles);
printf("Enter divisional steps : ");
scanf("%d",&s... |
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... | #Aikido | Aikido |
var doors = new int [100]
foreach pass 100 {
for (var door = pass ; door < 100 ; door += pass+1) {
doors[door] = !doors[door]
}
}
var d = 1
foreach door doors {
println ("door " + d++ + " is " + (door ? "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,... | #BQN | BQN | # Stranding:
arr ← 1‿2‿'a'‿+‿5
# General List Syntax:
arr1 ← ⟨1,2,'a',+,5⟩
•Show arr ≡ arr1 # both arrays are the same.
•Show arr
•Show arr1
# Taking nth element(⊑):
•Show 3⊑arr
# Modifying the array(↩):
arr ↩ "hello"⌾(4⊸⊑) 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... | #Forth | Forth | S" fsl-util.fs" REQUIRED
S" complex.fs" REQUIRED
zvariable x
zvariable y
1e 1e x z!
pi 1.2e y z!
x z@ y z@ z+ z.
x z@ y z@ z* z.
1e 0e zconstant 1+0i
1+0i x z@ z/ z.
x z@ znegate z. |
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... | #Go | Go | package main
import (
"fmt"
"math"
"math/big"
)
func main() {
var recip big.Rat
max := int64(1 << 19)
for candidate := int64(2); candidate < max; candidate++ {
sum := big.NewRat(1, candidate)
max2 := int64(math.Sqrt(float64(candidate)))
for factor := int64(2); factor ... |
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... | #jq | jq | def naive_agm(a; g; tolerance):
def abs: if . < 0 then -. else . end;
def _agm:
# state [an,gn]
if ((.[0] - .[1])|abs) > tolerance
then [add/2, ((.[0] * .[1])|sqrt)] | _agm
else .
end;
[a, g] | _agm | .[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... | #Julia | Julia | function agm(x, y, e::Real = 5)
(x ≤ 0 || y ≤ 0 || e ≤ 0) && throw(DomainError("x, y must be strictly positive"))
g, a = minmax(x, y)
while e * eps(x) < a - g
a, g = (a + g) / 2, sqrt(a * g)
end
a
end
x, y = 1.0, 1 / √2
println("# Using literal-precision float numbers:")
@show agm(x, y)
... |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #ZX_Spectrum_Basic | ZX Spectrum Basic | 5 LET a=5: LET b=3
10 PRINT a;" + ";b;" = ";a+b
20 PRINT a;" - ";b;" = ";a-b
30 PRINT a;" * ";b;" = ";a*b
40 PRINT a;" / ";b;" = ";INT (a/b)
50 PRINT a;" mod ";b;" = ";a-INT (a/b)*b
60 PRINT a;" to the power of ";b;" = ";a^b
|
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 ... | #Elena | Elena | import system'routines;
import extensions;
import extensions'text;
class Token
{
object theValue;
rprop int Level;
constructor new(int level)
{
theValue := new StringWriter();
Level := level + 9;
}
append(ch)
{
theValue.write(ch)
}
Number = theValue.... |
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.
| #C.23 | C# | using System;
using System.Linq;
using System.Drawing;
using System.Diagnostics;
using System.Drawing.Drawing2D;
class Program
{
const int width = 380;
const int height = 380;
static PointF archimedeanPoint(int degrees)
{
const double a = 1;
const double b = 9;
double t = degre... |
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... | #ALGOL_60 | ALGOL 60 |
begin
comment - 100 doors problem in ALGOL-60;
boolean array doors[1:100];
integer i, j;
boolean open, closed;
open := true;
closed := not true;
outstring(1,"100 Doors Problem\n");
comment - all doors are initially closed;
for i := 1 step 1 until 100 do
doors[i] := closed;
comment
cycle through at inc... |
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,... | #Bracmat | Bracmat | ( tbl$(mytable,100)
& 5:?(30$mytable)
& 9:?(31$mytable)
& out$(!(30$mytable))
& out$(!(-169$mytable)) { -169 mod 100 == 31 }
& out$!mytable { still index 31 }
& tbl$(mytable,0)
& (!mytable & out$"mytable still exists"
| out$"mytable is gone"
)
); |
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... | #Fortran | Fortran | program cdemo
complex :: a = (5,3), b = (0.5, 6.0) ! complex initializer
complex :: absum, abprod, aneg, ainv
absum = a + b
abprod = a * b
aneg = -a
ainv = 1.0 / a
end program cdemo |
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... | #Groovy | Groovy | class Rational extends Number implements Comparable {
final BigInteger num, denom
static final Rational ONE = new Rational(1)
static final Rational ZERO = new Rational(0)
Rational(BigDecimal decimal) {
this(
decimal.scale() < 0 ? decimal.unscaledValue() * 10 ** -decimal.scale() : dec... |
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... | #Klingphix | Klingphix | include ..\Utilitys.tlhy
:agm [ over over + 2 / rot rot * sqrt ] [ over over tostr swap tostr # ] while drop ;
1 1 2 sqrt / agm
pstack
" " input |
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... | #Kotlin | Kotlin | // version 1.0.5-2
fun agm(a: Double, g: Double): Double {
var aa = a // mutable 'a'
var gg = g // mutable 'g'
var ta: Double // temporary variable to hold next iteration of 'aa'
val epsilon = 1.0e-16 // tolerance for checking if limit has been reached
while (tru... |
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 ... | #Emacs_Lisp | Emacs Lisp | #!/usr/bin/env emacs --script
;; -*- mode: emacs-lisp; lexical-binding: t -*-
;;> ./arithmetic-evaluation '(1 + 2) * 3'
(defun advance ()
(let ((rtn (buffer-substring-no-properties (point) (match-end 0))))
(goto-char (match-end 0))
rtn))
(defvar current-symbol nil)
(defun next-symbol ()
(when (looking... |
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.
| #C.2B.2B | C++ |
#include <windows.h>
#include <string>
#include <iostream>
const int BMP_SIZE = 600;
class myBitmap {
public:
myBitmap() : pen( NULL ), brush( NULL ), clr( 0 ), wid( 1 ) {}
~myBitmap() {
DeleteObject( pen ); DeleteObject( brush );
DeleteDC( hdc ); DeleteObject( bmp );
}
bool create... |
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... | #ALGOL_68 | ALGOL 68 | # declare some constants #
INT limit = 100;
PROC doors = VOID:
(
MODE DOORSTATE = BOOL;
BOOL closed = FALSE;
BOOL open = NOT closed;
MODE DOORLIST = [limit]DOORSTATE;
DOORLIST the doors;
FOR i FROM LWB the doors TO UPB the doors DO the doors[i]:=closed OD;
FOR i FROM LWB the doors TO UPB the doors D... |
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,... | #Brainf.2A.2A.2A | Brainf*** |
===========[
ARRAY DATA STRUCTURE
AUTHOR: Keith Stellyes
WRITTEN: June 2016
This is a zero-based indexing array data structure, it assumes the following
precondition:
>INDEX<|NULL|VALUE|NULL|VALUE|NULL|VALUE|NULL
(Where >< mark pointer position, and | separates addresses)
It relies heavily on [>] and [<] b... |
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... | #FreeBASIC | FreeBASIC | ' FB 1.05.0 Win64
Type Complex
As Double real, imag
Declare Constructor(real As Double, imag As Double)
Declare Function invert() As Complex
Declare Function conjugate() As Complex
Declare Operator cast() As String
End Type
Constructor Complex(real As Double, imag As Double)
This.real = real
This.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... | #Haskell | Haskell | import Data.Ratio ((%))
-- Prints the first N perfect numbers.
main = do
let n = 4
mapM_ print $
take
n
[ candidate
| candidate <- [2 .. 2 ^ 19]
, getSum candidate == 1 ]
where
getSum candidate =
1 % candidate +
sum
[ 1 % factor + 1 % (candidate `div` factor)... |
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... | #LFE | LFE |
(defun agm (a g)
(agm a g 1.0e-15))
(defun agm (a g tol)
(if (=< (- a g) tol)
a
(agm (next-a a g)
(next-g a g)
tol)))
(defun next-a (a g)
(/ (+ a g) 2))
(defun next-g (a g)
(math:sqrt (* a g)))
|
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... | #Liberty_BASIC | Liberty BASIC |
print agm(1, 1/sqr(2))
print using("#.#################",agm(1, 1/sqr(2)))
function agm(a,g)
do
absdiff = abs(a-g)
an=(a+g)/2
gn=sqr(a*g)
a=an
g=gn
loop while abs(an-gn)< absdiff
agm = a
end function
|
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 ... | #ERRE | ERRE |
PROGRAM EVAL
!
! arithmetic expression evaluator
!
!$KEY
LABEL 98,100,110
DIM STACK$[50]
PROCEDURE DISEGNA_STACK
!$RCODE="LOCATE 3,1"
!$RCODE="COLOR 0,7"
PRINT(TAB(35);"S T A C K";TAB(79);)
!$RCODE="COLOR 7,0"
FOR TT=1 TO 38 DO
IF TT>=20 THEN
!$RCODE="LOCATE 3+TT-19,40"
ELSE
... |
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.
| #Clojure | Clojure |
(use '(incanter core stats charts io))
(defn Arquimidean-function
[a b theta]
(+ a (* theta b)))
(defn transform-pl-xy [r theta]
(let [x (* r (sin theta))
y (* r (cos theta))]
[x y]))
(defn arq-spiral [t] (transform-pl-xy (Arquimidean-function 0 7 t) t))
(view (parametric-plot arq-spiral 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.
| #Common_Lisp | Common Lisp | (defun draw-coords-as-text (coords size fill-char)
(let* ((min-x (apply #'min (mapcar #'car coords)))
(min-y (apply #'min (mapcar #'cdr coords)))
(max-x (apply #'max (mapcar #'car coords)))
(max-y (apply #'max (mapcar #'cdr coords)))
(real-size (max (+ (abs min-x) (abs max-x)) ; bo... |
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... | #ALGOL_W | ALGOL W | begin
% find the first few squares via the unoptimised door flipping method %
integer doorMax;
doorMax := 100;
begin
% need to start a new block so the array can have variable bounds %
% array of doors - door( i ) is true if open, false if closed %
logical array d... |
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,... | #C | C | int myArray2[10] = { 1, 2, 0 }; /* the rest of elements get the value 0 */
float myFloats[] ={1.2, 2.5, 3.333, 4.92, 11.2, 22.0 }; /* automatically sizes */ |
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... | #Free_Pascal | Free Pascal | Program ComplexDemo;
uses
ucomplex;
var
a, b, absum, abprod, aneg, ainv, acong: complex;
function complex(const re, im: real): ucomplex.complex; overload;
begin
complex.re := re;
complex.im := im;
end;
begin
a := complex(5, 3);
b := complex(0.5, 6.0);
absum := a + b;
writeln (... |
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... | #Icon_and_Unicon | Icon and Unicon | procedure main()
limit := 2^19
write("Perfect numbers up to ",limit," (using rational arithmetic):")
every write(is_perfect(c := 2 to limit))
write("End of perfect numbers")
# verify the rest of the implementation
zero := makerat(0) # from integer
half := makerat(0.5) # from r... |
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... | #LiveCode | LiveCode | function agm aa,g
put abs(aa-g) into absdiff
put (aa+g)/2 into aan
put sqrt(aa*g) into gn
repeat while abs(aan - gn) < absdiff
put abs(aa-g) into absdiff
put (aa+g)/2 into aan
put sqrt(aa*g) into gn
put aan into aa
put gn into g
end repeat
return aa
end ... |
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... | #LLVM | LLVM | ; This is not strictly LLVM, as it uses the C library function "printf".
; LLVM does not provide a way to print values, so the alternative would be
; to just load the string into memory, and that would be boring.
; Additional comments have been inserted, as well as changes made from the output produced by clang such ... |
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 ... | #F.23 | F# | module AbstractSyntaxTree
type Expression =
| Int of int
| Plus of Expression * Expression
| Minus of Expression * Expression
| Times of Expression * Expression
| Divide of Expression * Expression |
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.
| #FOCAL | FOCAL | 1.1 S A=1.5
1.2 S B=2
1.3 S N=250
1.4 F T=1,N; D 2
1.5 X FSKP(2*N)
1.6 Q
2.1 S R=A+B*T; D 3
2.2 X FPT(2*T,X1+512,Y1+390)
2.3 S R=A+B*(T+1); D 4
2.4 X FVEC(2*T+1,X2-X1,Y2-Y1)
3.1 S X1=R*FSIN(.2*T)
3.2 S Y1=R*FCOS(.2*T)
4.1 S X2=R*FSIN(.2*(T+1))
4.2 S Y2=R*FCOS(.2*(T+1)) |
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.
| #Frege | Frege | module Archimedean where
import Java.IO
import Prelude.Math
data BufferedImage = native java.awt.image.BufferedImage where
pure native type_3byte_bgr "java.awt.image.BufferedImage.TYPE_3BYTE_BGR" :: Int
native new :: Int -> Int -> Int -> STMutable s BufferedImage
native createGraphics :: Mutable s BufferedIma... |
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.
| #Go | Go | package main
import (
"image"
"image/color"
"image/draw"
"image/png"
"log"
"math"
"os"
)
func main() {
const (
width, height = 600, 600
centre = width / 2.0
degreesIncr = 0.1 * math.Pi / 180
turns = 2
stop = 360 * turns * 10 * degreesIncr
fileName = "spiral.png"
)... |
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... | #ALGOL-M | ALGOL-M |
BEGIN
INTEGER ARRAY DOORS[1:100];
INTEGER I, J, OPEN, CLOSED;
OPEN := 1;
CLOSED := 0;
% ALL DOORS ARE INITIALLY CLOSED %
FOR I := 1 STEP 1 UNTIL 100 DO
BEGIN
DOORS[I] := CLOSED;
END;
% PASS THROUGH AT INCREASING INTERVALS AND FLIP %
FOR I := 1 STEP 1 UNTIL 100 DO
BEGIN
FOR J := I STEP I UNTIL 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,... | #C.23 | C# | int[] numbers = new int[10]; |
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... | #Frink | Frink |
add[x,y] := x + y
multiply[x,y] := x * y
negate[x] := -x
invert[x] := 1/x // Could also use inv[x] or recip[x]
conjugate[x] := Re[x] - Im[x] i
a = 3 + 2.5i
b = 7.3 - 10i
println["$a + $b = " + add[a,b]]
println["$a * $b = " + multiply[a,b]]
println["-$a = " + negate[a]]
println["1/$a = " + invert[a]]
println["conj... |
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... | #J | J | (x: 3) % (x: -4)
_3r4
3 %&x: -4
_3r4 |
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... | #Logo | Logo | to about :a :b
output and [:a - :b < 1e-15] [:a - :b > -1e-15]
end
to agm :arith :geom
if about :arith :geom [output :arith]
output agm (:arith + :geom)/2 sqrt (:arith * :geom)
end
show 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... | #Lua | Lua | function agm(a, b, tolerance)
if not tolerance or tolerance < 1e-15 then
tolerance = 1e-15
end
repeat
a, b = (a + b) / 2, math.sqrt(a * b)
until math.abs(a-b) < tolerance
return a
end
print(string.format("%.15f", agm(1, 1 / math.sqrt(2)))) |
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 ... | #Factor | Factor | USING: accessors kernel locals math math.parser peg.ebnf ;
IN: rosetta.arith
TUPLE: operator left right ;
TUPLE: add < operator ; C: <add> add
TUPLE: sub < operator ; C: <sub> sub
TUPLE: mul < operator ; C: <mul> mul
TUPLE: div < operator ; C: <div> div
EBNF: expr-ast
spaces = [\n\t ]*
digit = [0-9]
nu... |
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.
| #Haskell | Haskell | #!/usr/bin/env stack
-- stack --resolver lts-7.0 --install-ghc runghc --package Rasterific --package JuicyPixels
import Codec.Picture( PixelRGBA8( .. ), writePng )
import Graphics.Rasterific
import Graphics.Rasterific.Texture
import Graphics.Rasterific.Transformations
archimedeanPoint a b t = V2 x y
where r = a +... |
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.
| #J | J | require'plot'
'aspect 1' plot (*^)j.0.01*i.1400 |
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... | #AmigaE | AmigaE | PROC main()
DEF t[100]: ARRAY,
pass, door
FOR door := 0 TO 99 DO t[door] := FALSE
FOR pass := 0 TO 99
door := pass
WHILE door <= 99
t[door] := Not(t[door])
door := door + pass + 1
ENDWHILE
ENDFOR
FOR door := 0 TO 99 DO WriteF('\d is \s\n', door+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,... | #C.2B.2B | C++ | #include <array>
#include <vector>
// These headers are only needed for the demonstration
#include <algorithm>
#include <iostream>
#include <iterator>
#include <string>
// This is a template function that works for any array-like object
template <typename Array>
void demonstrate(Array& array)
{
// Array element a... |
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... | #Futhark | Futhark |
type complex = (f64,f64)
fun complexAdd((a,b): complex) ((c,d): complex): complex =
(a + c,
b + d)
fun complexMult((a,b): complex) ((c,d): complex): complex =
(a*c - b * d,
a*d + b * c)
fun complexInv((r,i): complex): complex =
let denom = r*r + i * i
in (r / denom,
-i / denom)
fun complexNe... |
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... | #GAP | GAP | # GAP knows gaussian integers, gaussian rationals (i.e. Q[i]), and cyclotomic fields. Here are some examples.
# E(n) is an nth primitive root of 1
i := Sqrt(-1);
# E(4)
(3 + 2*i)*(5 - 7*i);
# 29-11*E(4)
1/i;
# -E(4)
Sqrt(-3);
# E(3)-E(3)^2
i in GaussianIntegers;
# true
i/2 in GaussianIntegers;
# false
i/2 in Gaussian... |
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... | #Java | Java | public class BigRationalFindPerfectNumbers {
public static void main(String[] args) {
int MAX_NUM = 1 << 19;
System.out.println("Searching for perfect numbers in the range [1, " + (MAX_NUM - 1) + "]");
BigRational TWO = BigRational.valueOf(2);
for (int i = 1; i < MAX_NUM; i++) {
... |
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... | #M2000_Interpreter | M2000 Interpreter |
Module Checkit {
Function Agm {
\\ new stack constructed at calling the Agm() with two values
Repeat {
Read a0, b0
Push Sqrt(a0*b0), (a0+b0)/2
' last pushed first read
} Until Stackitem(1)==Stackitem(2)
=Stackitem(... |
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... | #Maple | Maple |
> evalf( GaussAGM( 1, 1 / sqrt( 2 ) ) ); # default precision is 10 digits
0.8472130847
> evalf[100]( GaussAGM( 1, 1 / sqrt( 2 ) ) ); # to 100 digits
0.847213084793979086606499123482191636481445910326942185060579372659\
7340048341347597232002939946112300
|
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 ... | #FreeBASIC | FreeBASIC |
'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... |
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.
| #Java | Java | import java.awt.*;
import static java.lang.Math.*;
import javax.swing.*;
public class ArchimedeanSpiral extends JPanel {
public ArchimedeanSpiral() {
setPreferredSize(new Dimension(640, 640));
setBackground(Color.white);
}
void drawGrid(Graphics2D g) {
g.setColor(new Color(0xEE... |
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... | #APL | APL | doors←{100⍴((⍵-1)⍴0),1}
≠⌿⊃doors¨ ⍳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,... | #Ceylon | Ceylon | import ceylon.collection {
ArrayList
}
shared void run() {
// you can get an array from the Array.ofSize named constructor
value array = Array.ofSize(10, "hello");
value a = array[3];
print(a);
array[4] = "goodbye";
print(array);
// for a dynamic list import ceylon.collection in your module.ceylon file
... |
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... | #Go | Go | package main
import (
"fmt"
"math/cmplx"
)
func main() {
a := 1 + 1i
b := 3.14159 + 1.25i
fmt.Println("a: ", a)
fmt.Println("b: ", b)
fmt.Println("a + b: ", a+b)
fmt.Println("a * b: ", a*b)
fmt.Println("-a: ", -a)
fmt.Println("1 / a: ", 1/a)
fmt.Println("... |
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... | #JavaScript | JavaScript | // the constructor
function Rational(numerator, denominator) {
if (denominator === undefined)
denominator = 1;
else if (denominator == 0)
throw "divide by zero";
this.numer = numerator;
if (this.numer == 0)
this.denom = 1;
else
this.denom = denominator;
this.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... | #Mathematica.2FWolfram_Language | Mathematica/Wolfram Language | PrecisionDigits = 85;
AGMean[a_, b_] := FixedPoint[{ Tr@#/2, Sqrt[Times@@#] }&, N[{a,b}, PrecisionDigits]]〚1〛 |
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... | #MATLAB_.2F_Octave | MATLAB / Octave | function [a,g]=agm(a,g)
%%arithmetic_geometric_mean(a,g)
while (1)
a0=a;
a=(a0+g)/2;
g=sqrt(a0*g);
if (abs(a0-a) < a*eps) break; end;
end;
end |
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 ... | #Go | Go | enum Op {
ADD('+', 2),
SUBTRACT('-', 2),
MULTIPLY('*', 1),
DIVIDE('/', 1);
static {
ADD.operation = { a, b -> a + b }
SUBTRACT.operation = { a, b -> a - b }
MULTIPLY.operation = { a, b -> a * b }
DIVIDE.operation = { a, b -> a / b }
}
final String symbol
... |
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.
| #JavaScript | JavaScript |
<!-- ArchiSpiral.html -->
<html>
<head><title>Archimedean spiral</title></head>
<body onload="pAS(35,'navy');">
<h3>Archimedean spiral</h3> <p id=bo></p>
<canvas id="canvId" width="640" height="640" style="border: 2px outset;"></canvas>
<script>
// Plotting Archimedean_spiral aev 3/17/17
// lps - number of loops, clr... |
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.
| #jq | jq | def spiral($zero; $turns; $step):
def pi: 1 | atan * 4;
def p2: (. * 100 | round) / 100;
def svg:
400 as $width
| 400 as $height
| 2 as $swidth # stroke
| "blue" as $stroke
| (range($zero; $turns * 2 * pi; $step) as $theta
| (((($theta)|cos) * 2 * $theta + ($width/2)) |p2) as $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.
| #Julia | Julia | using UnicodePlots
spiral(θ, a=0, b=1) = @. b * θ * cos(θ + a), b * θ * sin(θ + a)
x, y = spiral(1:0.1:10)
println(lineplot(x, y)) |
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... | #AppleScript | AppleScript | set is_open to {}
repeat 100 times
set end of is_open to false
end
repeat with pass from 1 to 100
repeat with door from pass to 100 by pass
set item door of is_open to not item door of is_open
end
end
set open_doors to {}
repeat with door from 1 to 100
if item door of is_open then
set end of open_doo... |
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,... | #ChucK | ChucK |
int array[0]; // instantiate int array
array << 1; // append item
array << 2 << 3; // append items
4 => array[3]; // assign element(4) to index(3)
5 => array.size; // resize
array.clear(); // clear elements
<<<array.size()>>>; // print in cosole array size
[1,2,3,4,5,6,7] @=> array;
array.popBack(); // Pop last eleme... |
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... | #Groovy | Groovy | class Complex {
final Number real, imag
static final Complex i = [0,1] as Complex
Complex(Number r, Number i = 0) { (real, imag) = [r, i] }
Complex(Map that) { (real, imag) = [that.real ?: 0, that.imag ?: 0] }
Complex plus (Complex c) { [real + c.real, imag + c.imag] as Complex }
Complex... |
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... | #jq | jq | # a and b are assumed to be non-zero integers
def gcd(a; b):
# subfunction expects [a,b] as input
# i.e. a ~ .[0] and b ~ .[1]
def rgcd: if .[1] == 0 then .[0]
else [.[1], .[0] % .[1]] | rgcd
end;
[a,b] | rgcd;
# To take advantage of gojq's support for accurate integer division:
def idivide... |
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... | #Maxima | Maxima | agm(a, b) := %pi/4*(a + b)/elliptic_kc(((a - b)/(a + b))^2)$
agm(1, 1/sqrt(2)), bfloat, fpprec: 85;
/* 8.472130847939790866064991234821916364814459103269421850605793726597340048341347597232b-1 */ |
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... | #.D0.9C.D0.9A-61.2F52 | МК-61/52 | П1 <-> П0 1 ВП 8 /-/ П2 ИП0 ИП1
- ИП2 - /-/ x<0 31 ИП1 П3 ИП0 ИП1
* КвКор П1 ИП0 ИП3 + 2 / П0 БП
08 ИП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 ... | #Groovy | Groovy | enum Op {
ADD('+', 2),
SUBTRACT('-', 2),
MULTIPLY('*', 1),
DIVIDE('/', 1);
static {
ADD.operation = { a, b -> a + b }
SUBTRACT.operation = { a, b -> a - b }
MULTIPLY.operation = { a, b -> a * b }
DIVIDE.operation = { a, b -> a / b }
}
final String symbol
... |
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.
| #Kotlin | Kotlin | // version 1.1.0
import java.awt.*
import javax.swing.*
class ArchimedeanSpiral : JPanel() {
init {
preferredSize = Dimension(640, 640)
background = Color.white
}
private fun drawGrid(g: Graphics2D) {
g.color = Color(0xEEEEEE)
g.stroke = BasicStroke(2f)
val angl... |
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... | #Arbre | Arbre |
openshut(n):
for x in [1..n]
x%n==0
pass(n):
if n==100
openshut(n)
else
openshut(n) xor pass(n+1)
100doors():
pass(1) -> io
|
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,... | #Clean | Clean | array :: {String}
array = {"Hello", "World"} |
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... | #Hare | Hare | use fmt;
use math::complex::{c128,addc128,mulc128,divc128,negc128,conjc128};
export fn main() void = {
let x: c128 = (1.0, 1.0);
let y: c128 = (3.14159265, 1.2);
// addition
let (re, im) = addc128(x, y);
fmt::printfln("{} + {}i", re, im)!;
// multiplication
let (re, im) = mulc128(x, y);
fmt::printfln("{} + ... |
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... | #Haskell | Haskell | import Data.Complex
main = do
let a = 1.0 :+ 2.0 -- complex number 1+2i
let b = 4 -- complex number 4+0i
-- 'b' is inferred to be complex because it's used in
-- arithmetic with 'a' below.
putStrLn $ "Add: " ++ show (a + b)
putStrLn $ "Subtract: " ++ show (a - b)
putStrLn $ "Multipl... |
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... | #Julia | Julia | using Primes
divisors(n) = foldl((a, (p, e)) -> vcat((a * [p^i for i in 0:e]')...), factor(n), init=[1])
isperfect(n) = sum(1 // d for d in divisors(n)) == 2
lo, hi = 2, 2^19
println("Perfect numbers between ", lo, " and ", hi, ": ", collect(filter(isperfect, lo:hi)))
|
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... | #Modula-2 | Modula-2 | MODULE AGM;
FROM EXCEPTIONS IMPORT AllocateSource,ExceptionSource,GetMessage,RAISE;
FROM LongConv IMPORT ValueReal;
FROM LongMath IMPORT sqrt;
FROM LongStr IMPORT RealToStr;
FROM Terminal IMPORT ReadChar,Write,WriteString,WriteLn;
VAR
TextWinExSrc : ExceptionSource;
PROCEDURE ReadReal() : LONGREAL;
VAR
buff... |
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, ... | #11l | 11l | print(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 ... | #Haskell | Haskell | {-# LANGUAGE FlexibleContexts #-}
import Text.Parsec
import Text.Parsec.Expr
import Text.Parsec.Combinator
import Data.Functor
import Data.Function (on)
data Exp
= Num Int
| Add Exp
Exp
| Sub Exp
Exp
| Mul Exp
Exp
| Div Exp
Exp
expr
:: Stream s m Char
=> ParsecT s u m... |
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.
| #Lua | Lua |
a=1
b=2
cycles=40
step=0.001
x=0
y=0
function love.load()
x = love.graphics.getWidth()/2
y = love.graphics.getHeight()/2
end
function love.draw()
love.graphics.print("a="..a,16,16)
love.graphics.print("b="..b,16,32)
for i=0,cycles*math.pi,step do
love.graphics.points(x+(a + b*... |
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.
| #M2000_Interpreter | M2000 Interpreter |
module Archimedean_spiral {
smooth on ' enable GDI+
def r(θ)=5+3*θ
cls #002222,0
pen #FFFF00
refresh 5000
every 1000 {
\\ redifine window (console width and height) and place it to center (symbol ;)
Window 12, random(10, 18)*1000, random(8, 12)*1000;
move scale.x/2, scale.y/2
let N=2, k1=pi/120, k=k1, o... |
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... | #Argile | Argile | use std, array
close all doors
for each pass from 1 to 100
for (door = pass) (door <= 100) (door += pass)
toggle door
let int pass, door.
.: close all doors :. {memset doors 0 size of doors}
.:toggle <int door>:. { !!(doors[door - 1]) }
let doors be an array of 100 bool
for each door from 1 to 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,... | #Clipper | Clipper | // Declare and initialize two-dimensional array
Local arr1 := { { "NITEM","N",10,0 }, { "CONTENT","C",60,0} }
// Create an empty array
Local arr2 := {}
// Declare three-dimensional array
Local arr3[2,100,3]
// Create an array
Local arr4 := Array(50)
// Array can be dynamically resized:
a... |
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... | #Icon_and_Unicon | Icon and Unicon | procedure main()
SetupComplex()
a := complex(1,2)
b := complex(3,4)
c := complex(&pi,1.5)
d := complex(1)
e := complex(,1)
every v := !"abcde" do write(v," := ",cpxstr(variable(v)))
write("a+b := ", cpxstr(cpxadd(a,b)))
write("a-b := ", cpxstr(cpxsub(a,b)))
write("a*b := ", cpxstr(cpxmul(a,b)))
write("a/b :=... |
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... | #Kotlin | Kotlin | // version 1.1.2
fun gcd(a: Long, b: Long): Long = if (b == 0L) a else gcd(b, a % b)
infix fun Long.ldiv(denom: Long) = Frac(this, denom)
infix fun Int.idiv(denom: Int) = Frac(this.toLong(), denom.toLong())
fun Long.toFrac() = Frac(this, 1)
fun Int.toFrac() = Frac(this.toLong(), 1)
class Frac : Comparable<F... |
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... | #NetRexx | NetRexx | /* NetRexx */
options replace format comments java crossref symbols nobinary
numeric digits 18
parse arg a_ g_ .
if a_ = '' | a_ = '.' then a0 = 1
else a0 = a_
if g_ = '' | g_ = '.' then g0 = 1 / Math.sqrt(2)
else g0 = g_
say agm(a0, g0)
return
-- ~~~~~~~~~~~~~~~~~~~~... |
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, ... | #8th | 8th |
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, ... | #Action.21 | Action! | INCLUDE "D2:REAL.ACT" ;from the Action! Tool Kit
PROC Main()
REAL z,res
Put(125) PutE() ;clear the screen
IntToReal(0,z)
Power(z,z,res)
PrintR(z) Print("^")
PrintR(z) Print("=")
PrintRE(res)
RETURN |
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 ... | #Icon_and_Unicon | Icon and Unicon | procedure main() #: simple arithmetical parser / evaluator
write("Usage: Input expression = Abstract Syntax Tree = Value, ^Z to end.")
repeat {
writes("Input expression : ")
if not writes(line := read()) then break
if map(line) ? { (x := E()) & pos(... |
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.
| #Maple | Maple |
plots[polarplot](1+2*theta, theta = 0 .. 6*Pi)
|
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.
| #Mathematica.2FWolfram_Language | Mathematica/Wolfram Language | With[{a = 5, b = 4}, PolarPlot[a + b t, {t, 0, 10 Pi}]] |
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.
| #MATLAB | MATLAB | a = 1;
b = 1;
turns = 2;
theta = 0:0.1:2*turns*pi;
polarplot(theta, a + b*theta); |
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... | #ARM_Assembly | ARM Assembly |
/* ARM assembly Raspberry PI */
/* program 100doors.s */
/************************************/
/* Constantes */
/************************************/
.equ STDOUT, 1 @ Linux output console
.equ EXIT, 1 @ Linux syscall
.eq... |
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,... | #Clojure | Clojure | ;clojure is a language built with immutable/persistent data structures. there is no concept of changing what a vector/list
;is, instead clojure creates a new array with an added value using (conj...)
;in the example below the my-list does not change.
user=> (def my-list (list 1 2 3 4 5))
user=> my-list
(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... | #IDL | IDL | x=complex(1,1)
y=complex(!pi,1.2)
print,x+y
( 4.14159, 2.20000)
print,x*y
( 1.94159, 4.34159)
print,-x
( -1.00000, -1.00000)
print,1/x
( 0.500000, -0.500000) |
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... | #Liberty_BASIC | Liberty BASIC |
n=2^19
for testNumber=1 to n
sum$=castToFraction$(0)
for factorTest=1 to sqr(testNumber)
if GCD(factorTest,testNumber)=factorTest then sum$=add$(sum$,add$(reciprocal$(castToFraction$(factorTest)),reciprocal$(castToFraction$(testNumber/factorTest))))
next factorTest
if equal(sum$,castToFraction... |
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... | #NewLISP | NewLISP |
(define (a-next a g) (mul 0.5 (add a g)))
(define (g-next a g) (sqrt (mul a g)))
(define (amg a g tolerance)
(if (<= (sub a g) tolerance)
a
(amg (a-next a g) (g-next a g) tolerance)
)
)
(define quadrillionth 0.000000000000001)
(define root-reciprocal-2 (div 1.0 (sqrt 2.0)))
(println
"To the nearest ... |
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, ... | #Ada | Ada | with Ada.Text_IO, Ada.Integer_Text_IO, Ada.Long_Integer_Text_IO,
Ada.Long_Long_Integer_Text_IO, Ada.Float_Text_IO, Ada.Long_Float_Text_IO,
Ada.Long_Long_Float_Text_IO;
use Ada.Text_IO, Ada.Integer_Text_IO, Ada.Long_Integer_Text_IO,
Ada.Long_Long_Integer_Text_IO, Ada.Float_Text_IO, Ada.Long_Float_Text_IO,
Ada.L... |
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.