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/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...
#C.2B.2B
C++
#include <iostream> #include <functional> #include <vector>   int main() { std::vector<std::function<int()> > funcs; for (int i = 0; i < 10; i++) funcs.push_back([=]() { return i * i; }); for ( std::function<int( )> f : funcs ) std::cout << f( ) << std::endl ; return 0; }
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 ...
#C
C
#include <stdbool.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <gmp.h>   bool is_prime(uint32_t n) { if (n == 2) return true; if (n < 2 || n % 2 == 0) return false; for (uint32_t p = 3; p * p <= n; p += 2) { if (n % p == 0) re...
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...
#ABAP
ABAP
  REPORT z_test_rosetta_collection.   CLASS lcl_collection DEFINITION CREATE PUBLIC.   PUBLIC SECTION. METHODS: start. ENDCLASS.   CLASS lcl_collection IMPLEMENTATION. METHOD start. DATA(itab) = VALUE int4_table( ( 1 ) ( 2 ) ( 3 ) ).   cl_demo_output=>display( itab ). ENDMETHOD. ENDCLASS.   START-OF-S...
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 ...
#Emacs_Lisp
Emacs Lisp
(defun comb-recurse (m n n-max) (cond ((zerop m) '(())) ((= n-max n) '()) (t (append (mapcar #'(lambda (rest) (cons n rest)) (comb-recurse (1- m) (1+ n) n-max)) (comb-recurse m (1+ n) n-max)))))   (defun comb (m n) (comb-recurse m 0 n))   (comb 3 5)
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 ...
#Objective-C
Objective-C
let condition = true   if condition then 1 (* evaluate something *) else 2 (* evaluate 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.)
#Set_lang
Set lang
> Comments start where a > (greater than symbol) starts set a 0 > Comments may start after a Set command
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.)
#SETL
SETL
print("This is not a comment"); -- This is a comment $ For nostalgic reasons, this is also 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.)
#Sidef
Sidef
# this is commented
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
#M2000_Interpreter
M2000 Interpreter
  Module Checkit { Module Bars { barwidth=x.twips div 8 barheight=y.twips barcolors=(0,#ff0000,#00ff00, #0000ff, #FF00FF, #00ffff, #ffff00, #ffffff) For i=0 to 7 Move i*barwidth, 0 \\ gradient fill. Here second color are the same ...
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
#Maple
Maple
  with(plottools): plots:-display([rectangle([0, 0], [.3, 2.1], color = black), rectangle([.3, 0], [.6, 2.1], color = red), rectangle([.6, 0], [.9, 2.1], color = green), rectangle([.9, 0], [1.2, 2.1], color = magenta), rectangle([1.2, 0], [1.5, 2.1], color = cyan), rectangle([1.5, 0], [1.8, 2.1], color = white), rectan...
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
#Mathematica_.2F_Wolfram_Language
Mathematica / Wolfram Language
ArrayPlot[ ConstantArray[{Black, Red, Green, Blue, Magenta, Cyan, Yellow, White}, 5]]
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...
#Ceylon
Ceylon
shared void run() {   //create a list of closures with a list comprehension value closures = [for(i in 0:10) () => i ^ 2];   for(i->closure in closures.indexed) { print("closure number ``i`` returns: ``closure()``"); } }
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...
#Clojure
Clojure
(def funcs (map #(fn [] (* % %)) (range 11))) (printf "%d\n%d\n" ((nth funcs 3)) ((nth funcs 4)))
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 ...
#C.2B.2B
C++
#include <cstdint> #include <algorithm> #include <iostream> #include <sstream> #include <gmpxx.h>   typedef mpz_class integer;   bool is_prime(const integer& n, int reps = 50) { return mpz_probab_prime_p(n.get_mpz_t(), reps); }   std::string to_string(const integer& n) { std::ostringstream out; out << n; ...
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...
#Ada
Ada
procedure Array_Collection is   A : array (-3 .. -1) of Integer := (1, 2, 3);   begin   A (-3) := 3; A (-2) := 2; A (-1) := 1;   end Array_Collection;
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 ...
#Erlang
Erlang
  -module(comb). -compile(export_all).   comb(0,_) -> [[]]; comb(_,[]) -> []; comb(N,[H|T]) -> [[H|L] || L <- comb(N-1,T)]++comb(N,T).  
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 ...
#OCaml
OCaml
let condition = true   if condition then 1 (* evaluate something *) else 2 (* evaluate 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.)
#Simula
Simula
COMMENT This is a comment for Simula 67;
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.)
#Slate
Slate
"basically the same as smalltalk"
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.)
#Smalltalk
Smalltalk
"Comments traditionally are in double quotes." "Multiline comments are also supported. Comments are saved as metadata along with the source to a method. A comment just after a method signature is often given to explain the usage of the method. The class browser may display such comments specially."
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
#Nim
Nim
import gintro/[glib, gobject, gtk, gio, cairo]   const Width = 400 Height = 300   #---------------------------------------------------------------------------------------------------   proc draw(area: DrawingArea; context: Context) = ## Draw the color bars.   const Colors = [[0.0, 0.0, 0.0], [255.0, 0.0, 0.0], ...
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
#OCaml
OCaml
open Graphics   let round x = int_of_float (floor (x +. 0.5))   let () = open_graph ""; let cols = size_x () in let rows = size_y () in let colors = [| black; red; green; blue; magenta; cyan; yellow; white |] in let n = Array.length colors in let bar_width = (float cols) /. (float n) in Array.iteri (fun...
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...
#CoffeeScript
CoffeeScript
  # Generate an array of functions. funcs = ( for i in [ 0...10 ] then do ( i ) -> -> i * i )   # Call each function to demonstrate value capture. console.log func() for func in funcs  
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...
#Common_Lisp
Common Lisp
CL-USER> (defparameter alist (loop for i from 1 to 10 collect (cons i (let ((i i)) (lambda () (* i i)))))) ALIST CL-USER> (funcall (cdr (assoc 2 alist))) 4 CL-USER> (funcall (cdr (assoc 8 alist))) 64
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 ...
#D
D
import std.bigint; import std.stdio;   immutable PRIMES = [ 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, 26...
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...
#Aime
Aime
list l;
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 ...
#ERRE
ERRE
  PROGRAM COMBINATIONS   CONST M_MAX=3,N_MAX=5   DIM COMBINATION[M_MAX],STACK[100,1]   PROCEDURE GENERATE(M) LOCAL I IF (M>M_MAX) THEN FOR I=1 TO M_MAX DO PRINT(COMBINATION[I];" ";) END FOR PRINT ELSE FOR N=1 TO N_MAX DO IF ((M=1) OR (N>COMBINATION[M-1])) THEN COMBINATION[M]=...
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 ...
#Octave
Octave
if (condition) % body endif   if (condition) % body else % otherwise body endif   if (condition1) % body elseif (condition2) % body 2 else % otherwise body endif
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.)
#smart_BASIC
smart BASIC
'Single line comments are preceded by a single quote or the command REM   PRINT "Hello" 'Single line comments may follow code   PRINT "Hello" REM You can also use the command REM following code   /* Multi-line comments are surrounded by mirrored slash and asterisk */   /*Multi-line comments do not have to actually hav...
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.)
#SNOBOL4
SNOBOL4
  * An asterisk in column 1 is the standard Snobol comment * mechanism, marking the entire line as a comment. There * are no block or multiline comments.   * Comments may begin at * any position on the line.   - A hyphen in column 1 begins a control statement. - Unrecognized control stateme...
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.)
#SNUSP
SNUSP
'This is single-line comment   ''This is multiline comment''
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
#Perl
Perl
#!/usr/bin/perl -w use strict ; use GD ;   my %colors = ( 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 , 255 ] , black => [ 0 , 0 , 0 ] ) ; my $barwidth = 160 ...
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...
#360_Assembly
360 Assembly
* Closest Pair Problem 10/03/2017 CLOSEST CSECT USING CLOSEST,R13 base register B 72(R15) skip savearea DC 17F'0' savearea STM R14,R12,12(R13) save previous context ST R13,4(R15) link backward ST...
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...
#D
D
import std.stdio;   void main() { int delegate()[] funcs;   foreach (i; 0 .. 10) funcs ~= (i => () => i ^^ 2)(i);   writeln(funcs[3]()); }
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...
#Delphi
Delphi
program Project1;   type TFuncIntResult = reference to function: Integer;   // use function that returns anonymous method to avoid capturing the loop variable function CreateFunc(i: Integer): TFuncIntResult; begin Result := function: Integer begin Result := i * i; end; end;   var Funcs: array[0....
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 ...
#F.23
F#
  // Circular primes - Nigel Galloway: September 13th., 2021 let fG n g=let rec fG y=if y=g then true else if y>g && isPrime y then fG(10*(y%n)+y/n) else false in fG(10*(g%n)+g/n) let rec fN g l=seq{let g=[for n in g do for g in [1;3;7;9] do let g=n*10+g in yield g] in yield! g|>List.filter(fun n->isPrime n && fG l n);...
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...
#ALGOL_68
ALGOL 68
# create a constant array of integers and set its values # []INT constant array = ( 1, 2, 3, 4 ); # create an array of integers that can be changed, note the size mst be specified # # this array has the default lower bound of 1 # [ 5 ]INT mutable array := ( 9, 8, 7, 6, 5 ); # modify the second element of the mutable ar...
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 ...
#F.23
F#
let choose m n = let rec fC prefix m from = seq { let rec loopFor f = seq { match f with | [] -> () | x::xs -> yield (x, fC [] (m-1) xs) yield! loopFor xs } if m = 0 then yield prefix else for (i, s) in 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 ...
#Oforth
Oforth
aBoolean ifTrue: [ ...] aBoolean ifFalse: [ ... ] aObject ifNull: [ ... ] aObject ifNotNull: [ ... ] aObject ifZero: [ ... ]
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.)
#SPL
SPL
'This is single-line comment   ''This is multiline 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.)
#SQL
SQL
SELECT * FROM mytable -- Selects all columns and rows
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.)
#SQL_PL
SQL PL
  --This is a single line 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...
#11l
11l
T MyType Int public_variable // member variable = instance variable . Int private_variable   F () // constructor .private_variable = 0   F someMethod() // member function = method .private_variable = 1 .public_variable = 10
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...
#Action.21
Action!
BYTE FUNC AtasciiToInternal(CHAR c) BYTE c2   c2=c&$7F IF c2<32 THEN RETURN (c+64) ELSEIF c2<96 THEN RETURN (c-32) FI RETURN (c)   PROC CharOut(CARD x BYTE y CHAR c) BYTE i,j,v CARD addr   addr=$E000+AtasciiToInternal(c)*8 FOR j=0 TO 7 DO v=Peek(addr) i=8 WHILE i>0 DO IF (v&1)=0 THEN...
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
#Phix
Phix
-- demo\rosetta\Colour_bars.exw with javascript_semantics include pGUI.e constant colours = {CD_BLACK, CD_RED, CD_GREEN, CD_BLUE, CD_MAGENTA, CD_CYAN, CD_YELLOW, CD_WHITE} Ihandle dlg, canvas cdCanvas cdcanvas function redraw_cb(Ihandle /*ih*/, integer /*posx*/, /*posy*/) integer {width, height} = IupGetIntInt(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...
#Ada
Ada
with Ada.Numerics.Generic_Elementary_Functions; with Ada.Text_IO;   procedure Closest is package Math is new Ada.Numerics.Generic_Elementary_Functions (Float);   Dimension : constant := 2; type Vector is array (1 .. Dimension) of Float; type Matrix is array (Positive range <>) of Vector;   -- calculate t...
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...
#Dyalect
Dyalect
var xs = [] let num = 10   for n in 0..<num { xs.Add((n => () => n * n)(n)) }   for x in xs { print(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...
#EchoLisp
EchoLisp
  (define (fgen i) (lambda () (* i i))) (define fs (for/vector ((i 10)) (fgen i))) ;; vector of 10 anonymous functions ((vector-ref fs 5)) ;; calls fs[5] → 25  
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 ...
#Factor
Factor
USING: combinators.short-circuit formatting io kernel lists lists.lazy math math.combinatorics math.functions math.parser math.primes sequences sequences.extras ;   ! Create an ordered infinite lazy list of circular prime ! "candidates" -- the numbers 2, 3, 5 followed by numbers ! composed of only the digits 1, 3, 7, 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...
#Apex
Apex
  // Create an empty list of String List<String> my_list = new List<String>(); // Create a nested list List<List<Set<Integer>>> my_list_2 = new List<List<Set<Integer>>>();  
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 ...
#Factor
Factor
USING: math.combinatorics prettyprint ;   5 iota 3 all-combinations .
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 ...
#Ol
Ol
  (if (= (* 2 2) 4) (print "if-then: equal")) (if (= (* 2 2) 6) (print "if-then: non equal")) ; ==> if-then: equal  
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.)
#Squirrel
Squirrel
//this is a single line comment   #this is also a single line comment   /* this is a multi-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.)
#SSEM
SSEM
00101010010001000100100100001100
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.)
#Standard_ML
Standard ML
(* This a comment (* containing nested 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...
#ActionScript
ActionScript
package { public class MyClass {   private var myVariable:int; // Note: instance variables are usually "private"   /** * The constructor */ public function MyClass() { // creates a new instance }   /** * A method */ pub...
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...
#Ada
Ada
package My_Package is type My_Type is tagged private; procedure Some_Procedure(Item : out My_Type); function Set(Value : in Integer) return My_Type; private type My_Type is tagged record Variable : Integer := -12; end record; end My_Package;
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...
#AWK
AWK
  # syntax: GAWK -f CISTERCIAN_NUMERALS.AWK [-v debug={0|1}] [-v xc=anychar] numbers 0-9999 ... # # example: GAWK -f CISTERCIAN_NUMERALS.AWK 0 1 20 300 4000 5555 6789 1995 10000 # # sorting: # PROCINFO["sorted_in"] is used by GAWK # SORTTYPE is used by Thompson Automation's TAWK # BEGIN { cistercian_init() ...
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
#PHP
PHP
<?php $colors = array(array( 0, 0, 0), // black array(255, 0, 0), // red array( 0, 255, 0), // green array( 0, 0, 255), // blue array(255, 0, 255), // magenta array( 0, 255, 255), // cyan array(...
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...
#AutoHotkey
AutoHotkey
ClosestPair(points){ if (points.count() <= 3) return bruteForceClosestPair(points) split := xSplit(Points) LP := split.1 ; left points LD := ClosestPair(LP) ; recursion : left closest pair RP := split.2 ; right points RD := ClosestPair(RP) ; recursion : right closest pair minD := min(LD, RD) ; minimum o...
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...
#Elena
Elena
import system'routines; import extensions;   public program() { var functions := Array.allocate(10).populate:(int i => {^ i * i} );   functions.forEach:(func) { console.printLine(func()) } }
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...
#Elixir
Elixir
funs = for i <- 0..9, do: (fn -> i*i end) Enum.each(funs, &IO.puts &1.())
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 ...
#Forth
Forth
  create 235-wheel 6 c, 4 c, 2 c, 4 c, 2 c, 4 c, 6 c, 2 c, does> swap 7 and + c@ ;   0 1 2constant init-235 \ roll 235 wheel at position 1 : next-235 over 235-wheel + swap 1+ swap ;   \ check that n is prime excepting multiples of 2, 3, 5. : sq dup * ; : wheel-prime? ( n -- f ) >r init-235 begin n...
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...
#Arturo
Arturo
; initialize array arr: ["one" 2 "three" "four"]   ; add an element to the array arr: arr ++ 5   ; print it print arr
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 ...
#Fortran
Fortran
program Combinations use iso_fortran_env implicit none   type comb_result integer, dimension(:), allocatable :: combs end type comb_result   type(comb_result), dimension(:), pointer :: r integer :: i, j   call comb(5, 3, r) do i = 0, choose(5, 3) - 1 do j = 2, 0, -1 write(*, "(I4, ' ')...
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 ...
#ooRexx
ooRexx
if arg~isa(.string) & arg~left(1) == "*" then call processArg arg
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.)
#Stata
Stata
* Line comment: must be used at the beginning of a line (does not work in Mata)   // Line comment until the end of the line   /* Multiline 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.)
#Swift
Swift
// this is a single line comment /* This a block comment /* containing nested comment */ */   ///This is a documentation comment   /** This is a documentation block 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.)
#Symsyn
Symsyn
  | This is a 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...
#Aikido
Aikido
class Circle (radius, x, y) extends Shape (x, y) implements Drawable { var myvec = new Vector (x, y)   public function draw() { // draw the circle } }
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...
#ALGOL_68
ALGOL 68
MODE MYDATA = STRUCT( INT name1 ); STRUCT( INT name2, PROC (REF MYDATA)REF MYDATA new, PROC (REF MYDATA)VOID init, PROC (REF MYDATA)VOID some method ) class my data; class my data := ( # name2 := # 2, # Class attribute #   # PROC new := # (REF MYDATA new)REF MYDATA:( (init OF class my ...
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...
#C
C
#include <stdio.h>   #define GRID_SIZE 15 char canvas[GRID_SIZE][GRID_SIZE];   void initN() { int i, j; for (i = 0; i < GRID_SIZE; i++) { for (j = 0; j < GRID_SIZE; j++) { canvas[i][j] = ' '; } canvas[i][5] = 'x'; } }   void horizontal(size_t c1, size_t c2, size_t r) { ...
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
#PicoLisp
PicoLisp
(call 'clear)   (let Width (in '(tput cols) (read)) (do (in '(tput lines) (read)) (for B (range 0 7) (call 'tput 'setab B) (space (/ Width 8)) ) (prinl) ) )   (call 'tput 'sgr0) # reset
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
#Plain_English
Plain English
To run: Start up. Clear the screen. Divide the screen width by 8 giving a bar width. Make a bar with 0 and 0 and the bar width and the screen's bottom. Draw the color bars using the bar. Refresh the screen. Wait for the escape key. Shut down.   To divide the screen width by a number giving a width: Put the screen's rig...
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
#PowerShell
PowerShell
  [string[]]$colors = "Black" , "DarkBlue" , "DarkGreen" , "DarkCyan", "DarkRed" , "DarkMagenta", "DarkYellow", "Gray", "DarkGray", "Blue" , "Green" , "Cyan", "Red" , "Magenta" , "Yellow" , "White"   for ($i = 0; $i -lt 64; $i++) { ...
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...
#AWK
AWK
  # syntax: GAWK -f CLOSEST-PAIR_PROBLEM.AWK BEGIN { x[++n] = 0.654682 ; y[n] = 0.925557 x[++n] = 0.409382 ; y[n] = 0.619391 x[++n] = 0.891663 ; y[n] = 0.888594 x[++n] = 0.716629 ; y[n] = 0.996200 x[++n] = 0.477721 ; y[n] = 0.946355 x[++n] = 0.925092 ; y[n] = 0.818220 x[++n] = 0.624291 ; y[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...
#Emacs_Lisp
Emacs Lisp
;; -*- lexical-binding: t; -*- (mapcar #'funcall (mapcar (lambda (x) (lambda () (* x x))) '(1 2 3 4 5 6 7 8 9 10))) ;; => (1 4 9 16 25 36 49 64 81 100)
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...
#Erlang
Erlang
  -module(capture_demo). -export([demo/0]).   demo() -> Funs = lists:map(fun (X) -> fun () -> X * X end end, lists:seq(1,10)), lists:foreach(fun (F) -> io:...
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 ...
#FreeBASIC
FreeBASIC
#define floor(x) ((x*2.0-0.5)Shr 1)   Function isPrime(Byval p As Integer) As Boolean If p < 2 Then Return False If p Mod 2 = 0 Then Return p = 2 If p Mod 3 = 0 Then Return p = 3 Dim As Integer d = 5 While d * d <= p If p Mod d = 0 Then Return False Else d += 2 If p Mod d = 0 Then Re...
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...
#AutoHotkey
AutoHotkey
myCol := Object() mycol.mykey := "my value!" mycol["mykey"] := "new val!" MsgBox % mycol.mykey ; new val
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 ...
#FreeBASIC
FreeBASIC
sub iterate( byval curr as string, byval start as uinteger,_ byval stp as uinteger, byval depth as uinteger ) dim as uinteger i for i = start to stp if depth = 0 then print curr + " " + str(i) end if iterate( curr+" "+str(i), i+1, stp, depth-1 ) next i r...
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 ...
#OxygenBasic
OxygenBasic
  if a then b=c else b=d   if a=0 b=c elseif a<0 b=d else b=e end if   select case a case 'A' v=21 case 'B' v=22 case 1 to 64 v=a+300 case else v=0 end select    
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.)
#Tcl
Tcl
# comment on a line by itself. The next is a command by itself: set var1 $value1 set var2 $value2 ; # comment that follows a line of code
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.)
#Tern
Tern
:"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.)
#TI-83_BASIC
TI-83 BASIC
:"THIS IS A 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...
#AmigaE
AmigaE
OBJECT a_class varA, varP ENDOBJECT   -> this could be used like a constructor PROC init() OF a_class self.varP := 10 self.varA := 2 ENDPROC   -> the special proc end() is for destructor PROC end() OF a_class -> nothing to do here... ENDPROC   -> a not so useful getter PROC getP() OF a_class IS self.varP   PROC m...
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...
#AutoHotkey
AutoHotkey
obj := new MyClass obj.WhenCreated()   class MyClass { ; Instance Variable #1 time := A_Hour ":" A_Min ":" A_Sec   ; Constructor __New() { MsgBox, % "Constructing new object of type: " this.__Class FormatTime, date, , MM/dd/yyyy ; Instance Variable #2 this.date := date } ; Method WhenCr...
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...
#C.2B.2B
C++
#include <array> #include <iostream>   template<typename T, size_t S> using FixedSquareGrid = std::array<std::array<T, S>, S>;   struct Cistercian { public: Cistercian() { initN(); }   Cistercian(int v) { initN(); draw(v); }   Cistercian &operator=(int v) { initN(); ...
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
#Processing
Processing
fullScreen(); noStroke(); color[] cs = { color(0), // black color(255,0,0), // red color(0,255,0), // green color(255,0,255), // magenta color(0,255,255), // cyan color(255,255,0), // yellow color(255) // white }; for(int i=0; i<7; i++) { fill(cs[i]); rect(i*width/8,0,width/8,height...
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
#Python
Python
  #!/usr/bin/env python #vertical coloured stripes in window in Python 2.7.1   from livewires import *   horiz=640; vert=480 begin_graphics(width=horiz,height=vert,title="v_stripes",background=Colour.black) NameColors=["black","red","green","dark_blue","purple","blue","yellow","white"] stepik=horiz/len(NameColors)   fo...
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...
#BASIC256
BASIC256
  Dim x(9) x = {0.654682, 0.409382, 0.891663, 0.716629, 0.477721, 0.925092, 0.624291, 0.211332, 0.293786, 0.839186} Dim y(9) y = {0.925557, 0.619391, 0.888594, 0.996200, 0.946355, 0.818220, 0.142924, 0.221507, 0.691701, 0.728260}   minDist = 1^30 For i = 0 To 8 For j = i+1 To 9 dist = (x[i] - x[j])^2 + (y[i] - y[j])...
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...
#F.23
F#
[<EntryPoint>] let main argv = let fs = List.init 10 (fun i -> fun () -> i*i) do List.iter (fun f -> printfn "%d" <| f()) fs 0
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...
#Factor
Factor
USING: io kernel locals math prettyprint sequences ;   [let  ! Create a sequence of 10 quotations 10 iota [  :> i  ! Bind lexical variable i [ i i * ]  ! Push a quotation to calculate i squared ] map :> seq   { 3 8 } [ dup pprint " squared is " write seq nth ...
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 ...
#Go
Go
package main   import ( "fmt" big "github.com/ncw/gmp" "strings" )   // OK for 'small' numbers. func isPrime(n int) bool { switch { case n < 2: return false case n%2 == 0: return n == 2 case n%3 == 0: return n == 3 default: d := 5 for d*d <= n { ...
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...
#AWK
AWK
a[0]="hello"
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 ...
#GAP
GAP
# Built-in Combinations([1 .. n], m);   Combinations([1 .. 5], 3); # [ [ 1, 2, 3 ], [ 1, 2, 4 ], [ 1, 2, 5 ], [ 1, 3, 4 ], [ 1, 3, 5 ], # [ 1, 4, 5 ], [ 2, 3, 4 ], [ 2, 3, 5 ], [ 2, 4, 5 ], [ 3, 4, 5 ] ]
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 ...
#Oz
Oz
proc {PrintParity X} if {IsEven X} then {Show even} elseif {IsOdd X} then {Show odd} else {Show 'should not happen'} end 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.)
#TI-89_BASIC
TI-89 BASIC
© This is a comment. Everything from © to the end of the line is ignored.
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.)
#Tiny_BASIC
Tiny BASIC
  10 REM this is a comment 20   40 REM from above you can see that line numbers with no statement 50 REM and blank lines also are ignored  
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.)
#Toka
Toka
#! Everything on this line (after the shebang to the left) will be ignored.