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/Cholesky_decomposition | Cholesky decomposition | Every symmetric, positive definite matrix A can be decomposed into a product of a unique lower triangular matrix L and its transpose:
A
=
L
L
T
{\displaystyle A=LL^{T}}
L
{\displaystyle L}
is called the Cholesky factor of
A
{\displaystyle A}
, and can be interpreted as a generalized square r... | #Wren | Wren | import "/matrix" for Matrix
import "/fmt" for Fmt
var arrays = [
[ [25, 15, -5],
[15, 18, 0],
[-5, 0, 11] ],
[ [18, 22, 54, 42],
[22, 70, 86, 62],
[54, 86, 174, 134],
[42, 62, 134, 106] ]
]
for (array in arrays) {
System.print("Original:")
Fmt.mprint(array, 3, 0... |
http://rosettacode.org/wiki/Collections | Collections | This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task.
Collections are abstractions to represent sets of values.
In statically-typed languages, the values are typically of a common data type.
Task
Create a collection, and add a fe... | #Raven | Raven | [ 1 2 3 'abc' ] as a_list
a_list print
list (4 items)
0 => 1
1 => 2
2 => 3
3 => "abc" |
http://rosettacode.org/wiki/Combinations | Combinations | Task
Given non-negative integers m and n, generate all size m combinations of the integers from 0 (zero) to n-1 in sorted order (each combination is sorted and the entire table is sorted).
Example
3 comb 5 is:
0 1 2
0 1 3
0 1 4
0 2 3
0 2 4
0 3 4
1 2 3
1 2 4
1 3 4
2 3 4
... | #Ursala | Ursala | choices = ^(iota@r,~&l); leql@a^& ~&al?\&! ~&arh2fabt2RDfalrtPXPRT |
http://rosettacode.org/wiki/Conditional_structures | Conditional structures | Control Structures
These are examples of control structures. You may also be interested in:
Conditional structures
Exceptions
Flow-control structures
Loops
Task
List the conditional structures offered by a programming language. See Wikipedia: conditionals for descriptions.
Common conditional structures include ... | #Wren | Wren | for (b in [true, false]) {
if (b) {
System.print(true)
} else {
System.print(false)
}
// equivalent code using ternary operator
System.print(b ? true : false)
// equivalent code using && operator
System.print(b && true)
// equivalent code using || operator
Syste... |
http://rosettacode.org/wiki/Classes | Classes | In object-oriented programming class is a set (a transitive closure) of types bound by the relation of inheritance. It is said that all types derived from some base type T and the type T itself form a class T.
The first type T from the class T sometimes is called the root type of the class.
A class of types itself, a... | #TIScript | TIScript | class Car
{
//Constructor function.
function this(brand, weight, price = 0) {
this.brand = brand;
this.weight = weight || 1000; // Resort to default value (with 'or' notation).
this._price = price;
}
property price(v) // computable property, special kind of member function
{
get { return this... |
http://rosettacode.org/wiki/Circles_of_given_radius_through_two_points | Circles of given radius through two points |
Given two points on a plane and a radius, usually two circles of given radius can be drawn through the points.
Exceptions
r==0.0 should be treated as never describing circles (except in the case where the points are coincident).
If the points are coincident then an infinite number of circles with the point on thei... | #Stata | Stata | real matrix centers(real colvector a, real colvector b, real scalar r) {
real matrix rot
real scalar d, u, v
d = norm(b-a)
if (r == 0 | d == 0) {
if (r == 0 & d == 0) {
return((a,a))
} else {
return(J(2, 2, .))
}
} else if (d <= 2*r) {
u = d/(2*r)
v = sqrt(1-u^2)
rot = u,-v\v,u
return((rot*(b-a... |
http://rosettacode.org/wiki/Check_that_file_exists | Check that file exists | Task
Verify that a file called input.txt and a directory called docs exist.
This should be done twice:
once for the current working directory, and
once for a file and a directory in the filesystem root.
Optional criteria (May 2015): verify it works with:
zero-length files
an ... | #NewLISP | NewLISP | (dolist (file '("input.txt" "/input.txt"))
(if (file? file true)
(println "file " file " exists")))
(dolist (dir '("docs" "/docs"))
(if (directory? dir)
(println "directory " dir " exists"))) |
http://rosettacode.org/wiki/Check_that_file_exists | Check that file exists | Task
Verify that a file called input.txt and a directory called docs exist.
This should be done twice:
once for the current working directory, and
once for a file and a directory in the filesystem root.
Optional criteria (May 2015): verify it works with:
zero-length files
an ... | #Nim | Nim | import os
echo fileExists "input.txt"
echo fileExists "/input.txt"
echo dirExists "docs"
echo dirExists "/docs" |
http://rosettacode.org/wiki/Character_codes | Character codes |
Task
Given a character value in your language, print its code (could be ASCII code, Unicode code, or whatever your language uses).
Example
The character 'a' (lowercase letter A) has a code of 97 in ASCII (as well as Unicode, as ASCII forms the beginning of Unicode).
Conversely, given a code, print out... | #langur | langur | val .a1 = 'a'
val .a2 = 97
val .a3 = "a"[1]
val .a4 = s2cp "a", 1
val .a5 = [.a1, .a2, .a3, .a4]
writeln .a1 == .a2
writeln .a2 == .a3
writeln .a3 == .a4
writeln "numbers: ", join ", ", [.a1, .a2, .a3, .a4, .a5]
writeln "letters: ", join ", ", [cp2s(.a1), cp2s(.a2), cp2s(.a3), cp2s(.a4), cp2s(.a5)] |
http://rosettacode.org/wiki/Character_codes | Character codes |
Task
Given a character value in your language, print its code (could be ASCII code, Unicode code, or whatever your language uses).
Example
The character 'a' (lowercase letter A) has a code of 97 in ASCII (as well as Unicode, as ASCII forms the beginning of Unicode).
Conversely, given a code, print out... | #Lasso | Lasso | 'a'->integer
'A'->integer
97->bytes
65->bytes |
http://rosettacode.org/wiki/Cholesky_decomposition | Cholesky decomposition | Every symmetric, positive definite matrix A can be decomposed into a product of a unique lower triangular matrix L and its transpose:
A
=
L
L
T
{\displaystyle A=LL^{T}}
L
{\displaystyle L}
is called the Cholesky factor of
A
{\displaystyle A}
, and can be interpreted as a generalized square r... | #zkl | zkl | var [const] GSL=Import("zklGSL"); // libGSL (GNU Scientific Library)
fcn lowerCholesky(m){ // trans: C
rows:=m.rows;
lcm:=GSL.Matrix(rows,rows); // zero filled
foreach i,j in (rows,i+1){
s:=(0).reduce(j,'wrap(s,k){ s + lcm[i,k]*lcm[j,k] },0.0);
lcm[i,j]=( if(i==j)(m[i,i] - s).sqrt()
els... |
http://rosettacode.org/wiki/Cholesky_decomposition | Cholesky decomposition | Every symmetric, positive definite matrix A can be decomposed into a product of a unique lower triangular matrix L and its transpose:
A
=
L
L
T
{\displaystyle A=LL^{T}}
L
{\displaystyle L}
is called the Cholesky factor of
A
{\displaystyle A}
, and can be interpreted as a generalized square r... | #ZX_Spectrum_Basic | ZX Spectrum Basic | 10 LET d=2000: GO SUB 1000: GO SUB 4000: GO SUB 5000
20 LET d=3000: GO SUB 1000: GO SUB 4000: GO SUB 5000
30 STOP
1000 RESTORE d
1010 READ a,b
1020 DIM m(a,b)
1040 FOR i=1 TO a
1050 FOR j=1 TO b
1060 READ m(i,j)
1070 NEXT j
1080 NEXT i
1090 RETURN
2000 DATA 3,3,25,15,-5,15,18,0,-5,0,11
3000 DATA 4,4,18,22,54,42,22,70... |
http://rosettacode.org/wiki/Collections | Collections | This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task.
Collections are abstractions to represent sets of values.
In statically-typed languages, the values are typically of a common data type.
Task
Create a collection, and add a fe... | #REXX | REXX | pr. = /*define a default for all elements for the array*/
pr.1 = 2 /*note that this array starts at 1 (one). */
pr.2 = 3
pr.3 = 5
pr.4 = 7
pr.5 = 11
pr.6 = 13
pr.7 = 17
pr.8 = 19
pr.9 = 23
pr.10 = 29
pr.11 = 31
pr.12 = 37
pr.13 = 41
pr.14 = 43
pr.15 ... |
http://rosettacode.org/wiki/Combinations | Combinations | Task
Given non-negative integers m and n, generate all size m combinations of the integers from 0 (zero) to n-1 in sorted order (each combination is sorted and the entire table is sorted).
Example
3 comb 5 is:
0 1 2
0 1 3
0 1 4
0 2 3
0 2 4
0 3 4
1 2 3
1 2 4
1 3 4
2 3 4
... | #V | V | [comb [m lst] let
[ [m zero?] [[[]]]
[lst null?] [[]]
[true] [m pred lst rest comb [lst first swap cons] map
m lst rest comb concat]
] when]. |
http://rosettacode.org/wiki/Conditional_structures | Conditional structures | Control Structures
These are examples of control structures. You may also be interested in:
Conditional structures
Exceptions
Flow-control structures
Loops
Task
List the conditional structures offered by a programming language. See Wikipedia: conditionals for descriptions.
Common conditional structures include ... | #X86_Assembly | X86 Assembly |
if(i>1)
DoSomething
FailedSoContinueCodeExecution.
|
http://rosettacode.org/wiki/Conditional_structures | Conditional structures | Control Structures
These are examples of control structures. You may also be interested in:
Conditional structures
Exceptions
Flow-control structures
Loops
Task
List the conditional structures offered by a programming language. See Wikipedia: conditionals for descriptions.
Common conditional structures include ... | #XLISP | XLISP | (if (eq s "Rosetta Code")
"The well-known programming chrestomathy site"
"Some other website, maybe, I dunno" ) |
http://rosettacode.org/wiki/Classes | Classes | In object-oriented programming class is a set (a transitive closure) of types bound by the relation of inheritance. It is said that all types derived from some base type T and the type T itself form a class T.
The first type T from the class T sometimes is called the root type of the class.
A class of types itself, a... | #Transd | Transd | #lang transd
class Point : {
x: Double(),
y: Double(),
@init: (λ v Vector<Double>() (= x (get v 0)) (= y (get v 1))),
print: (λ (textout "Point(" x "; " y ")\n" ))
}
MainModule: {
v_: [[1.0, 2.0], [3.0, 4.0]],
_start: (λ
// creating an instance of class
(with pt Point([5.0, 6.0])
... |
http://rosettacode.org/wiki/Circles_of_given_radius_through_two_points | Circles of given radius through two points |
Given two points on a plane and a radius, usually two circles of given radius can be drawn through the points.
Exceptions
r==0.0 should be treated as never describing circles (except in the case where the points are coincident).
If the points are coincident then an infinite number of circles with the point on thei... | #Swift | Swift | import Foundation
struct Point: Equatable {
var x: Double
var y: Double
}
struct Circle {
var center: Point
var radius: Double
static func circleBetween(
_ p1: Point,
_ p2: Point,
withRadius radius: Double
) -> (Circle, Circle?)? {
func applyPoint(_ p1: Point, _ p2: Point, op: (Dou... |
http://rosettacode.org/wiki/Check_that_file_exists | Check that file exists | Task
Verify that a file called input.txt and a directory called docs exist.
This should be done twice:
once for the current working directory, and
once for a file and a directory in the filesystem root.
Optional criteria (May 2015): verify it works with:
zero-length files
an ... | #Objeck | Objeck |
use IO;
bundle Default {
class Test {
function : Main(args : String[]) ~ Nil {
File->Exists("input.txt")->PrintLine();
File->Exists("/input.txt")->PrintLine();
Directory->Exists("docs")->PrintLine();
Directory->Exists("/docs")->PrintLine();
}
}
|
http://rosettacode.org/wiki/Character_codes | Character codes |
Task
Given a character value in your language, print its code (could be ASCII code, Unicode code, or whatever your language uses).
Example
The character 'a' (lowercase letter A) has a code of 97 in ASCII (as well as Unicode, as ASCII forms the beginning of Unicode).
Conversely, given a code, print out... | #LFE | LFE | > (list 68 111 110 39 116 32 80 97 110 105 99 46)
"Don't Panic." |
http://rosettacode.org/wiki/Character_codes | Character codes |
Task
Given a character value in your language, print its code (could be ASCII code, Unicode code, or whatever your language uses).
Example
The character 'a' (lowercase letter A) has a code of 97 in ASCII (as well as Unicode, as ASCII forms the beginning of Unicode).
Conversely, given a code, print out... | #Liberty_BASIC | Liberty BASIC | charCode = 97
char$ = "a"
print chr$(charCode) 'prints a
print asc(char$) 'prints 97 |
http://rosettacode.org/wiki/Collections | Collections | This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task.
Collections are abstractions to represent sets of values.
In statically-typed languages, the values are typically of a common data type.
Task
Create a collection, and add a fe... | #Ring | Ring |
text = list(2)
text[1] = "Hello "
text[2] = "world!"
see text[1] + text[2] + nl
|
http://rosettacode.org/wiki/Combinations | Combinations | Task
Given non-negative integers m and n, generate all size m combinations of the integers from 0 (zero) to n-1 in sorted order (each combination is sorted and the entire table is sorted).
Example
3 comb 5 is:
0 1 2
0 1 3
0 1 4
0 2 3
0 2 4
0 3 4
1 2 3
1 2 4
1 3 4
2 3 4
... | #VBA | VBA | Option Explicit
Option Base 0
'Option Base 1
Private ArrResult
Sub test()
'compute
Main_Combine 5, 3
'return
Dim j As Long, i As Long, temp As String
For i = LBound(ArrResult, 1) To UBound(ArrResult, 1)
temp = vbNullString
For j = LBound(ArrResult, 2) To UBound(ArrResult, 2)
... |
http://rosettacode.org/wiki/Conditional_structures | Conditional structures | Control Structures
These are examples of control structures. You may also be interested in:
Conditional structures
Exceptions
Flow-control structures
Loops
Task
List the conditional structures offered by a programming language. See Wikipedia: conditionals for descriptions.
Common conditional structures include ... | #XPL0 | XPL0 | if BOOLEAN EXPRESSION then STATEMENT
if BOOLEAN EXPRESSION then STATEMENT else STATEMENT
if BOOLEAN EXPRESSION then EXPRESSION else EXPRESSION
case INTEGER EXPRESSION of
INTEGER EXPRESSION, ... INTEGER EXPRESSION: STATEMENT;
...
INTEGER EXPRESSION, ... INTEGER ... |
http://rosettacode.org/wiki/Classes | Classes | In object-oriented programming class is a set (a transitive closure) of types bound by the relation of inheritance. It is said that all types derived from some base type T and the type T itself form a class T.
The first type T from the class T sometimes is called the root type of the class.
A class of types itself, a... | #TXR | TXR | (defstruct shape ()
cached-area
(:init (self)
(put-line `@self is born!`))
(:fini (self)
(put-line `@self says goodbye!`))
(:method area (self)
(or self.cached-area
(set self.cached-area self.(calc-area)))))
(defstruct circle shape
(radius 1.0)
(:method calc-area (self)
(* ... |
http://rosettacode.org/wiki/Classes | Classes | In object-oriented programming class is a set (a transitive closure) of types bound by the relation of inheritance. It is said that all types derived from some base type T and the type T itself form a class T.
The first type T from the class T sometimes is called the root type of the class.
A class of types itself, a... | #UNIX_Shell | UNIX Shell | typeset -T Summation_t=(
integer sum
# the constructor
function create {
_.sum=0
}
# a method
function add {
(( _.sum += $1 ))
}
)
Summation_t s
for i in 1 2 3 4 5; do
s.add $i
done
print ${s.sum} |
http://rosettacode.org/wiki/Circles_of_given_radius_through_two_points | Circles of given radius through two points |
Given two points on a plane and a radius, usually two circles of given radius can be drawn through the points.
Exceptions
r==0.0 should be treated as never describing circles (except in the case where the points are coincident).
If the points are coincident then an infinite number of circles with the point on thei... | #Tcl | Tcl | proc findCircles {p1 p2 r} {
lassign $p1 x1 y1
lassign $p2 x2 y2
# Special case: coincident & zero size
if {$x1 == $x2 && $y1 == $y2 && $r == 0.0} {
return [list [list $x1 $y1 0.0]]
}
if {$r <= 0.0} {
error "radius must be positive for sane results"
}
if {$x1 == $x2 && $y1 == $y2} {
e... |
http://rosettacode.org/wiki/Check_that_file_exists | Check that file exists | Task
Verify that a file called input.txt and a directory called docs exist.
This should be done twice:
once for the current working directory, and
once for a file and a directory in the filesystem root.
Optional criteria (May 2015): verify it works with:
zero-length files
an ... | #Objective-C | Objective-C | NSFileManager *fm = [NSFileManager defaultManager];
NSLog(@"input.txt %s", [fm fileExistsAtPath:@"input.txt"] ? @"exists" : @"doesn't exist");
NSLog(@"docs %s", [fm fileExistsAtPath:@"docs"] ? @"exists" : @"doesn't exist"); |
http://rosettacode.org/wiki/Character_codes | Character codes |
Task
Given a character value in your language, print its code (could be ASCII code, Unicode code, or whatever your language uses).
Example
The character 'a' (lowercase letter A) has a code of 97 in ASCII (as well as Unicode, as ASCII forms the beginning of Unicode).
Conversely, given a code, print out... | #LIL | LIL | print [char 97]
print [codeat "a" 0] |
http://rosettacode.org/wiki/Character_codes | Character codes |
Task
Given a character value in your language, print its code (could be ASCII code, Unicode code, or whatever your language uses).
Example
The character 'a' (lowercase letter A) has a code of 97 in ASCII (as well as Unicode, as ASCII forms the beginning of Unicode).
Conversely, given a code, print out... | #Lingo | Lingo | -- returns Unicode code point (=ASCII code for ASCII characters) for character
put chartonum("a")
-- 97
-- returns character for Unicode code point (=ASCII code for ASCII characters)
put numtochar(934)
-- Φ |
http://rosettacode.org/wiki/Collections | Collections | This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task.
Collections are abstractions to represent sets of values.
In statically-typed languages, the values are typically of a common data type.
Task
Create a collection, and add a fe... | #Ruby | Ruby | # creating an empty array and adding values
a = [] #=> []
a[0] = 1 #=> [1]
a[3] = "abc" #=> [1, nil, nil, "abc"]
a << 3.14 #=> [1, nil, nil, "abc", 3.14]
# creating an array with the constructor
a = Array.new #=> []
a = Array.new(3) #=> [nil, nil, nil]... |
http://rosettacode.org/wiki/Combinations | Combinations | Task
Given non-negative integers m and n, generate all size m combinations of the integers from 0 (zero) to n-1 in sorted order (each combination is sorted and the entire table is sorted).
Example
3 comb 5 is:
0 1 2
0 1 3
0 1 4
0 2 3
0 2 4
0 3 4
1 2 3
1 2 4
1 3 4
2 3 4
... | #VBScript | VBScript |
Function Dec2Bin(n)
q = n
Dec2Bin = ""
Do Until q = 0
Dec2Bin = CStr(q Mod 2) & Dec2Bin
q = Int(q / 2)
Loop
Dec2Bin = Right("00000" & Dec2Bin,6)
End Function
Sub Combination(n,k)
Dim arr()
ReDim arr(n-1)
For h = 0 To n-1
arr(h) = h + 1
Next
Set list = CreateObject("System.Collections.Arraylist")
Fo... |
http://rosettacode.org/wiki/Conditional_structures | Conditional structures | Control Structures
These are examples of control structures. You may also be interested in:
Conditional structures
Exceptions
Flow-control structures
Loops
Task
List the conditional structures offered by a programming language. See Wikipedia: conditionals for descriptions.
Common conditional structures include ... | #XSLT | XSLT | <xsl:if test="condition">
<!-- executed if XPath expression evaluates to true -->
</xsl:if> |
http://rosettacode.org/wiki/Classes | Classes | In object-oriented programming class is a set (a transitive closure) of types bound by the relation of inheritance. It is said that all types derived from some base type T and the type T itself form a class T.
The first type T from the class T sometimes is called the root type of the class.
A class of types itself, a... | #Vala | Vala | public class MyClass : Object {
// Instance variable
public int variable;
// Method
public void some_method() {
variable = 24;
}
// Constructor
public MyClass() {
variable = 42;
}
}
void main() {
// Class instance
MyClass instance = new MyClass();
print... |
http://rosettacode.org/wiki/Circles_of_given_radius_through_two_points | Circles of given radius through two points |
Given two points on a plane and a radius, usually two circles of given radius can be drawn through the points.
Exceptions
r==0.0 should be treated as never describing circles (except in the case where the points are coincident).
If the points are coincident then an infinite number of circles with the point on thei... | #VBA | VBA | Public Sub circles()
tests = [{0.1234, 0.9876, 0.8765, 0.2345, 2.0; 0.0000, 2.0000, 0.0000, 0.0000, 1.0; 0.1234, 0.9876, 0.1234, 0.9876, 2.0; 0.1234, 0.9876, 0.8765, 0.2345, 0.5; 0.1234, 0.9876, 0.1234, 0.9876, 0.0}]
For i = 1 To UBound(tests)
x1 = tests(i, 1)
y1 = tests(i, 2)
x2 = tests... |
http://rosettacode.org/wiki/Check_that_file_exists | Check that file exists | Task
Verify that a file called input.txt and a directory called docs exist.
This should be done twice:
once for the current working directory, and
once for a file and a directory in the filesystem root.
Optional criteria (May 2015): verify it works with:
zero-length files
an ... | #OCaml | OCaml | Sys.file_exists "input.txt";;
Sys.file_exists "docs";;
Sys.file_exists "/input.txt";;
Sys.file_exists "/docs";; |
http://rosettacode.org/wiki/Check_that_file_exists | Check that file exists | Task
Verify that a file called input.txt and a directory called docs exist.
This should be done twice:
once for the current working directory, and
once for a file and a directory in the filesystem root.
Optional criteria (May 2015): verify it works with:
zero-length files
an ... | #ooRexx | ooRexx | /**********************************************************************
* exists(filespec)
* returns 1 if filespec identifies a file with size>0
* (a file of size 0 is deemed not to exist.)
* or a directory
* 0 otherwise
* 09.06.2013 Walter Pachl (retrieved from my toolset)
******... |
http://rosettacode.org/wiki/Character_codes | Character codes |
Task
Given a character value in your language, print its code (could be ASCII code, Unicode code, or whatever your language uses).
Example
The character 'a' (lowercase letter A) has a code of 97 in ASCII (as well as Unicode, as ASCII forms the beginning of Unicode).
Conversely, given a code, print out... | #Little | Little | puts("Unicode value of ñ is ${scan("ñ", "%c")}");
printf("The code 241 in Unicode is the letter: %c.\n", 241);
|
http://rosettacode.org/wiki/Collections | Collections | This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task.
Collections are abstractions to represent sets of values.
In statically-typed languages, the values are typically of a common data type.
Task
Create a collection, and add a fe... | #Rust | Rust | let a = [1u8,2,3,4,5]; // a is of type [u8; 5];
let b = [0;256] // Equivalent to `let b = [0,0,0,0,0,0... repeat 256 times]` |
http://rosettacode.org/wiki/Combinations | Combinations | Task
Given non-negative integers m and n, generate all size m combinations of the integers from 0 (zero) to n-1 in sorted order (each combination is sorted and the entire table is sorted).
Example
3 comb 5 is:
0 1 2
0 1 3
0 1 4
0 2 3
0 2 4
0 3 4
1 2 3
1 2 4
1 3 4
2 3 4
... | #Wren | Wren | import "./perm" for Comb
var fib = Fiber.new { Comb.generate((0..4).toList, 3) }
while (true) {
var c = fib.call()
if (!c) return
System.print(c)
} |
http://rosettacode.org/wiki/Conditional_structures | Conditional structures | Control Structures
These are examples of control structures. You may also be interested in:
Conditional structures
Exceptions
Flow-control structures
Loops
Task
List the conditional structures offered by a programming language. See Wikipedia: conditionals for descriptions.
Common conditional structures include ... | #Yabasic | Yabasic |
// if-then-endif, switch / end switch
// on gosub, on goto
// repeat / until, do / loop, while / end while
if expr_booleana then
sentencia(s)
endif
if expr_booleana sentencia(s)
if expr_booleana1 then
sentencia(s)
elsif expr_booleana2
sentencia(s)
elsif expr_booleana3 then
sentencia(s)
else
... |
http://rosettacode.org/wiki/Classes | Classes | In object-oriented programming class is a set (a transitive closure) of types bound by the relation of inheritance. It is said that all types derived from some base type T and the type T itself form a class T.
The first type T from the class T sometimes is called the root type of the class.
A class of types itself, a... | #VBA | VBA | Private Const m_default = 10
Private m_bar As Integer
Private Sub Class_Initialize()
'constructor, can be used to set default values
m_bar = m_default
End Sub
Private Sub Class_Terminate()
'destructor, can be used to do some cleaning up
'here we just print a message
Debug.Print "---object destroyed---"
En... |
http://rosettacode.org/wiki/Circles_of_given_radius_through_two_points | Circles of given radius through two points |
Given two points on a plane and a radius, usually two circles of given radius can be drawn through the points.
Exceptions
r==0.0 should be treated as never describing circles (except in the case where the points are coincident).
If the points are coincident then an infinite number of circles with the point on thei... | #Visual_Basic_.NET | Visual Basic .NET | Public Class CirclesOfGivenRadiusThroughTwoPoints
Public Shared Sub Main()
For Each valu In New Double()() {
New Double() {0.1234, 0.9876, 0.8765, 0.2345, 2},
New Double() {0.0, 2.0, 0.0, 0.0, 1},
New Double() {0.1234, 0.9876, 0.1234, 0.9876, 2},
New Double() {0.1234, 0.9876,... |
http://rosettacode.org/wiki/Check_that_file_exists | Check that file exists | Task
Verify that a file called input.txt and a directory called docs exist.
This should be done twice:
once for the current working directory, and
once for a file and a directory in the filesystem root.
Optional criteria (May 2015): verify it works with:
zero-length files
an ... | #Oz | Oz | declare
[Path] = {Module.link ['x-oz://system/os/Path.ozf']}
in
{Show {Path.exists "docs"}}
{Show {Path.exists "input.txt"}}
{Show {Path.exists "/docs"}}
{Show {Path.exists "/input.txt"}} |
http://rosettacode.org/wiki/Check_that_file_exists | Check that file exists | Task
Verify that a file called input.txt and a directory called docs exist.
This should be done twice:
once for the current working directory, and
once for a file and a directory in the filesystem root.
Optional criteria (May 2015): verify it works with:
zero-length files
an ... | #PARI.2FGP | PARI/GP | trap(,"does not exist",read("input.txt");"exists")
trap(,"does not exist",read("c:\\input.txt");"exists")
trap(,"does not exist",read("c:\\dirname\\nul");"exists") |
http://rosettacode.org/wiki/Character_codes | Character codes |
Task
Given a character value in your language, print its code (could be ASCII code, Unicode code, or whatever your language uses).
Example
The character 'a' (lowercase letter A) has a code of 97 in ASCII (as well as Unicode, as ASCII forms the beginning of Unicode).
Conversely, given a code, print out... | #LiveCode | LiveCode | Since 7.0.x works with unicode
put charToNum("") && numToChar(240) |
http://rosettacode.org/wiki/Character_codes | Character codes |
Task
Given a character value in your language, print its code (could be ASCII code, Unicode code, or whatever your language uses).
Example
The character 'a' (lowercase letter A) has a code of 97 in ASCII (as well as Unicode, as ASCII forms the beginning of Unicode).
Conversely, given a code, print out... | #Logo | Logo | print ascii "a ; 97
print char 97 ; a |
http://rosettacode.org/wiki/Collections | Collections | This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task.
Collections are abstractions to represent sets of values.
In statically-typed languages, the values are typically of a common data type.
Task
Create a collection, and add a fe... | #Scala | Scala | Windows PowerShell
Copyright (C) 2012 Microsoft Corporation. All rights reserved.
PS C:\Users\FransAdm> scala
Welcome to Scala version 2.10.1 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_25).
Type in expressions to have them evaluated.
Type :help for more information.
scala> // Immutable collections do not and ca... |
http://rosettacode.org/wiki/Combinations | Combinations | Task
Given non-negative integers m and n, generate all size m combinations of the integers from 0 (zero) to n-1 in sorted order (each combination is sorted and the entire table is sorted).
Example
3 comb 5 is:
0 1 2
0 1 3
0 1 4
0 2 3
0 2 4
0 3 4
1 2 3
1 2 4
1 3 4
2 3 4
... | #XPL0 | XPL0 | code ChOut=8, CrLf=9, IntOut=11;
def M=3, N=5;
int A(N-1);
proc Combos(D, S); \Display all size M combinations of N in sorted order
int D, S; \depth of recursion, starting value of N
int I;
[if D<M then \depth < size
for I:= S to N-1 do
[A(D):= I;
Combos(D+1, I+1);... |
http://rosettacode.org/wiki/Conditional_structures | Conditional structures | Control Structures
These are examples of control structures. You may also be interested in:
Conditional structures
Exceptions
Flow-control structures
Loops
Task
List the conditional structures offered by a programming language. See Wikipedia: conditionals for descriptions.
Common conditional structures include ... | #Z80_Assembly | Z80 Assembly |
char x;
if (x == 20)
{
doThis();
}
else
{
doThat();
} |
http://rosettacode.org/wiki/Classes | Classes | In object-oriented programming class is a set (a transitive closure) of types bound by the relation of inheritance. It is said that all types derived from some base type T and the type T itself form a class T.
The first type T from the class T sometimes is called the root type of the class.
A class of types itself, a... | #Visual_Basic_.NET | Visual Basic .NET | Class Foo
Private m_Bar As Integer
Public Sub New()
End Sub
Public Sub New(ByVal bar As Integer)
m_Bar = bar
End Sub
Public Property Bar() As Integer
Get
Return m_Bar
End Get
Set(ByVal value As Integer)
m_Bar = value
End Set
End Prope... |
http://rosettacode.org/wiki/Circles_of_given_radius_through_two_points | Circles of given radius through two points |
Given two points on a plane and a radius, usually two circles of given radius can be drawn through the points.
Exceptions
r==0.0 should be treated as never describing circles (except in the case where the points are coincident).
If the points are coincident then an infinite number of circles with the point on thei... | #Visual_FoxPro | Visual FoxPro |
LOCAL p1 As point, p2 As point, rr As Double
CLOSE DATABASES ALL
SET FIXED ON
SET DECIMALS TO 4
CLEAR
CREATE CURSOR circles (xc1 B(4), yc1 B(4), xc2 B(4), yc2 B(4), rad B(4))
INSERT INTO circles VALUES (0.1234, 0.9876, 0.8765, 0.2345, 2.0)
INSERT INTO circles VALUES (0.0000, 2.0000, 0.0000, 0.0000, 1.0)
INSERT INTO c... |
http://rosettacode.org/wiki/Check_that_file_exists | Check that file exists | Task
Verify that a file called input.txt and a directory called docs exist.
This should be done twice:
once for the current working directory, and
once for a file and a directory in the filesystem root.
Optional criteria (May 2015): verify it works with:
zero-length files
an ... | #Pascal | Pascal | use File::Spec::Functions qw(catfile rootdir);
# here
print -e 'input.txt';
print -d 'docs';
# root dir
print -e catfile rootdir, 'input.txt';
print -d catfile rootdir, 'docs'; |
http://rosettacode.org/wiki/Check_that_file_exists | Check that file exists | Task
Verify that a file called input.txt and a directory called docs exist.
This should be done twice:
once for the current working directory, and
once for a file and a directory in the filesystem root.
Optional criteria (May 2015): verify it works with:
zero-length files
an ... | #Perl | Perl | use File::Spec::Functions qw(catfile rootdir);
# here
print -e 'input.txt';
print -d 'docs';
# root dir
print -e catfile rootdir, 'input.txt';
print -d catfile rootdir, 'docs'; |
http://rosettacode.org/wiki/Character_codes | Character codes |
Task
Given a character value in your language, print its code (could be ASCII code, Unicode code, or whatever your language uses).
Example
The character 'a' (lowercase letter A) has a code of 97 in ASCII (as well as Unicode, as ASCII forms the beginning of Unicode).
Conversely, given a code, print out... | #Logtalk | Logtalk | |?- char_code(Char, 97), write(Char).
a
Char = a
yes |
http://rosettacode.org/wiki/Collections | Collections | This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task.
Collections are abstractions to represent sets of values.
In statically-typed languages, the values are typically of a common data type.
Task
Create a collection, and add a fe... | #Scheme | Scheme | (list obj ...) |
http://rosettacode.org/wiki/Combinations | Combinations | Task
Given non-negative integers m and n, generate all size m combinations of the integers from 0 (zero) to n-1 in sorted order (each combination is sorted and the entire table is sorted).
Example
3 comb 5 is:
0 1 2
0 1 3
0 1 4
0 2 3
0 2 4
0 3 4
1 2 3
1 2 4
1 3 4
2 3 4
... | #zkl | zkl | fcn comb(k,seq){ // no repeats, seq is finite
seq=seq.makeReadOnly(); // because I append to parts of seq
fcn(k,seq){
if(k<=0) return(T(T));
if(not seq) return(T);
self.fcn(k-1,seq[1,*]).pump(List,seq[0,1].extend)
.extend(self.fcn(k,seq[1,*]));
}(k,seq);
} |
http://rosettacode.org/wiki/Conditional_structures | Conditional structures | Control Structures
These are examples of control structures. You may also be interested in:
Conditional structures
Exceptions
Flow-control structures
Loops
Task
List the conditional structures offered by a programming language. See Wikipedia: conditionals for descriptions.
Common conditional structures include ... | #zkl | zkl | if (x) y else z;
if(a)b else if (c) else d; etc
x:=(if (a) b else c);
a and b or c // usually the same as if(a) b else c, beware if b evals to False
switch(x){
case(1){...}
case("2"){...} // matches anything
case(a)[fallthrough]{...} // no break, no break has to be explicit
case(b){...}
else {...} // c... |
http://rosettacode.org/wiki/Classes | Classes | In object-oriented programming class is a set (a transitive closure) of types bound by the relation of inheritance. It is said that all types derived from some base type T and the type T itself form a class T.
The first type T from the class T sometimes is called the root type of the class.
A class of types itself, a... | #Visual_FoxPro | Visual FoxPro |
LOCAL o1 As MyClass, o2 As MyClass
*!* Instantiate o1
o1 = NEWOBJECT("MyClass")
o1.ShowInstance()
*!* Instantiate o2
o2 = CREATEOBJECT("MyClass", 2)
o2.ShowInstance()
DEFINE CLASS MyClass As Session
*!* Custom property (protected)
PROTECTED nInstance
nInstance = 0
*!* Constructor
PROCEDURE Init(tnInstance As I... |
http://rosettacode.org/wiki/Classes | Classes | In object-oriented programming class is a set (a transitive closure) of types bound by the relation of inheritance. It is said that all types derived from some base type T and the type T itself form a class T.
The first type T from the class T sometimes is called the root type of the class.
A class of types itself, a... | #Wren | Wren | class Bear {
// Constructs a Bear instance passing it a name
// which is stored in the field _name
// automatically created by Wren.
construct new(name) { _name = name }
// Property to get the name
name { _name }
// Method to make a noise.
makeNoise() { System.print("Growl!") }
}
/... |
http://rosettacode.org/wiki/Circles_of_given_radius_through_two_points | Circles of given radius through two points |
Given two points on a plane and a radius, usually two circles of given radius can be drawn through the points.
Exceptions
r==0.0 should be treated as never describing circles (except in the case where the points are coincident).
If the points are coincident then an infinite number of circles with the point on thei... | #Vlang | Vlang | import math
const (
two = "two circles."
r0 = "R==0.0 does not describe circles."
co = "coincident points describe an infinite number of circles."
cor0 = "coincident points with r==0.0 describe a degenerate circle."
diam = "Points form a diameter and describe only a single circle."
far =... |
http://rosettacode.org/wiki/Check_that_file_exists | Check that file exists | Task
Verify that a file called input.txt and a directory called docs exist.
This should be done twice:
once for the current working directory, and
once for a file and a directory in the filesystem root.
Optional criteria (May 2015): verify it works with:
zero-length files
an ... | #Phix | Phix | without js -- (file i/o)
procedure check(string name)
bool bExists = file_exists(name),
bDir = get_file_type(name)=FILETYPE_DIRECTORY
string exists = iff(bExists?"exists":"does not exist"),
dfs = iff(bExists?iff(bDir?"directory ":"file "):"")
printf(1,"%s%s %s.\n",{dfs,name,exists})
end ... |
http://rosettacode.org/wiki/Check_that_file_exists | Check that file exists | Task
Verify that a file called input.txt and a directory called docs exist.
This should be done twice:
once for the current working directory, and
once for a file and a directory in the filesystem root.
Optional criteria (May 2015): verify it works with:
zero-length files
an ... | #Phixmonti | Phixmonti | "foo.bar" "w" fopen
"Hallo !" over fputs
fclose
"fou.bar" "r" fopen
dup 0 < if "Could not open 'foo.bar' for reading" print drop else fclose endif |
http://rosettacode.org/wiki/Character_codes | Character codes |
Task
Given a character value in your language, print its code (could be ASCII code, Unicode code, or whatever your language uses).
Example
The character 'a' (lowercase letter A) has a code of 97 in ASCII (as well as Unicode, as ASCII forms the beginning of Unicode).
Conversely, given a code, print out... | #Lua | Lua | print(string.byte("a")) -- prints "97"
print(string.char(97)) -- prints "a" |
http://rosettacode.org/wiki/Character_codes | Character codes |
Task
Given a character value in your language, print its code (could be ASCII code, Unicode code, or whatever your language uses).
Example
The character 'a' (lowercase letter A) has a code of 97 in ASCII (as well as Unicode, as ASCII forms the beginning of Unicode).
Conversely, given a code, print out... | #M2000_Interpreter | M2000 Interpreter |
\\ ANSI
Print Asc("a")
Print Chr$(Asc("a"))
\\ Utf16-Le
Print ChrCode("a")
Print ChrCode$(ChrCode("a"))
\\ (,) is an empty array.
Function Codes(a$) {
If Len(A$)=0 then =(,) : Exit
Buffer Mem as byte*Len(a$)
\\ Str$(string) return one byte character
Return Mem, 0:=Str$(a$)
... |
http://rosettacode.org/wiki/Collections | Collections | This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task.
Collections are abstractions to represent sets of values.
In statically-typed languages, the values are typically of a common data type.
Task
Create a collection, and add a fe... | #Seed7 | Seed7 | $ include "seed7_05.s7i";
enable_output(set of string);
const proc: main is func
local
var set of string: aSet is {"iron", "copper"};
begin
writeln(aSet);
incl(aSet, "silver");
writeln(aSet);
end func; |
http://rosettacode.org/wiki/Conditional_structures | Conditional structures | Control Structures
These are examples of control structures. You may also be interested in:
Conditional structures
Exceptions
Flow-control structures
Loops
Task
List the conditional structures offered by a programming language. See Wikipedia: conditionals for descriptions.
Common conditional structures include ... | #Zig | Zig | const std = @import("std");
const builtin = @import("builtin");
fn printOpenSource(comptime is_open_source: bool) !void {
if (is_open_source) {
try std.io.getStdOut().writer().writeAll("Open source.\n");
} else {
try std.io.getStdOut().writer().writeAll("No open source.\n");
}
}
fn printYe... |
http://rosettacode.org/wiki/Classes | Classes | In object-oriented programming class is a set (a transitive closure) of types bound by the relation of inheritance. It is said that all types derived from some base type T and the type T itself form a class T.
The first type T from the class T sometimes is called the root type of the class.
A class of types itself, a... | #X86-64_Assembly | X86-64 Assembly |
option casemap:none
ifndef __SOMECLASS_CLASS__
__SOMECLASS_CLASS__ equ 1
;; Once again, HeapAlloc/Free is REQUIRED by the class extention for windows.
;; Malloc/Free are used by Linux and OSX. So the function prototypes have to
;; be defined somewhere. If you have include files where they're defined, just... |
http://rosettacode.org/wiki/Circles_of_given_radius_through_two_points | Circles of given radius through two points |
Given two points on a plane and a radius, usually two circles of given radius can be drawn through the points.
Exceptions
r==0.0 should be treated as never describing circles (except in the case where the points are coincident).
If the points are coincident then an infinite number of circles with the point on thei... | #Wren | Wren | import "/math" for Math
var Two = "Two circles."
var R0 = "R == 0 does not describe circles."
var Co = "Coincident points describe an infinite number of circles."
var CoR0 = "Coincident points with r == 0 describe a degenerate circle."
var Diam = "Points form a diameter and describe only a single circle."
var Fa... |
http://rosettacode.org/wiki/Check_that_file_exists | Check that file exists | Task
Verify that a file called input.txt and a directory called docs exist.
This should be done twice:
once for the current working directory, and
once for a file and a directory in the filesystem root.
Optional criteria (May 2015): verify it works with:
zero-length files
an ... | #PHP | PHP | if (file_exists('input.txt')) echo 'input.txt is here right by my side';
if (file_exists('docs' )) echo 'docs is here with me';
if (file_exists('/input.txt')) echo 'input.txt is over there in the root dir';
if (file_exists('/docs' )) echo 'docs is over there in the root dir'; |
http://rosettacode.org/wiki/Check_that_file_exists | Check that file exists | Task
Verify that a file called input.txt and a directory called docs exist.
This should be done twice:
once for the current working directory, and
once for a file and a directory in the filesystem root.
Optional criteria (May 2015): verify it works with:
zero-length files
an ... | #PicoLisp | PicoLisp | (if (info "file.txt")
(prinl "Size: " (car @) " bytes, last modified " (stamp (cadr @) (cddr @)))
(prinl "File doesn't exist") )
# for directory existing
# Nehal-Singhal 2018-05-25
(if (info "./docs")
(print 'exists)
(print 'doesNotExist)))
# To verify if it's really a directory, (CAR of return value... |
http://rosettacode.org/wiki/Character_codes | Character codes |
Task
Given a character value in your language, print its code (could be ASCII code, Unicode code, or whatever your language uses).
Example
The character 'a' (lowercase letter A) has a code of 97 in ASCII (as well as Unicode, as ASCII forms the beginning of Unicode).
Conversely, given a code, print out... | #Maple | Maple | > use StringTools in Ord( "A" ); Char( 65 ) end;
65
"A"
|
http://rosettacode.org/wiki/Character_codes | Character codes |
Task
Given a character value in your language, print its code (could be ASCII code, Unicode code, or whatever your language uses).
Example
The character 'a' (lowercase letter A) has a code of 97 in ASCII (as well as Unicode, as ASCII forms the beginning of Unicode).
Conversely, given a code, print out... | #Mathematica_.2F_Wolfram_Language | Mathematica / Wolfram Language | ToCharacterCode["abcd"]
FromCharacterCode[{97}] |
http://rosettacode.org/wiki/Collections | Collections | This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task.
Collections are abstractions to represent sets of values.
In statically-typed languages, the values are typically of a common data type.
Task
Create a collection, and add a fe... | #Setl4 | Setl4 |
set = new('set 5 10 15 20 25 25')
add(set,30)
show(set)
show.eval('member(set,5)')
show.eval('member(set,6)')
show.eval("exists(set,'eq(this,10)')")
show.eval("forall(set,'eq(this,40)')")
|
http://rosettacode.org/wiki/Classes | Classes | In object-oriented programming class is a set (a transitive closure) of types bound by the relation of inheritance. It is said that all types derived from some base type T and the type T itself form a class T.
The first type T from the class T sometimes is called the root type of the class.
A class of types itself, a... | #XBS | XBS | class Person {
construct=func(self,Name,Age,Gender){
self:Name=Name;
self:Age=Age;
self:Gender=Gender;
}{Name="John",Age=20,Gender="Male"};
ToString=func(self){
send self.Name+" ("+self.Gender+"): Age "+self.Age;
}
}
set John = new Person with [];
log(John::ToString());
set Jane = new Person with ["Jane",... |
http://rosettacode.org/wiki/Classes | Classes | In object-oriented programming class is a set (a transitive closure) of types bound by the relation of inheritance. It is said that all types derived from some base type T and the type T itself form a class T.
The first type T from the class T sometimes is called the root type of the class.
A class of types itself, a... | #XLISP | XLISP | (DEFINE-CLASS PROGRAMMING-LANGUAGE
(INSTANCE-VARIABLES NAME YEAR))
(DEFINE-METHOD (PROGRAMMING-LANGUAGE 'INITIALIZE X)
(SETQ NAME X)
SELF)
(DEFINE-METHOD (PROGRAMMING-LANGUAGE 'WAS-CREATED-IN X)
(SETQ YEAR X))
(DEFINE-METHOD (PROGRAMMING-LANGUAGE 'DESCRIBE)
`(THE PROGRAMMING LANGUAGE ,NAME WAS... |
http://rosettacode.org/wiki/Circles_of_given_radius_through_two_points | Circles of given radius through two points |
Given two points on a plane and a radius, usually two circles of given radius can be drawn through the points.
Exceptions
r==0.0 should be treated as never describing circles (except in the case where the points are coincident).
If the points are coincident then an infinite number of circles with the point on thei... | #XPL0 | XPL0 | include c:\cxpl\codes;
proc Circles; real Data; \Show centers of circles, given points P & Q and radius
real Px, Py, Qx, Qy, R, X, Y, X1, Y1, Bx, By, PB, CB;
[Px:= Data(0); Py:= Data(1); Qx:= Data(2); Qy:= Data(3); R:= Data(4);
if R = 0.0 then [Text(0, "Radius = zero gives no circles^M^J"); return];
X:= (Qx-Px)/2.0; ... |
http://rosettacode.org/wiki/Circles_of_given_radius_through_two_points | Circles of given radius through two points |
Given two points on a plane and a radius, usually two circles of given radius can be drawn through the points.
Exceptions
r==0.0 should be treated as never describing circles (except in the case where the points are coincident).
If the points are coincident then an infinite number of circles with the point on thei... | #Yabasic | Yabasic |
sub twoCircles (x1, y1, x2, y2, radio)
if x1 = x2 and y1 = y2 then //Si los puntos coinciden
if radio = 0 then //a no ser que radio=0
print "Los puntos son los mismos\n"
return true
else
print "Hay cualquier numero de circulos a traves de un solo punto (", x1, ",", y1, ") de radio ", radio : print... |
http://rosettacode.org/wiki/Check_that_file_exists | Check that file exists | Task
Verify that a file called input.txt and a directory called docs exist.
This should be done twice:
once for the current working directory, and
once for a file and a directory in the filesystem root.
Optional criteria (May 2015): verify it works with:
zero-length files
an ... | #Pike | Pike | import Stdio;
int main(){
if(exist("/var")){
write("/var exists!\n");
}
if(exist("file-exists.pike")){
write("I exist!\n");
}
} |
http://rosettacode.org/wiki/Check_that_file_exists | Check that file exists | Task
Verify that a file called input.txt and a directory called docs exist.
This should be done twice:
once for the current working directory, and
once for a file and a directory in the filesystem root.
Optional criteria (May 2015): verify it works with:
zero-length files
an ... | #PL.2FI | PL/I | *Process source or(!);
/*********************************************************************
* 20.10.2013 Walter Pachl
* 'set dd:f=d:\_l\xxx.txt,recsize(300)'
* 'tex'
*********************************************************************/
tex: Proc Options(main);
Dcl fid Char(30) Var Init('D:\_l\tst.txt');
Dcl ... |
http://rosettacode.org/wiki/Character_codes | Character codes |
Task
Given a character value in your language, print its code (could be ASCII code, Unicode code, or whatever your language uses).
Example
The character 'a' (lowercase letter A) has a code of 97 in ASCII (as well as Unicode, as ASCII forms the beginning of Unicode).
Conversely, given a code, print out... | #MATLAB_.2F_Octave | MATLAB / Octave | character = char(asciiNumber) |
http://rosettacode.org/wiki/Character_codes | Character codes |
Task
Given a character value in your language, print its code (could be ASCII code, Unicode code, or whatever your language uses).
Example
The character 'a' (lowercase letter A) has a code of 97 in ASCII (as well as Unicode, as ASCII forms the beginning of Unicode).
Conversely, given a code, print out... | #Maxima | Maxima | ascii(65);
"A"
cint("A");
65 |
http://rosettacode.org/wiki/Collections | Collections | This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task.
Collections are abstractions to represent sets of values.
In statically-typed languages, the values are typically of a common data type.
Task
Create a collection, and add a fe... | #Sidef | Sidef | # creating an empty array and adding values
var a = [] #=> []
a[0] = 1 #=> [1]
a[3] = "abc" #=> [1, nil, nil, "abc"]
a << 3.14 #=> [1, nil, nil, "abc", 3.14] |
http://rosettacode.org/wiki/Classes | Classes | In object-oriented programming class is a set (a transitive closure) of types bound by the relation of inheritance. It is said that all types derived from some base type T and the type T itself form a class T.
The first type T from the class T sometimes is called the root type of the class.
A class of types itself, a... | #zkl | zkl | class C{ // define class named "C", no parents or attributes
println("starting construction"); // all code outside functions is wrapped into the constructor
var v; // instance data for this class
fcn init(x) // initializer for this class, calls constructor
{ v = x }
println("ending construction of ... |
http://rosettacode.org/wiki/Classes | Classes | In object-oriented programming class is a set (a transitive closure) of types bound by the relation of inheritance. It is said that all types derived from some base type T and the type T itself form a class T.
The first type T from the class T sometimes is called the root type of the class.
A class of types itself, a... | #zonnon | zonnon |
module Graphics;
type
{ref,public} (* class *)
Point = object(ord,abs: integer)
var
(* instance variables *)
{public,immutable} x,y: integer;
(* method *)
procedure {public} Ord():integer;
begin
return y
end Ord;
(* method *)
procedure {public} Abs():integer;
begin
return x
end Abs;
(* const... |
http://rosettacode.org/wiki/Circles_of_given_radius_through_two_points | Circles of given radius through two points |
Given two points on a plane and a radius, usually two circles of given radius can be drawn through the points.
Exceptions
r==0.0 should be treated as never describing circles (except in the case where the points are coincident).
If the points are coincident then an infinite number of circles with the point on thei... | #zkl | zkl | fcn findCircles(a,b, c,d, r){ //-->T(T(x,y,r) [,T(x,y,r)]))
delta:=(a-c).hypot(b-d);
switch(delta){ // could just catch MathError
case(0.0){"singularity"} // should use epsilon test
case(r*2){T(T((a+c)/2,(b+d)/2,r))}
else{
if(delta > 2*r) "Point delta > diameter";
else{
md:=(r.pow(2) -... |
http://rosettacode.org/wiki/Check_that_file_exists | Check that file exists | Task
Verify that a file called input.txt and a directory called docs exist.
This should be done twice:
once for the current working directory, and
once for a file and a directory in the filesystem root.
Optional criteria (May 2015): verify it works with:
zero-length files
an ... | #PL.2FM | PL/M | 100H:
DECLARE FCB$SIZE LITERALLY '36';
BDOS: PROCEDURE( FN, ARG )BYTE; /* CP/M BDOS SYSTEM CALL, RETURNS A VALUE */
DECLARE FN BYTE, ARG ADDRESS;
GOTO 5;
END BDOS;
BDOS$P: PROCEDURE( FN, ARG ); /* CP/M BDOS SYSTEM CALL, NO RETURN VALUE */
DECLARE FN BYTE, ARG ADDRESS;
GOTO... |
http://rosettacode.org/wiki/Check_that_file_exists | Check that file exists | Task
Verify that a file called input.txt and a directory called docs exist.
This should be done twice:
once for the current working directory, and
once for a file and a directory in the filesystem root.
Optional criteria (May 2015): verify it works with:
zero-length files
an ... | #Pop11 | Pop11 | sys_file_exists('input.txt') =>
sys_file_exists('/input.txt') =>
sys_file_exists('docs') =>
sys_file_exists('/docs') => |
http://rosettacode.org/wiki/Character_codes | Character codes |
Task
Given a character value in your language, print its code (could be ASCII code, Unicode code, or whatever your language uses).
Example
The character 'a' (lowercase letter A) has a code of 97 in ASCII (as well as Unicode, as ASCII forms the beginning of Unicode).
Conversely, given a code, print out... | #Metafont | Metafont | message "enter a letter: ";
string a;
a := readstring;
message decimal (ASCII a); % writes the decimal number of the first character
% of the string a
message "enter a number: ";
num := scantokens readstring;
message char num; % num can be anything between 0 and 255; what will be seen
... |
http://rosettacode.org/wiki/Character_codes | Character codes |
Task
Given a character value in your language, print its code (could be ASCII code, Unicode code, or whatever your language uses).
Example
The character 'a' (lowercase letter A) has a code of 97 in ASCII (as well as Unicode, as ASCII forms the beginning of Unicode).
Conversely, given a code, print out... | #Microsoft_Small_Basic | Microsoft Small Basic | TextWindow.WriteLine("The ascii code for 'A' is: " + Text.GetCharacterCode("A") + ".")
TextWindow.WriteLine("The character for '65' is: " + Text.GetCharacter(65) + ".") |
http://rosettacode.org/wiki/Collections | Collections | This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task.
Collections are abstractions to represent sets of values.
In statically-typed languages, the values are typically of a common data type.
Task
Create a collection, and add a fe... | #Slate | Slate | {1. 2. 3. 4. 5} collect: [|:x| x + 1]. "--> {2. 3. 4. 5. 6}"
{1. 2. 3. 4. 5} select: #isOdd `er. "--> {1. 3. 5}"
({3. 2. 7} collect: #+ `er <- 3) sort. "--> {"SortedArray traitsWindow" 5. 6. 10}"
ExtensibleArray new `>> [addLast: 3. addFirst: 4. ]. "--> {"ExtensibleArray traitsWindow" 4. 3}" |
http://rosettacode.org/wiki/Circles_of_given_radius_through_two_points | Circles of given radius through two points |
Given two points on a plane and a radius, usually two circles of given radius can be drawn through the points.
Exceptions
r==0.0 should be treated as never describing circles (except in the case where the points are coincident).
If the points are coincident then an infinite number of circles with the point on thei... | #ZX_Spectrum_Basic | ZX Spectrum Basic | 10 FOR i=1 TO 5
20 READ x1,y1,x2,y2,r
30 PRINT i;") ";x1;" ";y1;" ";x2;" ";y2;" ";r
40 GO SUB 1000
50 NEXT i
60 STOP
70 DATA 0.1234,0.9876,0.8765,0.2345,2.0
80 DATA 0.0000,2.0000,0.0000,0.0000,1.0
90 DATA 0.1234,0.9876,0.1234,0.9876,2.0
100 DATA 0.1234,0.9876,0.8765,0.2345,0.5
110 DATA 0.1234,0.9876,0.1234,0.9876,0.0
... |
http://rosettacode.org/wiki/Check_that_file_exists | Check that file exists | Task
Verify that a file called input.txt and a directory called docs exist.
This should be done twice:
once for the current working directory, and
once for a file and a directory in the filesystem root.
Optional criteria (May 2015): verify it works with:
zero-length files
an ... | #PowerShell | PowerShell | if (Test-Path -Path .\input.txt) {
write-host "File input exist"
}
else {
write-host "File input doesn't exist"
} |
http://rosettacode.org/wiki/Check_that_file_exists | Check that file exists | Task
Verify that a file called input.txt and a directory called docs exist.
This should be done twice:
once for the current working directory, and
once for a file and a directory in the filesystem root.
Optional criteria (May 2015): verify it works with:
zero-length files
an ... | #Prolog | Prolog |
exists_file('input.txt'),
exists_directory('docs').
exits_file('/input.txt'),
exists_directory('/docs').
|
http://rosettacode.org/wiki/Character_codes | Character codes |
Task
Given a character value in your language, print its code (could be ASCII code, Unicode code, or whatever your language uses).
Example
The character 'a' (lowercase letter A) has a code of 97 in ASCII (as well as Unicode, as ASCII forms the beginning of Unicode).
Conversely, given a code, print out... | #Modula-2 | Modula-2 | MODULE asc;
IMPORT InOut;
VAR letter : CHAR;
ascii : CARDINAL;
BEGIN
letter := 'a';
InOut.Write (letter);
ascii := ORD (letter);
InOut.Write (11C); (* ASCII TAB *)
InOut.WriteCard (ascii, 8);
ascii := ascii - ORD ('0');
InOut.Write (11C); (* ... |
http://rosettacode.org/wiki/Character_codes | Character codes |
Task
Given a character value in your language, print its code (could be ASCII code, Unicode code, or whatever your language uses).
Example
The character 'a' (lowercase letter A) has a code of 97 in ASCII (as well as Unicode, as ASCII forms the beginning of Unicode).
Conversely, given a code, print out... | #Modula-3 | Modula-3 | ORD('a') (* Returns 97 *)
VAL(97, CHAR); (* Returns 'a' *) |
http://rosettacode.org/wiki/Collections | Collections | This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task.
Collections are abstractions to represent sets of values.
In statically-typed languages, the values are typically of a common data type.
Task
Create a collection, and add a fe... | #Smalltalk | Smalltalk | |anOrdered aBag aSet aSorted aSorted2 aDictionary|
anOrdered := OrderedCollection new.
anOrdered add: 1; add: 5; add: 3.
anOrdered printNl.
aBag := Bag new.
aBag add: 5; add: 5; add: 5; add: 6.
aBag printNl.
aSet := Set new.
aSet add: 10; add: 5; add: 5; add: 6; add: 10.
aSet printNl.
aSorted := SortedCollectio... |
http://rosettacode.org/wiki/Check_that_file_exists | Check that file exists | Task
Verify that a file called input.txt and a directory called docs exist.
This should be done twice:
once for the current working directory, and
once for a file and a directory in the filesystem root.
Optional criteria (May 2015): verify it works with:
zero-length files
an ... | #PureBasic | PureBasic | result = ReadFile(#PB_Any, "input.txt")
If result>0 : Debug "this local file exists"
Else : Debug "result=" +Str(result) +" so this local file is missing"
EndIf
result = ReadFile(#PB_Any, "/input.txt")
If result>0 : Debug "this root file exists"
Else : Debug "result=" +Str(result) +" so this root file is missing... |
http://rosettacode.org/wiki/Check_that_file_exists | Check that file exists | Task
Verify that a file called input.txt and a directory called docs exist.
This should be done twice:
once for the current working directory, and
once for a file and a directory in the filesystem root.
Optional criteria (May 2015): verify it works with:
zero-length files
an ... | #Python | Python | import os
os.path.isfile("input.txt")
os.path.isfile("/input.txt")
os.path.isdir("docs")
os.path.isdir("/docs") |
http://rosettacode.org/wiki/Character_codes | Character codes |
Task
Given a character value in your language, print its code (could be ASCII code, Unicode code, or whatever your language uses).
Example
The character 'a' (lowercase letter A) has a code of 97 in ASCII (as well as Unicode, as ASCII forms the beginning of Unicode).
Conversely, given a code, print out... | #MUMPS | MUMPS | WRITE $ASCII("M")
WRITE $CHAR(77) |
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.