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/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... | #BaCon | BaCon |
PRAGMA COMPILER g++
PRAGMA OPTIONS -Wno-write-strings -Wno-pointer-arith -fpermissive
OPTION PARSE FALSE
'---The class does the declaring for you
CLASS Books
public:
const char* title;
const char* author;
const char* subject;
int book_id;
END CLASS
'---pointer to an object declaration (we us... |
http://rosettacode.org/wiki/Cistercian_numerals | Cistercian numerals | Cistercian numerals were used across Europe by Cistercian monks during the Late Medieval Period as an alternative to Roman numerals. They were used to represent base 10 integers from 0 to 9999.
How they work
All Cistercian numerals begin with a vertical line segment, which by itself represents the number 0. Then, glyp... | #D | D | import std.stdio;
class Cistercian {
private immutable SIZE = 15;
private char[SIZE][SIZE] canvas;
public this(int n) {
initN();
draw(n);
}
private void initN() {
foreach (ref row; canvas) {
row[] = ' ';
row[5] = 'x';
}
}
privat... |
http://rosettacode.org/wiki/Colour_bars/Display | Colour bars/Display | Task
Display a series of vertical color bars across the width of the display.
The color bars should either use:
the system palette, or
the sequence of colors:
black
red
green
blue
magenta
cyan
yellow
white
| #R | R |
pal <- c("black", "red", "green", "blue", "magenta", "cyan", "yellow", "white")
par(mar = rep(0, 4))
image(matrix(1:8), col = pal, axes = FALSE)
|
http://rosettacode.org/wiki/Colour_bars/Display | Colour bars/Display | Task
Display a series of vertical color bars across the width of the display.
The color bars should either use:
the system palette, or
the sequence of colors:
black
red
green
blue
magenta
cyan
yellow
white
| #Racket | Racket |
#lang racket/gui
(define-values [W H] (get-display-size #t))
(define colors
'("Black" "Red" "Green" "Blue" "Magenta" "Cyan" "Yellow" "White"))
(define (paint-pinstripe canvas dc)
(send dc set-pen "black" 0 'transparent)
(for ([x (in-range 0 W (/ W (length colors)))] [c colors])
(send* dc (set-brush c ... |
http://rosettacode.org/wiki/Colour_bars/Display | Colour bars/Display | Task
Display a series of vertical color bars across the width of the display.
The color bars should either use:
the system palette, or
the sequence of colors:
black
red
green
blue
magenta
cyan
yellow
white
| #Raku | Raku | my ($x,$y) = 1280, 720;
my @colors = map -> $r, $g, $b { Buf.new: |(($r, $g, $b) xx $x div 8) },
0, 0, 0,
255, 0, 0,
0, 255, 0,
0, 0, 255,
255, 0, 255,
0, 255, 255,
255, 255, 0,
255, 255, 255;
my $img = open "colorbars.ppm", :w orelse die "Can't create colorba... |
http://rosettacode.org/wiki/Closest-pair_problem | Closest-pair problem |
This page uses content from Wikipedia. The original article was at Closest pair of points problem. 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
Provide a function to find the closest two p... | #BBC_BASIC | BBC BASIC | DIM x(9), y(9)
FOR I% = 0 TO 9
READ x(I%), y(I%)
NEXT
min = 1E30
FOR I% = 0 TO 8
FOR J% = I%+1 TO 9
dsq = (x(I%) - x(J%))^2 + (y(I%) - y(J%))^2
IF dsq < min min = dsq : mini% = I% : minj% = J%
NEXT
NEXT I%
PRINT "Closest pair is "... |
http://rosettacode.org/wiki/Closures/Value_capture | Closures/Value capture | Task
Create a list of ten functions, in the simplest manner possible (anonymous functions are encouraged), such that the function at index i (you may choose to start i from either 0 or 1), when run, should return the square of the index, that is, i 2.
Display the result of runnin... | #Fantom | Fantom |
class Closures
{
Void main ()
{
// define a list of functions, which take no arguments and return an Int
|->Int|[] functions := [,]
// create and store a function which returns i*i for i in 0 to 10
(0..10).each |Int i|
{
functions.add (|->Int| { i*i })
}
// show result of cal... |
http://rosettacode.org/wiki/Closures/Value_capture | Closures/Value capture | Task
Create a list of ten functions, in the simplest manner possible (anonymous functions are encouraged), such that the function at index i (you may choose to start i from either 0 or 1), when run, should return the square of the index, that is, i 2.
Display the result of runnin... | #Forth | Forth | : xt-array here { a }
10 cells allot 10 0 do
:noname i ]] literal dup * ; [[ a i cells + !
loop a ;
xt-array 5 cells + @ execute . |
http://rosettacode.org/wiki/Circular_primes | Circular primes | Definitions
A circular prime is a prime number with the property that the number generated at each intermediate step when cyclically permuting its (base 10) digits will also be prime.
For example:
1193 is a circular prime, since 1931, 9311 and 3119 are all also prime.
Note that a number which is a cyclic permutation ... | #Haskell | Haskell | import Math.NumberTheory.Primes (Prime, unPrime, nextPrime)
import Math.NumberTheory.Primes.Testing (isPrime, millerRabinV)
import Text.Printf (printf)
rotated :: [Integer] -> [Integer]
rotated xs
| any (< head xs) xs = []
| otherwise = map asNum $ take (pred $ length xs) $ rotate xs
where
rotate [] ... |
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... | #Axe | Axe | 1→{L₁}
2→{L₁+1}
3→{L₁+2}
4→{L₁+3}
Disp {L₁}►Dec,i
Disp {L₁+1}►Dec,i
Disp {L₁+2}►Dec,i
Disp {L₁+3}►Dec,i |
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
... | #Glee | Glee | 5!3 >>> ,,\
$$(5!3) give all combinations of 3 out of 5
$$(>>>) sorted up,
$$(,,\) printed with crlf delimiters. |
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 ... | #PARI.2FGP | PARI/GP | if(condition, do_if_true, do_if_false) |
http://rosettacode.org/wiki/Comments | Comments | Task
Show all ways to include text in a language source file
that's completely ignored by the compiler or interpreter.
Related tasks
Documentation
Here_document
See also
Wikipedia
xkcd (Humor: hand gesture denoting // for "commenting out" people.)
| #TorqueScript | TorqueScript | //This is a one line comment. There are no other commenting options in TorqueScript. |
http://rosettacode.org/wiki/Comments | Comments | Task
Show all ways to include text in a language source file
that's completely ignored by the compiler or interpreter.
Related tasks
Documentation
Here_document
See also
Wikipedia
xkcd (Humor: hand gesture denoting // for "commenting out" people.)
| #TPP | TPP | --## comments are prefixed with a long handed double paintbrush |
http://rosettacode.org/wiki/Comments | Comments | Task
Show all ways to include text in a language source file
that's completely ignored by the compiler or interpreter.
Related tasks
Documentation
Here_document
See also
Wikipedia
xkcd (Humor: hand gesture denoting // for "commenting out" people.)
| #Transd | Transd | // This is a line comment.
/* This is a single line block comment.*/
/* This is
a multi-line
block comment.*/
|
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... | #BASIC | BASIC | DECLARE SUB MyClassDelete (pthis AS MyClass)
DECLARE SUB MyClassSomeMethod (pthis AS MyClass)
DECLARE SUB MyClassInit (pthis AS MyClass)
TYPE MyClass
Variable AS INTEGER
END TYPE
DIM obj AS MyClass
MyClassInit obj
MyClassSomeMethod obj
SUB MyClassInit (pthis AS MyClass)
pthis.Variable = ... |
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... | #BBC_BASIC | BBC BASIC | INSTALL @lib$+"CLASSLIB"
REM Declare the class:
DIM MyClass{variable, @constructor, _method}
DEF MyClass.@constructor MyClass.variable = PI : ENDPROC
DEF MyClass._method = MyClass.variable ^ 2
REM Register the class:
PROC_class(MyClass{})
REM Instantiate the class:
... |
http://rosettacode.org/wiki/Cistercian_numerals | Cistercian numerals | Cistercian numerals were used across Europe by Cistercian monks during the Late Medieval Period as an alternative to Roman numerals. They were used to represent base 10 integers from 0 to 9999.
How they work
All Cistercian numerals begin with a vertical line segment, which by itself represents the number 0. Then, glyp... | #F.23 | F# |
// Cistercian numerals. Nigel Galloway: February 2nd., 2021
let N=[|[[|' ';' ';' '|];[|' ';' ';' '|];[|' ';' ';' '|]];
[[|'#';'#';'#'|];[|' ';' ';' '|];[|' ';' ';' '|]];
[[|' ';' ';' '|];[|'#';'#';'#'|];[|' ';' ';' '|]];
[[|'#';' ';' '|];[|' ';'#';' '|];[|' ';' ';'#'|]];
[[|' ';' ';'#'... |
http://rosettacode.org/wiki/Colour_bars/Display | Colour bars/Display | Task
Display a series of vertical color bars across the width of the display.
The color bars should either use:
the system palette, or
the sequence of colors:
black
red
green
blue
magenta
cyan
yellow
white
| #REXX | REXX | /*REXX program displays eight colored vertical bars on a full screen. */
parse value scrsize() with sd sw . /*the screen depth and width. */
barWidth=sw%8 /*calculate the bar width. */
_.=copies('db'x, barWidth) ... |
http://rosettacode.org/wiki/Colour_bars/Display | Colour bars/Display | Task
Display a series of vertical color bars across the width of the display.
The color bars should either use:
the system palette, or
the sequence of colors:
black
red
green
blue
magenta
cyan
yellow
white
| #Ring | Ring |
load "guilib.ring"
new qapp
{
win1 = new qwidget() {
setwindowtitle("drawing using qpainter")
setwinicon(self,"C:\Ring\bin\image\browser.png")
setgeometry(100,100,500,600)
label1 = new qlabel(win1) {
setgeometry(10,... |
http://rosettacode.org/wiki/Closest-pair_problem | Closest-pair problem |
This page uses content from Wikipedia. The original article was at Closest pair of points problem. 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
Provide a function to find the closest two p... | #C | C | class Segment
{
public Segment(PointF p1, PointF p2)
{
P1 = p1;
P2 = p2;
}
public readonly PointF P1;
public readonly PointF P2;
public float Length()
{
return (float)Math.Sqrt(LengthSquared());
}
public float LengthSquared()
{
return (P1.X -... |
http://rosettacode.org/wiki/Closures/Value_capture | Closures/Value capture | Task
Create a list of ten functions, in the simplest manner possible (anonymous functions are encouraged), such that the function at index i (you may choose to start i from either 0 or 1), when run, should return the square of the index, that is, i 2.
Display the result of runnin... | #FreeBASIC | FreeBASIC | ' FB 1.05.0 Win64
Type Closure
Private:
index As Integer
Public:
Declare Constructor(index As Integer = 0)
Declare Function Square As Integer
End Type
Constructor Closure(index As Integer = 0)
This.index = index
End Constructor
Function Closure.Square As Integer
Return index * index
End Fun... |
http://rosettacode.org/wiki/Circular_primes | Circular primes | Definitions
A circular prime is a prime number with the property that the number generated at each intermediate step when cyclically permuting its (base 10) digits will also be prime.
For example:
1193 is a circular prime, since 1931, 9311 and 3119 are all also prime.
Note that a number which is a cyclic permutation ... | #J | J |
R=: [: ". 'x' ,~ #&'1'
assert 11111111111111111111111111111111x -: R 32
Filter=: (#~`)(`:6)
rotations=: (|."0 1~ i.@#)&.(10&#.inv)
assert 123 231 312 -: rotations 123
primes_less_than=: i.&.:(p:inv)
assert 2 3 5 7 11 -: primes_less_than 12
NB. circular y --> y is the order of magnitude.
circular=: monad d... |
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... | #BBC_BASIC | BBC BASIC | DIM text$(1)
text$(0) = "Hello "
text$(1) = "world!" |
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
... | #Go | Go | package main
import (
"fmt"
)
func main() {
comb(5, 3, func(c []int) {
fmt.Println(c)
})
}
func comb(n, m int, emit func([]int)) {
s := make([]int, m)
last := m - 1
var rc func(int, int)
rc = func(i, next int) {
for j := next; j < n; j++ {
s[i] = j
... |
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 ... | #Pascal | Pascal | IF condition1 THEN
procedure1
ELSE
procedure3;
IF condition1 THEN
BEGIN
procedure1;
procedure2
END
ELSE
procedure3;
IF condition1 THEN
BEGIN
procedure1;
procedure2
END
ELSE
BEGIN
procedure3;
procedure4
END; |
http://rosettacode.org/wiki/Comments | Comments | Task
Show all ways to include text in a language source file
that's completely ignored by the compiler or interpreter.
Related tasks
Documentation
Here_document
See also
Wikipedia
xkcd (Humor: hand gesture denoting // for "commenting out" people.)
| #TUSCRIPT | TUSCRIPT |
$$ MODE TUSCRIPT
- This is a comment
|
http://rosettacode.org/wiki/Comments | Comments | Task
Show all ways to include text in a language source file
that's completely ignored by the compiler or interpreter.
Related tasks
Documentation
Here_document
See also
Wikipedia
xkcd (Humor: hand gesture denoting // for "commenting out" people.)
| #TXR | TXR | @# old-style comment to end of line
@; new-style comment to end of line
@(bind a ; comment within expression
"foo") |
http://rosettacode.org/wiki/Comments | Comments | Task
Show all ways to include text in a language source file
that's completely ignored by the compiler or interpreter.
Related tasks
Documentation
Here_document
See also
Wikipedia
xkcd (Humor: hand gesture denoting // for "commenting out" people.)
| #UNIX_Shell | UNIX Shell | #!/bin/sh
# A leading hash symbol begins a comment.
echo "Hello" # Comments can appear after a statement.
# The hash symbol must be at the beginning of a word.
echo This_Is#Not_A_Comment
#Comment |
http://rosettacode.org/wiki/Church_numerals | Church numerals | Task
In the Church encoding of natural numbers, the number N is encoded by a function that applies its first argument N times to its second argument.
Church zero always returns the identity function, regardless of its first argument. In other words, the first argument is not applied to the second argument at all.
C... | #AppleScript | AppleScript | --------------------- CHURCH NUMERALS --------------------
-- churchZero :: (a -> a) -> a -> a
on churchZero(f, x)
x
end churchZero
-- churchSucc :: ((a -> a) -> a -> a) -> (a -> a) -> a -> a
on churchSucc(n)
script
on |λ|(f)
script
property mf : mReturn(f)
... |
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... | #BQN | BQN | ExClass ← {
𝕊 value: # Constructor portion
priv ← value
priv2 ⇐ 0
ChangePriv ⇐ { priv ↩ 𝕩 }
DispPriv ⇐ {𝕊: •Show priv‿priv2 }
}
obj ← ExClass 5
obj.DispPriv@
obj.ChangePriv 6
obj.DispPriv@ |
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... | #blz | blz |
# Constructors can take parameters (that automatically become properties)
constructor Ball(color, radius)
# Objects can also have functions (closures)
:volume
return 4/3 * {pi} * (radius ** 3)
end
:show
return "a " + color + " ball with radius " + radius
end
end
red_ball = Ball("red", 2)
print(red_ball... |
http://rosettacode.org/wiki/Cistercian_numerals | Cistercian numerals | Cistercian numerals were used across Europe by Cistercian monks during the Late Medieval Period as an alternative to Roman numerals. They were used to represent base 10 integers from 0 to 9999.
How they work
All Cistercian numerals begin with a vertical line segment, which by itself represents the number 0. Then, glyp... | #Factor | Factor | USING: combinators continuations formatting grouping io kernel
literals math.order math.text.utils multiline sequences
splitting ;
CONSTANT: numerals $[
HEREDOC: END
+ +-+ + + + + +-+ + + +-+ + + +-+
| | | |\ |/ |/ | | | | | | | |
| | +-+ | + + + | + | + +-+ +-+... |
http://rosettacode.org/wiki/Colour_bars/Display | Colour bars/Display | Task
Display a series of vertical color bars across the width of the display.
The color bars should either use:
the system palette, or
the sequence of colors:
black
red
green
blue
magenta
cyan
yellow
white
| #Ruby | Ruby |
# Array of web colors black, red, green, blue, magenta, cyan, yellow, white
PALETTE = %w[#000000 #ff0000 #00ff00 #0000ff #ff00ff #00ffff #ffffff].freeze
def settings
full_screen
end
def setup
PALETTE.each_with_index do |col, idx|
fill color(col)
rect(idx * width / 8, 0, width / 8, height)
end
end
|
http://rosettacode.org/wiki/Colour_bars/Display | Colour bars/Display | Task
Display a series of vertical color bars across the width of the display.
The color bars should either use:
the system palette, or
the sequence of colors:
black
red
green
blue
magenta
cyan
yellow
white
| #Rust | Rust | use pixels::{Pixels, SurfaceTexture}; // 0.2.0
use winit::event::*; // 0.24.0
use winit::event_loop::{ControlFlow, EventLoop};
use winit::window::{Fullscreen, WindowBuilder};
fn main() {
let event_loop = EventLoop::new();
let window = WindowBuilder::new()
.with_title("Colour Bars")
.with_decor... |
http://rosettacode.org/wiki/Closest-pair_problem | Closest-pair problem |
This page uses content from Wikipedia. The original article was at Closest pair of points problem. 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
Provide a function to find the closest two p... | #C.23 | C# | class Segment
{
public Segment(PointF p1, PointF p2)
{
P1 = p1;
P2 = p2;
}
public readonly PointF P1;
public readonly PointF P2;
public float Length()
{
return (float)Math.Sqrt(LengthSquared());
}
public float LengthSquared()
{
return (P1.X -... |
http://rosettacode.org/wiki/Closures/Value_capture | Closures/Value capture | Task
Create a list of ten functions, in the simplest manner possible (anonymous functions are encouraged), such that the function at index i (you may choose to start i from either 0 or 1), when run, should return the square of the index, that is, i 2.
Display the result of runnin... | #Go | Go | package main
import "fmt"
func main() {
fs := make([]func() int, 10)
for i := range fs {
i := i
fs[i] = func() int {
return i * i
}
}
fmt.Println("func #0:", fs[0]())
fmt.Println("func #3:", fs[3]())
} |
http://rosettacode.org/wiki/Circular_primes | Circular primes | Definitions
A circular prime is a prime number with the property that the number generated at each intermediate step when cyclically permuting its (base 10) digits will also be prime.
For example:
1193 is a circular prime, since 1931, 9311 and 3119 are all also prime.
Note that a number which is a cyclic permutation ... | #Java | Java | import java.math.BigInteger;
import java.util.Arrays;
public class CircularPrimes {
public static void main(String[] args) {
System.out.println("First 19 circular primes:");
int p = 2;
for (int count = 0; count < 19; ++p) {
if (isCircularPrime(p)) {
if (count > ... |
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... | #bc | bc | #define cSize( a ) ( sizeof(a)/sizeof(a[0]) ) /* a.size() */
int ar[10]; /* Collection<Integer> ar = new ArrayList<Integer>(10); */
ar[0] = 1; /* ar.set(0, 1); */
ar[1] = 2;
int* p; /* Iterator<Integer> p; Integer pValue; */
for (p=ar; /* for( p = ar.iter... |
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
... | #Groovy | Groovy | def comb
comb = { m, list ->
def n = list.size()
m == 0 ?
[[]] :
(0..(n-m)).inject([]) { newlist, k ->
def sublist = (k+1 == n) ? [] : list[(k+1)..<n]
newlist += comb(m-1, sublist).collect { [list[k]] + it }
}
} |
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 ... | #Perl | Perl | if ($expression) {
do_something;
} |
http://rosettacode.org/wiki/Comments | Comments | Task
Show all ways to include text in a language source file
that's completely ignored by the compiler or interpreter.
Related tasks
Documentation
Here_document
See also
Wikipedia
xkcd (Humor: hand gesture denoting // for "commenting out" people.)
| #Unlambda | Unlambda | # this is a comment.
|
http://rosettacode.org/wiki/Comments | Comments | Task
Show all ways to include text in a language source file
that's completely ignored by the compiler or interpreter.
Related tasks
Documentation
Here_document
See also
Wikipedia
xkcd (Humor: hand gesture denoting // for "commenting out" people.)
| #Ursa | Ursa | # this is a comment
# this is another comment
|
http://rosettacode.org/wiki/Church_numerals | Church numerals | Task
In the Church encoding of natural numbers, the number N is encoded by a function that applies its first argument N times to its second argument.
Church zero always returns the identity function, regardless of its first argument. In other words, the first argument is not applied to the second argument at all.
C... | #C.23 | C# | using System;
public delegate Church Church(Church f);
public static class ChurchNumeral
{
public static readonly Church ChurchZero = _ => x => x;
public static readonly Church ChurchOne = f => f;
public static Church Successor(this Church n) => f => x => f(n(f)(x));
public static Church Add(this ... |
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... | #Bracmat | Bracmat | ( ( resolution
= (x=)
(y=)
(new=.!arg:(?(its.x),?(its.y)))
)
& new$(resolution,640,480):?VGA
& new$(resolution,1920,1080):?1080p
& out$("VGA: horizontal " !(VGA..x) " vertical " !(VGA..y))); |
http://rosettacode.org/wiki/Cistercian_numerals | Cistercian numerals | Cistercian numerals were used across Europe by Cistercian monks during the Late Medieval Period as an alternative to Roman numerals. They were used to represent base 10 integers from 0 to 9999.
How they work
All Cistercian numerals begin with a vertical line segment, which by itself represents the number 0. Then, glyp... | #F.C5.8Drmul.C3.A6 | Fōrmulæ | package main
import "fmt"
var n = make([][]string, 15)
func initN() {
for i := 0; i < 15; i++ {
n[i] = make([]string, 11)
for j := 0; j < 11; j++ {
n[i][j] = " "
}
n[i][5] = "x"
}
}
func horiz(c1, c2, r int) {
for c := c1; c <= c2; c++ {
n[r][c] = ... |
http://rosettacode.org/wiki/Colour_bars/Display | Colour bars/Display | Task
Display a series of vertical color bars across the width of the display.
The color bars should either use:
the system palette, or
the sequence of colors:
black
red
green
blue
magenta
cyan
yellow
white
| #Scala | Scala | import java.awt.Color
import scala.swing._
class ColorBars extends Component {
override def paintComponent(g:Graphics2D)={
val colors=List(Color.BLACK, Color.RED, Color.GREEN, Color.BLUE, Color.MAGENTA, Color.CYAN, Color.YELLOW, Color.WHITE)
val colCount=colors.size
val deltaX=size.width.toDouble/colCou... |
http://rosettacode.org/wiki/Colour_bars/Display | Colour bars/Display | Task
Display a series of vertical color bars across the width of the display.
The color bars should either use:
the system palette, or
the sequence of colors:
black
red
green
blue
magenta
cyan
yellow
white
| #Sidef | Sidef | require('GD');
var colors = Hash.new(
white => [255, 255, 255],
red => [255, 0, 0],
green => [0, 255, 0],
blue => [0, 0, 255],
magenta => [255, 0, 255],
yellow => [255, 255, 0],
cyan => [0, 255... |
http://rosettacode.org/wiki/Closest-pair_problem | Closest-pair problem |
This page uses content from Wikipedia. The original article was at Closest pair of points problem. 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
Provide a function to find the closest two p... | #C.2B.2B | C++ | /*
Author: Kevin Bacon
Date: 04/03/2014
Task: Closest-pair problem
*/
#include <iostream>
#include <vector>
#include <utility>
#include <cmath>
#include <random>
#include <chrono>
#include <algorithm>
#include <iterator>
typedef std::pair<double, double> point_t;
typedef std::pair<point_t, point_t> points_t;
d... |
http://rosettacode.org/wiki/Closures/Value_capture | Closures/Value capture | Task
Create a list of ten functions, in the simplest manner possible (anonymous functions are encouraged), such that the function at index i (you may choose to start i from either 0 or 1), when run, should return the square of the index, that is, i 2.
Display the result of runnin... | #Groovy | Groovy | def closures = (0..9).collect{ i -> { -> i*i } } |
http://rosettacode.org/wiki/Closures/Value_capture | Closures/Value capture | Task
Create a list of ten functions, in the simplest manner possible (anonymous functions are encouraged), such that the function at index i (you may choose to start i from either 0 or 1), when run, should return the square of the index, that is, i 2.
Display the result of runnin... | #Haskell | Haskell | fs = map (\i _ -> i * i) [1 .. 10] |
http://rosettacode.org/wiki/Circular_primes | Circular primes | Definitions
A circular prime is a prime number with the property that the number generated at each intermediate step when cyclically permuting its (base 10) digits will also be prime.
For example:
1193 is a circular prime, since 1931, 9311 and 3119 are all also prime.
Note that a number which is a cyclic permutation ... | #jq | jq |
def is_circular_prime:
def circle: range(0;length) as $i | .[$i:] + .[:$i];
tostring as $s
| [$s|circle|tonumber] as $c
| . == ($c|min) and all($c|unique[]; is_prime);
def circular_primes:
2, (range(3; infinite; 2) | select(is_circular_prime));
# Probably only useful with unbounded-precision in... |
http://rosettacode.org/wiki/Circular_primes | Circular primes | Definitions
A circular prime is a prime number with the property that the number generated at each intermediate step when cyclically permuting its (base 10) digits will also be prime.
For example:
1193 is a circular prime, since 1931, 9311 and 3119 are all also prime.
Note that a number which is a cyclic permutation ... | #Julia | Julia | using Lazy, Primes
function iscircularprime(n)
!isprime(n) && return false
dig = digits(n)
return all(i -> (m = evalpoly(10, circshift(dig, i))) >= n && isprime(m), 1:length(dig)-1)
end
filtcircular(n, rang) = Int.(collect(take(n, filter(iscircularprime, rang))))
isprimerepunit(n) = isprime(evalpoly(Big... |
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... | #C | C | #define cSize( a ) ( sizeof(a)/sizeof(a[0]) ) /* a.size() */
int ar[10]; /* Collection<Integer> ar = new ArrayList<Integer>(10); */
ar[0] = 1; /* ar.set(0, 1); */
ar[1] = 2;
int* p; /* Iterator<Integer> p; Integer pValue; */
for (p=ar; /* for( p = ar.iter... |
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
... | #Haskell | Haskell | comb :: Int -> [a] -> [[a]]
comb 0 _ = [[]]
comb _ [] = []
comb m (x:xs) = map (x:) (comb (m-1) xs) ++ comb m xs |
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 ... | #Phix | Phix | with javascript_semantics
if name="Pete" then
-- do something
elsif age>50 then
-- do something
elsif age<20 then
-- do something
else
-- do something
end if
|
http://rosettacode.org/wiki/Comments | Comments | Task
Show all ways to include text in a language source file
that's completely ignored by the compiler or interpreter.
Related tasks
Documentation
Here_document
See also
Wikipedia
xkcd (Humor: hand gesture denoting // for "commenting out" people.)
| #Ursala | Ursala | # this is single line a comment
# this is a\
continued comment
(# this is a
multi-line comment #)
(# comments in (# this form #) can (#
be (# arbitrarily #) #) nested #)
---- this is also a comment\
and can be continued
###
The whole rest of the file after three hashes
is a comment. |
http://rosettacode.org/wiki/Comments | Comments | Task
Show all ways to include text in a language source file
that's completely ignored by the compiler or interpreter.
Related tasks
Documentation
Here_document
See also
Wikipedia
xkcd (Humor: hand gesture denoting // for "commenting out" people.)
| #VBA | VBA | ' This is a VBA comment
|
http://rosettacode.org/wiki/Church_numerals | Church numerals | Task
In the Church encoding of natural numbers, the number N is encoded by a function that applies its first argument N times to its second argument.
Church zero always returns the identity function, regardless of its first argument. In other words, the first argument is not applied to the second argument at all.
C... | #Chapel | Chapel | class Church { // identity Church function by default
proc this(f: shared Church): shared Church { return f; }
}
// utility Church functions...
class ComposeChurch : Church {
const l, r: shared Church;
override proc this(f: shared Church): shared Church {
return l(r(f)); }
}
proc composeChur... |
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... | #C | C |
#include <stdlib.h>
typedef struct sMyClass
{
int variable;
} *MyClass;
MyClass MyClass_new()
{
MyClass pthis = malloc(sizeof *pthis);
pthis->variable = 0;
return pthis;
}
void MyClass_delete(MyClass* pthis)
{
if (pthis)
{
free(*pthis);
*pthis = NULL;
}
}
void MyClass_someMethod(MyClass... |
http://rosettacode.org/wiki/Cistercian_numerals | Cistercian numerals | Cistercian numerals were used across Europe by Cistercian monks during the Late Medieval Period as an alternative to Roman numerals. They were used to represent base 10 integers from 0 to 9999.
How they work
All Cistercian numerals begin with a vertical line segment, which by itself represents the number 0. Then, glyp... | #Go | Go | package main
import "fmt"
var n = make([][]string, 15)
func initN() {
for i := 0; i < 15; i++ {
n[i] = make([]string, 11)
for j := 0; j < 11; j++ {
n[i][j] = " "
}
n[i][5] = "x"
}
}
func horiz(c1, c2, r int) {
for c := c1; c <= c2; c++ {
n[r][c] = ... |
http://rosettacode.org/wiki/Colour_bars/Display | Colour bars/Display | Task
Display a series of vertical color bars across the width of the display.
The color bars should either use:
the system palette, or
the sequence of colors:
black
red
green
blue
magenta
cyan
yellow
white
| #SmileBASIC | SmileBASIC | FOR I=0 TO 7
READ R,G,B
GFILL I*50,0,I*50+49,239,RGB(R,G,B)
NEXT
REPEAT UNTIL BUTTON(0) AND #B
DATA 0,0,0
DATA 255,0,0
DATA 0,255,0
DATA 0,0,255
DATA 255,0,255
DATA 0,255,255
DATA 255,255,0
DATA 255,255,255 |
http://rosettacode.org/wiki/Colour_bars/Display | Colour bars/Display | Task
Display a series of vertical color bars across the width of the display.
The color bars should either use:
the system palette, or
the sequence of colors:
black
red
green
blue
magenta
cyan
yellow
white
| #Tcl | Tcl | package require Tcl 8.5
package require Tk 8.5
wm attributes . -fullscreen 1
pack [canvas .c -highlightthick 0] -fill both -expand 1
set colors {black red green blue magenta cyan yellow white}
for {set x 0} {$x < [winfo screenwidth .c]} {incr x 8} {
.c create rectangle $x 0 [expr {$x+7}] [winfo screenheight .c]... |
http://rosettacode.org/wiki/Closest-pair_problem | Closest-pair problem |
This page uses content from Wikipedia. The original article was at Closest pair of points problem. 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
Provide a function to find the closest two p... | #Clojure | Clojure |
(defn distance [[x1 y1] [x2 y2]]
(let [dx (- x2 x1), dy (- y2 y1)]
(Math/sqrt (+ (* dx dx) (* dy dy)))))
(defn brute-force [points]
(let [n (count points)]
(when (< 1 n)
(apply min-key first
(for [i (range 0 (dec n)), :let [p1 (nth points i)],
j (range (inc i) n), :... |
http://rosettacode.org/wiki/Closures/Value_capture | Closures/Value capture | Task
Create a list of ten functions, in the simplest manner possible (anonymous functions are encouraged), such that the function at index i (you may choose to start i from either 0 or 1), when run, should return the square of the index, that is, i 2.
Display the result of runnin... | #Icon_and_Unicon | Icon and Unicon | procedure main(args) # Closure/Variable Capture
every put(L := [], vcapture(1 to 10)) # build list of index closures
write("Randomly selecting L[",i := ?*L,"] = ",L[i]()) # L[i]() calls the closure
end
# The anonymous 'function', as a co-expression. Most o... |
http://rosettacode.org/wiki/Circular_primes | Circular primes | Definitions
A circular prime is a prime number with the property that the number generated at each intermediate step when cyclically permuting its (base 10) digits will also be prime.
For example:
1193 is a circular prime, since 1931, 9311 and 3119 are all also prime.
Note that a number which is a cyclic permutation ... | #Kotlin | Kotlin | import java.math.BigInteger
val SMALL_PRIMES = listOf(
2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97,
101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199,
211, 223, 227, 229, 233, 239, 241, 251, 257, 263, ... |
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... | #C.23 | C# |
// Creates and initializes a new integer Array
int[] intArray = new int[5] { 1, 2, 3, 4, 5 };
//same as
int[] intArray = new int[]{ 1, 2, 3, 4, 5 };
//same as
int[] intArray = { 1, 2, 3, 4, 5 };
//Arrays are zero-based
string[] stringArr = new string[5];
stringArr[0] = "string";
|
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
... | #Icon_and_Unicon | Icon and Unicon | procedure main()
return combinations(3,5,0)
end
procedure combinations(m,n,z) # demonstrate combinations
/z := 1
write(m," combinations of ",n," integers starting from ",z)
every put(L := [], z to n - 1 + z by 1) # generate list of n items from z
write("Intial list\n",list2string(L)... |
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 ... | #PHL | PHL | var a = 5;
if (a == 5) {
doSomething();
} else if (a > 0) {
doSomethingElse();
} else {
error();
} |
http://rosettacode.org/wiki/Comments | Comments | Task
Show all ways to include text in a language source file
that's completely ignored by the compiler or interpreter.
Related tasks
Documentation
Here_document
See also
Wikipedia
xkcd (Humor: hand gesture denoting // for "commenting out" people.)
| #VBScript | VBScript | ' This is a VBScript comment
|
http://rosettacode.org/wiki/Comments | Comments | Task
Show all ways to include text in a language source file
that's completely ignored by the compiler or interpreter.
Related tasks
Documentation
Here_document
See also
Wikipedia
xkcd (Humor: hand gesture denoting // for "commenting out" people.)
| #Verbexx | Verbexx |
//////////////////////////////////////////////////////////////////////////////////////////////
//
// Line Comments:
// =============
//
@VAR v1 = 10; // Line comments start from the "//" and continue to end of the line.
// (normal code can appear on the same line, before the //)
//
// Line comments ... |
http://rosettacode.org/wiki/Church_numerals | Church numerals | Task
In the Church encoding of natural numbers, the number N is encoded by a function that applies its first argument N times to its second argument.
Church zero always returns the identity function, regardless of its first argument. In other words, the first argument is not applied to the second argument at all.
C... | #Clojure | Clojure | (defn zero [f] identity)
(defn succ [n] (fn [f] (fn [x] (f ((n f) x)))))
(defn add [n,m] (fn [f] (fn [x] ((m f)((n f) x)))))
(defn mult [n,m] (fn [f] (fn [x] ((m (n f)) x))))
(defn power [b,e] (e b))
(defn to-int [c] ((c inc) 0))
(defn from-int [n]
(letfn [(countdown [i] (if (zero? i) zero (succ (countdown ... |
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... | #C.23 | C# | public class MyClass
{
public MyClass()
{
}
public void SomeMethod()
{
}
private int _variable;
public int Variable
{
get { return _variable; }
set { _variable = value; }
}
public static void Main()
{
// instantiate it
MyClass instance = ne... |
http://rosettacode.org/wiki/Cistercian_numerals | Cistercian numerals | Cistercian numerals were used across Europe by Cistercian monks during the Late Medieval Period as an alternative to Roman numerals. They were used to represent base 10 integers from 0 to 9999.
How they work
All Cistercian numerals begin with a vertical line segment, which by itself represents the number 0. Then, glyp... | #J | J | main'jc.svg'[load'jc.ijs'
open browser to /tmp/jc.svg
|
http://rosettacode.org/wiki/Cistercian_numerals | Cistercian numerals | Cistercian numerals were used across Europe by Cistercian monks during the Late Medieval Period as an alternative to Roman numerals. They were used to represent base 10 integers from 0 to 9999.
How they work
All Cistercian numerals begin with a vertical line segment, which by itself represents the number 0. Then, glyp... | #Java | Java | import java.util.Arrays;
import java.util.List;
public class Cistercian {
private static final int SIZE = 15;
private final char[][] canvas = new char[SIZE][SIZE];
public Cistercian(int n) {
initN();
draw(n);
}
public void initN() {
for (var row : canvas) {
... |
http://rosettacode.org/wiki/Colour_bars/Display | Colour bars/Display | Task
Display a series of vertical color bars across the width of the display.
The color bars should either use:
the system palette, or
the sequence of colors:
black
red
green
blue
magenta
cyan
yellow
white
| #UNIX_Shell | UNIX Shell | #!/bin/sh
clear
WIDTH=`tput cols`
HEIGHT=`tput lines`
NUMBARS=8
BARWIDTH=`expr $WIDTH / $NUMBARS`
l="1" # Set the line counter to 1
while [ "$l" -lt $HEIGHT ]; do
b="0" # Bar counter
while [ "$b" -lt $NUMBARS ]; do
tput setab $b
s="0"
while [ "$s" -lt $BARWIDTH ]; do
echo -n " "
s=`e... |
http://rosettacode.org/wiki/Colour_bars/Display | Colour bars/Display | Task
Display a series of vertical color bars across the width of the display.
The color bars should either use:
the system palette, or
the sequence of colors:
black
red
green
blue
magenta
cyan
yellow
white
| #Wren | Wren | import "graphics" for Canvas, Color
import "dome" for Window
class Game {
static init() {
Window.title = "Color bars"
__width = 400
__height = 400
Canvas.resize(__width, __height)
Window.resize(__width, __height)
var colors = [
Color.hex("000000"), // bl... |
http://rosettacode.org/wiki/Closest-pair_problem | Closest-pair problem |
This page uses content from Wikipedia. The original article was at Closest pair of points problem. 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
Provide a function to find the closest two p... | #Common_Lisp | Common Lisp | (defun point-distance (p1 p2)
(destructuring-bind (x1 . y1) p1
(destructuring-bind (x2 . y2) p2
(let ((dx (- x2 x1)) (dy (- y2 y1)))
(sqrt (+ (* dx dx) (* dy dy)))))))
(defun closest-pair-bf (points)
(let ((pair (list (first points) (second points)))
(dist (point-distance (first points) ... |
http://rosettacode.org/wiki/Closures/Value_capture | Closures/Value capture | Task
Create a list of ten functions, in the simplest manner possible (anonymous functions are encouraged), such that the function at index i (you may choose to start i from either 0 or 1), when run, should return the square of the index, that is, i 2.
Display the result of runnin... | #Io | Io | blist := list(0,1,2,3,4,5,6,7,8,9) map(i,block(i,block(i*i)) call(i))
writeln(blist at(3) call) // prints 9 |
http://rosettacode.org/wiki/Closures/Value_capture | Closures/Value capture | Task
Create a list of ten functions, in the simplest manner possible (anonymous functions are encouraged), such that the function at index i (you may choose to start i from either 0 or 1), when run, should return the square of the index, that is, i 2.
Display the result of runnin... | #J | J | constF=:3 :0
{.''`(y "_)
) |
http://rosettacode.org/wiki/Circular_primes | Circular primes | Definitions
A circular prime is a prime number with the property that the number generated at each intermediate step when cyclically permuting its (base 10) digits will also be prime.
For example:
1193 is a circular prime, since 1931, 9311 and 3119 are all also prime.
Note that a number which is a cyclic permutation ... | #Lua | Lua | -- Circular primes, in Lua, 6/22/2020 db
local function isprime(n)
if n < 2 then return false end
if n % 2 == 0 then return n==2 end
if n % 3 == 0 then return n==3 end
for f = 5, math.sqrt(n), 6 do
if n % f == 0 or n % (f+2) == 0 then return false end
end
return true
end
local function iscircularprime... |
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... | #C.2B.2B | C++ | int a[5]; // array of 5 ints (since int is POD, the members are not initialized)
a[0] = 1; // indexes start at 0
int primes[10] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29 }; // arrays can be initialized on creation
#include <string>
std::string strings[4]; // std::string is no POD, therefore all array members are defau... |
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
... | #IS-BASIC | IS-BASIC | 100 PROGRAM "Combinat.bas"
110 LET MMAX=3:LET NMAX=5
120 NUMERIC COMB(0 TO MMAX)
130 CALL GENERATE(1)
140 DEF GENERATE(M)
150 NUMERIC N,I
160 IF M>MMAX THEN
170 FOR I=1 TO MMAX
180 PRINT COMB(I);
190 NEXT
200 PRINT
220 ELSE
230 FOR N=0 TO NMAX-1
240 IF M=1 OR N>COMB(M-1) THEN
250 ... |
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 ... | #PHP | PHP | <?php
$foo = 3;
if ($foo == 2)
//do something
if ($foo == 3)
//do something
else
//do something else
if ($foo != 0)
{
//do something
}
else
{
//do another thing
}
?> |
http://rosettacode.org/wiki/Comments | Comments | Task
Show all ways to include text in a language source file
that's completely ignored by the compiler or interpreter.
Related tasks
Documentation
Here_document
See also
Wikipedia
xkcd (Humor: hand gesture denoting // for "commenting out" people.)
| #Verilog | Verilog | // Single line commment.
/*
Multiple
line
comment.
*/ |
http://rosettacode.org/wiki/Comments | Comments | Task
Show all ways to include text in a language source file
that's completely ignored by the compiler or interpreter.
Related tasks
Documentation
Here_document
See also
Wikipedia
xkcd (Humor: hand gesture denoting // for "commenting out" people.)
| #VHDL | VHDL | -- Single line commment in VHDL |
http://rosettacode.org/wiki/Comments | Comments | Task
Show all ways to include text in a language source file
that's completely ignored by the compiler or interpreter.
Related tasks
Documentation
Here_document
See also
Wikipedia
xkcd (Humor: hand gesture denoting // for "commenting out" people.)
| #Vim_Script | Vim Script | let a = 4 " A valid comment
echo "foo" " Not a comment but an argument that misses the closing quote |
http://rosettacode.org/wiki/Chowla_numbers | Chowla numbers | Chowla numbers are also known as:
Chowla's function
chowla numbers
the chowla function
the chowla number
the chowla sequence
The chowla number of n is (as defined by Chowla's function):
the sum of the divisors of n excluding unity and n
where n is a positive integer
The s... | #11l | 11l | F chowla(n)
V sum = 0
V i = 2
L i * i <= n
I n % i == 0
sum += i
V j = n I/ i
I i != j
sum += j
i++
R sum
L(n) 1..37
print(‘chowla(’n‘) = ’chowla(n))
V count = 0
V power = 100
L(n) 2..10'000'000
I chowla(n) == 0
count++
I n % power == 0
... |
http://rosettacode.org/wiki/Church_numerals | Church numerals | Task
In the Church encoding of natural numbers, the number N is encoded by a function that applies its first argument N times to its second argument.
Church zero always returns the identity function, regardless of its first argument. In other words, the first argument is not applied to the second argument at all.
C... | #Crystal | Crystal | struct Church # can't be generic!
getter church : (Church -> Church) | Int32
def initialize(@church) end
def apply(ch)
chf = @church
chf.responds_to?(:call) ? chf.call(ch) : self
end
def compose(chr)
chlf = @church
chrf = chr.church
if chlf.responds_to?(:call) && chrf.responds_to?(:call)
... |
http://rosettacode.org/wiki/Church_numerals | Church numerals | Task
In the Church encoding of natural numbers, the number N is encoded by a function that applies its first argument N times to its second argument.
Church zero always returns the identity function, regardless of its first argument. In other words, the first argument is not applied to the second argument at all.
C... | #Elm | Elm | module Main exposing ( main )
import Html exposing ( Html, text )
type alias Church a = (a -> a) -> a -> a
churchZero : Church a -- a Church constant
churchZero = always identity
succChurch : Church a -> Church a
succChurch ch = \ f -> f << ch f -- add one recursion
addChurch : Church a -> Church a -> Church ... |
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... | #C.2B.2B | C++ | class MyClass
{
public:
void someMethod(); // member function = method
MyClass(); // constructor
private:
int variable; // member variable = instance variable
};
// implementation of constructor
MyClass::MyClass():
variable(0)
{
// here could be more code
}
// implementation of member function
void MyClas... |
http://rosettacode.org/wiki/Cistercian_numerals | Cistercian numerals | Cistercian numerals were used across Europe by Cistercian monks during the Late Medieval Period as an alternative to Roman numerals. They were used to represent base 10 integers from 0 to 9999.
How they work
All Cistercian numerals begin with a vertical line segment, which by itself represents the number 0. Then, glyp... | #JavaScript | JavaScript |
// html
document.write(`
<p><input id="num" type="number" min="0" max="9999" value="0" onchange="showCist()"></p>
<p><canvas id="cist" width="200" height="300"></canvas></p>
<p> <!-- EXAMPLES (can be deleted for normal use) -->
<button onclick="set(0)">0</button>
<button onclick="set(1)">1</button>
... |
http://rosettacode.org/wiki/Colour_bars/Display | Colour bars/Display | Task
Display a series of vertical color bars across the width of the display.
The color bars should either use:
the system palette, or
the sequence of colors:
black
red
green
blue
magenta
cyan
yellow
white
| #XPL0 | XPL0 | include c:\cxpl\codes; \intrinsic code declarations
int W, X0, X1, Y, C;
[SetVid($13); \320x200x8 graphics
W:= 320/8; \width of color bar (pixels)
for C:= 0 to 8-1 do
[X0:= W*C; X1:= X0+W-1;
for Y:= 0 to 200-1 do
[Move(X0, Y); Line(X1, Y, C)];
];
C:= ... |
http://rosettacode.org/wiki/Closest-pair_problem | Closest-pair problem |
This page uses content from Wikipedia. The original article was at Closest pair of points problem. 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
Provide a function to find the closest two p... | #Crystal | Crystal | import std.stdio, std.typecons, std.math, std.algorithm,
std.random, std.traits, std.range, std.complex;
auto bruteForceClosestPair(T)(in T[] points) pure nothrow @nogc {
// return pairwise(points.length.iota, points.length.iota)
// .reduce!(min!((i, j) => abs(points[i] - points[j])));
auto minD = U... |
http://rosettacode.org/wiki/Closures/Value_capture | Closures/Value capture | Task
Create a list of ten functions, in the simplest manner possible (anonymous functions are encouraged), such that the function at index i (you may choose to start i from either 0 or 1), when run, should return the square of the index, that is, i 2.
Display the result of runnin... | #Java | Java | import java.util.function.Supplier;
import java.util.ArrayList;
public class ValueCapture {
public static void main(String[] args) {
ArrayList<Supplier<Integer>> funcs = new ArrayList<>();
for (int i = 0; i < 10; i++) {
int j = i;
funcs.add(() -> j * j);
}
Supplier<Integer> foo = funcs.get(3);
Sy... |
http://rosettacode.org/wiki/Circular_primes | Circular primes | Definitions
A circular prime is a prime number with the property that the number generated at each intermediate step when cyclically permuting its (base 10) digits will also be prime.
For example:
1193 is a circular prime, since 1931, 9311 and 3119 are all also prime.
Note that a number which is a cyclic permutation ... | #Mathematica_.2F_Wolfram_Language | Mathematica / Wolfram Language | ClearAll[RepUnit, CircularPrimeQ]
RepUnit[n_] := (10^n - 1)/9
CircularPrimeQ[n_Integer] := Module[{id = IntegerDigits[n], nums, t},
AllTrue[
Range[Length[id]]
,
Function[{z},
t = FromDigits[RotateLeft[id, z]];
If[t < n,
False
,
PrimeQ[t]
]
]
]
]
Select[Range[200000], Circ... |
http://rosettacode.org/wiki/Circular_primes | Circular primes | Definitions
A circular prime is a prime number with the property that the number generated at each intermediate step when cyclically permuting its (base 10) digits will also be prime.
For example:
1193 is a circular prime, since 1931, 9311 and 3119 are all also prime.
Note that a number which is a cyclic permutation ... | #Nim | Nim | import bignum
import strformat
const SmallPrimes = [
2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97,
101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199,
211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271... |
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... | #Clojure | Clojure | {1 "a", "Q" 10} ; commas are treated as whitespace
(hash-map 1 "a" "Q" 10) ; equivalent to the above
(let [my-map {1 "a"}]
(assoc my-map "Q" 10)) ; "adding" an element |
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
... | #J | J | require'stats' |
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 ... | #Picat | Picat | go =>
N = 10,
% "direct" test that will fail if not satisfied
N < 14,
% if/then/elseif/else
if N < 14 then
println("less than 14")
elseif N == 14 then
println("is 14")
else
println("not less than 14")
end,
% From Prolog: (condition -> then ; else)
( N < 14 ->
println("less than ... |
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.
SQL Code Examples from Training Data
Retrieves raw SQL code examples for the SQL language, which is basic data retrieval without meaningful analysis or patterns.
SQL Code Examples from Training Data
Retrieves raw SQL code examples for the SQL language, which is basic filtering that shows what data looks like but doesn't provide meaningful analysis or patterns.
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.