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/Split_a_character_string_based_on_change_of_character
Split a character string based on change of character
Task Split a (character) string into comma (plus a blank) delimited strings based on a change of character   (left to right). Show the output here   (use the 1st example below). Blanks should be treated as any other character   (except they are problematic to display clearly).   The same applies to commas. Fo...
#Ring
Ring
  see split("gHHH5YY++///\")   func split(s ) c =left (s, 1) split = "" for i = 1 to len(s) d = substr(s, i, 1) if d != c split = split + ", " c = d ok split = split + d next return split  
http://rosettacode.org/wiki/Split_a_character_string_based_on_change_of_character
Split a character string based on change of character
Task Split a (character) string into comma (plus a blank) delimited strings based on a change of character   (left to right). Show the output here   (use the 1st example below). Blanks should be treated as any other character   (except they are problematic to display clearly).   The same applies to commas. Fo...
#Ruby
Ruby
def split(str) puts " input string: #{str}" s = str.chars.chunk(&:itself).map{|_,a| a.join}.join(", ") puts "output string: #{s}" s end   split("gHHH5YY++///\\")
http://rosettacode.org/wiki/Stack
Stack
Data Structure This illustrates a data structure, a means of storing data within a program. You may see other such structures in the Data Structures category. A stack is a container of elements with   last in, first out   access policy.   Sometimes it also called LIFO. The stack is accessed through its top. The ba...
#Erlang
Erlang
-module(stack). -export([empty/1, new/0, pop/1, push/2, top/1]).   new() -> [].   empty([]) -> true; empty(_) -> false.   pop([H|T]) -> {H,T}.   push(H,T) -> [H|T].   top([H|_]) -> H.
http://rosettacode.org/wiki/Spiral_matrix
Spiral matrix
Task Produce a spiral array. A   spiral array   is a square arrangement of the first   N2   natural numbers,   where the numbers increase sequentially as you go around the edges of the array spiraling inwards. For example, given   5,   produce this array: 0 1 2 3 4 15 16 17 18 5 14 23 24 19 6 13 22 21 ...
#Common_Lisp
Common Lisp
(defun spiral (rows columns) (do ((N (* rows columns)) (spiral (make-array (list rows columns) :initial-element nil)) (dx 1) (dy 0) (x 0) (y 0) (i 0 (1+ i))) ((= i N) spiral) (setf (aref spiral y x) i) (let ((nx (+ x dx)) (ny (+ y dy))) (cond ((and (< -1 nx columns) ...
http://rosettacode.org/wiki/Special_variables
Special variables
Special variables have a predefined meaning within a computer programming language. Task List the special variables used within the language.
#M2000_Interpreter
M2000 Interpreter
  Module Checkit { Let inkey$="hello", dir$="Something Else" \\ using a dot we tell to interpreter to skip internal identifiers, \\ and look for user variables Print .inkey$="hello", .dir$="Something Else"   Print dir$ ' return current path do Print "wait to press space...
http://rosettacode.org/wiki/Special_variables
Special variables
Special variables have a predefined meaning within a computer programming language. Task List the special variables used within the language.
#Mathematica.2FWolfram_Language
Mathematica/Wolfram Language
Grid[Partition[Names["$*"],4]] -> $Aborted $ActivationGroupID $ActivationKey $ActivationUserRegistered $AddOnsDirectory $AllowDataUpdates $AllowDocumentationUpdates $AllowInternet $AssertFunction $Assump...
http://rosettacode.org/wiki/Special_variables
Special variables
Special variables have a predefined meaning within a computer programming language. Task List the special variables used within the language.
#Maxima
Maxima
/* There are many special variables in Maxima: more than 250 are used for options, for example */ fpprec; /* precision for big floats */ obase; /* number base for output */   /* Other variables are read-only, and give the list of user-defined variables, functions... */ infolists; /* give the names of all available l...
http://rosettacode.org/wiki/Special_characters
Special characters
Special characters are symbols (single characters or sequences of characters) that have a "special" built-in meaning in the language and typically cannot be used in identifiers. Escape sequences are methods that the language uses to remove the special meaning from the symbol, enabling it to be used as a normal charact...
#Erlang
Erlang
  10 \ single cell number -10 \ negative single cell number 10. \ double cell number 10e \ floating-point number
http://rosettacode.org/wiki/Special_characters
Special characters
Special characters are symbols (single characters or sequences of characters) that have a "special" built-in meaning in the language and typically cannot be used in identifiers. Escape sequences are methods that the language uses to remove the special meaning from the symbol, enabling it to be used as a normal charact...
#Forth
Forth
  10 \ single cell number -10 \ negative single cell number 10. \ double cell number 10e \ floating-point number
http://rosettacode.org/wiki/Sorting_algorithms/Stooge_sort
Sorting algorithms/Stooge sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#AutoHotkey
AutoHotkey
StoogeSort(L, i:=1, j:=""){ if !j j := L.MaxIndex() if (L[j] < L[i]){ temp := L[i] L[i] := L[j] L[j] := temp } if (j - i > 1){ t := floor((j - i + 1)/3) StoogeSort(L, i, j-t) StoogeSort(L, i+t, j) StoogeSort(L, i, j-t) } return L }
http://rosettacode.org/wiki/Sorting_algorithms/Sleep_sort
Sorting algorithms/Sleep sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#Brainf.2A.2A.2A
Brainf***
  >>>>>,----------[++++++++ ++[->+>+<<]>+>[-<<+>>]+++ +++++[-<------>]>>+>,---- ------<<+[->>>>>+<<<<<]>> ]>>>[<<<<[<<<[->>+<<[->+> [-]<<]]>[-<+>]>[-<<<.>>>> ->>>>>[>>>>>]<-<<<<[<<<<< ]+<]<<<<]>>>>>[>>>>>]<]  
http://rosettacode.org/wiki/Soundex
Soundex
Soundex is an algorithm for creating indices for words based on their pronunciation. Task The goal is for homophones to be encoded to the same representation so that they can be matched despite minor differences in spelling   (from the   soundex   Wikipedia article). Caution There is a major issue in many of the ...
#11l
11l
V inv_code = [ ‘1’ = [‘B’, ‘F’, ‘P’, ‘V’], ‘2’ = [‘C’, ‘G’, ‘J’, ‘K’, ‘Q’, ‘S’, ‘X’, ‘Z’], ‘3’ = [‘D’, ‘T’], ‘4’ = [‘L’], ‘5’ = [‘M’, ‘N’], ‘6’ = [‘R’] ]   [Char = Char] _code L(k, arr) inv_code L(el) arr _code[el] = k   F soundex(s) V code = String(s[0].uppercase()) V previous = :_code...
http://rosettacode.org/wiki/Sorting_algorithms/Shell_sort
Sorting algorithms/Shell sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#Ada
Ada
generic type Element_Type is digits <>; type Index_Type is (<>); type Array_Type is array(Index_Type range <>) of Element_Type; package Shell_Sort is procedure Sort(Item : in out Array_Type); end Shell_Sort;
http://rosettacode.org/wiki/Sparkline_in_unicode
Sparkline in unicode
A sparkline is a graph of successive values laid out horizontally where the height of the line is proportional to the values in succession. Task Use the following series of Unicode characters to create a program that takes a series of numbers separated by one or more whitespace or comma characters and generates a s...
#Factor
Factor
USING: formatting kernel math math.order math.parser math.statistics sequences splitting ;   : sparkline-index ( v min max -- i ) [ drop - 8 * ] [ swap - /i ] 2bi 0 7 clamp 9601 + ;   : (sparkline) ( seq -- new-seq ) dup minmax [ sparkline-index ] 2curry "" map-as ;   : sparkline ( str -- new-str ) ", " spl...
http://rosettacode.org/wiki/Sorting_algorithms/Strand_sort
Sorting algorithms/Strand sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#jq
jq
# merge input array with array x by comparing the heads of the arrays # in turn; # if both arrays are sorted, the result will be sorted: def merge(x): length as $length | (x|length) as $xl | if $length == 0 then x elif $xl == 0 then . else . as $in | reduce range(0; $xl + $length) as $z ...
http://rosettacode.org/wiki/Sorting_algorithms/Strand_sort
Sorting algorithms/Strand sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#Julia
Julia
function mergelist(a, b) out = Vector{Int}() while !isempty(a) && !isempty(b) if a[1] < b[1] push!(out, popfirst!(a)) else push!(out, popfirst!(b)) end end append!(out, a) append!(out, b) out end   function strand(a) i, s = 1, [popfirst!(a)] ...
http://rosettacode.org/wiki/Stable_marriage_problem
Stable marriage problem
Solve the Stable marriage problem using the Gale/Shapley algorithm. Problem description Given an equal number of men and women to be paired for marriage, each man ranks all the women in order of his preference and each woman ranks all the men in order of her preference. A stable set of engagements for marriage is o...
#Java
Java
import java.util.*;   public class Stable { static List<String> guys = Arrays.asList( new String[]{ "abe", "bob", "col", "dan", "ed", "fred", "gav", "hal", "ian", "jon"}); static List<String> girls = Arrays.asList( new String[]{ "abi", "bea", "cath", "dee", "eve", "fay", ...
http://rosettacode.org/wiki/Square_but_not_cube
Square but not cube
Task Show the first   30   positive integers which are squares but not cubes of such integers. Optionally, show also the first   3   positive integers which are both squares and cubes,   and mark them as such.
#Tcl
Tcl
proc squaregen {{i 0}} { proc squaregen "{i [incr i]}" [info body squaregen] expr $i * $i }   proc is_cube {n} { for {set i 1} {($i * $i * $i) < $n} {incr i} { } expr ($i * $i * $i) == $n }   set cubes {} set noncubes {} for {set s [squaregen]} {[llength $noncubes] < 30} {set s [squaregen]} { if [is_cube $s] ...
http://rosettacode.org/wiki/Split_a_character_string_based_on_change_of_character
Split a character string based on change of character
Task Split a (character) string into comma (plus a blank) delimited strings based on a change of character   (left to right). Show the output here   (use the 1st example below). Blanks should be treated as any other character   (except they are problematic to display clearly).   The same applies to commas. Fo...
#Rust
Rust
fn splitter(string: &str) -> String { let chars: Vec<_> = string.chars().collect(); let mut result = Vec::new(); let mut last_mismatch = 0; for i in 0..chars.len() { if chars.len() == 1 { return chars[0..1].iter().collect(); } if i > 0 && chars[i-1] != chars[i] { ...
http://rosettacode.org/wiki/Split_a_character_string_based_on_change_of_character
Split a character string based on change of character
Task Split a (character) string into comma (plus a blank) delimited strings based on a change of character   (left to right). Show the output here   (use the 1st example below). Blanks should be treated as any other character   (except they are problematic to display clearly).   The same applies to commas. Fo...
#Scala
Scala
// Split a (character) string into comma (plus a blank) delimited strings // based on a change of character (left to right). // See https://rosettacode.org/wiki/Split_a_character_string_based_on_change_of_character#Scala   def runLengthSplit(s: String): String = /// Add a guard letter (s + 'X').sliding(2).map(pair =>...
http://rosettacode.org/wiki/Stack
Stack
Data Structure This illustrates a data structure, a means of storing data within a program. You may see other such structures in the Data Structures category. A stack is a container of elements with   last in, first out   access policy.   Sometimes it also called LIFO. The stack is accessed through its top. The ba...
#F.23
F#
type Stack<'a> //'//(workaround for syntax highlighting problem) (?items) = let items = defaultArg items []   member x.Push(A) = Stack(A::items)   member x.Pop() = match items with | x::xr -> (x, Stack(xr)) | [] -> failwith "Stack is empty."   member x.IsEmpty() = items = []   // example usag...
http://rosettacode.org/wiki/Spiral_matrix
Spiral matrix
Task Produce a spiral array. A   spiral array   is a square arrangement of the first   N2   natural numbers,   where the numbers increase sequentially as you go around the edges of the array spiraling inwards. For example, given   5,   produce this array: 0 1 2 3 4 15 16 17 18 5 14 23 24 19 6 13 22 21 ...
#D
D
void main() { import std.stdio; enum n = 5; int[n][n] M; int pos, side = n;   foreach (immutable i; 0 .. n / 2 + n % 2) { foreach (immutable j; 0 .. side) M[i][i + j] = pos++; foreach (immutable j; 1 .. side) M[i + j][n - 1 - i] = pos++; foreach_revers...
http://rosettacode.org/wiki/Special_variables
Special variables
Special variables have a predefined meaning within a computer programming language. Task List the special variables used within the language.
#ML.2FI
ML/I
MCSKIP "WITH" NL "" Special variables "" There are four different kinds of variables in ML/I. "" Permanent (P) variables - these have no special predefined values. "" Character (C) variables - these have no special predefined values. "" Temporary (T) variables - a macro has at least three of these, and "" those have...
http://rosettacode.org/wiki/Special_variables
Special variables
Special variables have a predefined meaning within a computer programming language. Task List the special variables used within the language.
#Nanoquery
Nanoquery
println dumpstack()
http://rosettacode.org/wiki/Special_characters
Special characters
Special characters are symbols (single characters or sequences of characters) that have a "special" built-in meaning in the language and typically cannot be used in identifiers. Escape sequences are methods that the language uses to remove the special meaning from the symbol, enabling it to be used as a normal charact...
#Fortran
Fortran
C or c in column one mark a comment line. D or d in column one mark a debugging statement, ignored or compiled according to an option set at compile time. * in column one for compiler control statements (e.g. Fortran II, Fortran IV) 0 in column six does not indicate a continuation line, even though not a blank. ...
http://rosettacode.org/wiki/Special_characters
Special characters
Special characters are symbols (single characters or sequences of characters) that have a "special" built-in meaning in the language and typically cannot be used in identifiers. Escape sequences are methods that the language uses to remove the special meaning from the symbol, enabling it to be used as a normal charact...
#FreeBASIC
FreeBASIC
-- comment here until end of line {- comment here -}
http://rosettacode.org/wiki/Sorting_algorithms/Stooge_sort
Sorting algorithms/Stooge sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#BASIC
BASIC
DECLARE SUB stoogesort (L() AS LONG, i AS LONG, j AS LONG)   RANDOMIZE TIMER   CONST arraysize = 10   DIM x(arraysize) AS LONG DIM i AS LONG   PRINT "Before: "; FOR i = 0 TO arraysize x(i) = INT(RND * 100) PRINT x(i); " "; NEXT PRINT   stoogesort x(), 0, arraysize   PRINT "After: "; FOR i = 0 TO arraysize P...
http://rosettacode.org/wiki/Sorting_algorithms/Sleep_sort
Sorting algorithms/Sleep sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#C
C
#include <stdlib.h> #include <unistd.h> #include <sys/types.h> #include <sys/wait.h>   int main(int c, char **v) { while (--c > 1 && !fork()); sleep(c = atoi(v[c])); printf("%d\n", c); wait(0); return 0; }
http://rosettacode.org/wiki/Soundex
Soundex
Soundex is an algorithm for creating indices for words based on their pronunciation. Task The goal is for homophones to be encoded to the same representation so that they can be matched despite minor differences in spelling   (from the   soundex   Wikipedia article). Caution There is a major issue in many of the ...
#360_Assembly
360 Assembly
* Soundex 02/04/2017 SOUNDEX CSECT USING SOUNDEX,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/Sorting_algorithms/Shell_sort
Sorting algorithms/Shell sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#ALGOL_68
ALGOL 68
# -*- coding: utf-8 -*- #   COMMENT REQUIRES( MODE SORTELEMENT = mode of element of array to be sorted... OP < = (SORTELEMENT a, b)BOOL: a < b; ) END COMMENT   MODE SORTELEMENTCMP = PROC(SORTELEMENT,SORTELEMENT)BOOL;   # create a global sort procedure for convenience # PROC(SORTELEMENT,SORTELEMENT)BOOL sor...
http://rosettacode.org/wiki/Sparkline_in_unicode
Sparkline in unicode
A sparkline is a graph of successive values laid out horizontally where the height of the line is proportional to the values in succession. Task Use the following series of Unicode characters to create a program that takes a series of numbers separated by one or more whitespace or comma characters and generates a s...
#FALSE
FALSE
{ variables: s: sign (1 or -1) u: current number f: current number fraction length v: current number is valid t: number of numbers read x: biggest fraction y: smallest number (without fraction) z: biggest number (without fraction) }   {function a: test if top is 0-9, without popping the value, codes 4...
http://rosettacode.org/wiki/Sparkline_in_unicode
Sparkline in unicode
A sparkline is a graph of successive values laid out horizontally where the height of the line is proportional to the values in succession. Task Use the following series of Unicode characters to create a program that takes a series of numbers separated by one or more whitespace or comma characters and generates a s...
#Go
Go
package main   import ( "bufio" "errors" "fmt" "math" "os" "regexp" "strconv" "strings" )   func main() { fmt.Println("Numbers please separated by space/commas:") sc := bufio.NewScanner(os.Stdin) sc.Scan() s, n, min, max, err := spark(sc.Text()) if err != nil { ...
http://rosettacode.org/wiki/Sorting_algorithms/Strand_sort
Sorting algorithms/Strand sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#Kotlin
Kotlin
// version 1.1.2   fun <T : Comparable<T>> strandSort(l: List<T>): List<T> { fun merge(left: MutableList<T>, right: MutableList<T>): MutableList<T> { val res = mutableListOf<T>() while (!left.isEmpty() && !right.isEmpty()) { if (left[0] <= right[0]) { res.add(left[0]) ...
http://rosettacode.org/wiki/Stable_marriage_problem
Stable marriage problem
Solve the Stable marriage problem using the Gale/Shapley algorithm. Problem description Given an equal number of men and women to be paired for marriage, each man ranks all the women in order of his preference and each woman ranks all the men in order of her preference. A stable set of engagements for marriage is o...
#JavaScript
JavaScript
function Person(name) {   var candidateIndex = 0;   this.name = name; this.fiance = null; this.candidates = [];   this.rank = function(p) { for (i = 0; i < this.candidates.length; i++) if (this.candidates[i] === p) return i; return this.candidates.length + 1; }   ...
http://rosettacode.org/wiki/Square_but_not_cube
Square but not cube
Task Show the first   30   positive integers which are squares but not cubes of such integers. Optionally, show also the first   3   positive integers which are both squares and cubes,   and mark them as such.
#UNIX_Shell
UNIX Shell
# First 30 positive integers which are squares but not cubes # also, the first 3 positive integers which are both squares and cubes   ###### # main # ######   integer n sq cr cnt=0   for (( n=1; cnt<30; n++ )); do (( sq = n * n )) (( cr = cbrt(sq) )) if (( (cr * cr * cr) != sq )); then (( cnt++ )) print ${sq}...
http://rosettacode.org/wiki/Square_but_not_cube
Square but not cube
Task Show the first   30   positive integers which are squares but not cubes of such integers. Optionally, show also the first   3   positive integers which are both squares and cubes,   and mark them as such.
#Visual_Basic_.NET
Visual Basic .NET
Module Module1   ' flag / mask explanation: ' bit 0 (1) = increment square ' bit 1 (2) = increment cube ' bit 2 (4) = has output   ' Checks flag against mask, then advances mask. Function ChkFlg(flag As Integer, ByRef mask As Integer) As Boolean ChkFlg = (flag And mask) = mask : mask <<= 1 End Func...
http://rosettacode.org/wiki/Split_a_character_string_based_on_change_of_character
Split a character string based on change of character
Task Split a (character) string into comma (plus a blank) delimited strings based on a change of character   (left to right). Show the output here   (use the 1st example below). Blanks should be treated as any other character   (except they are problematic to display clearly).   The same applies to commas. Fo...
#Sed
Sed
echo 'gHHH5YY++///\' | sed 's/\(.\)\1*/&, /g;s/, $//'
http://rosettacode.org/wiki/Split_a_character_string_based_on_change_of_character
Split a character string based on change of character
Task Split a (character) string into comma (plus a blank) delimited strings based on a change of character   (left to right). Show the output here   (use the 1st example below). Blanks should be treated as any other character   (except they are problematic to display clearly).   The same applies to commas. Fo...
#Sidef
Sidef
func group(str) { gather { while (var match = (str =~ /((.)\g{-1}*)/g)) { take(match[0]) } } }   say group(ARGV[0] \\ 'gHHH5YY++///\\').join(', ')
http://rosettacode.org/wiki/Stack
Stack
Data Structure This illustrates a data structure, a means of storing data within a program. You may see other such structures in the Data Structures category. A stack is a container of elements with   last in, first out   access policy.   Sometimes it also called LIFO. The stack is accessed through its top. The ba...
#Factor
Factor
V{ 1 2 3 } { [ 6 swap push ] [ "hi" swap push ] [ "Vector is now: " write . ] [ "Let's pop it: " write pop . ] [ "Vector is now: " write . ] [ "Top is: " write last . ] } cleave   Vector is now: V{ 1 2 3 6 "hi" } Let's pop it: "hi" Vector is now: V{ 1 2 3 6 } Top is: 6
http://rosettacode.org/wiki/Spiral_matrix
Spiral matrix
Task Produce a spiral array. A   spiral array   is a square arrangement of the first   N2   natural numbers,   where the numbers increase sequentially as you go around the edges of the array spiraling inwards. For example, given   5,   produce this array: 0 1 2 3 4 15 16 17 18 5 14 23 24 19 6 13 22 21 ...
#DCL
DCL
$ p1 = f$integer( p1 ) $ max = p1 * p1 $ $ i = 0 $ r = 1 $ rd = 0 $ c = 1 $ cd = 1 $ loop: $ a'r'_'c' = i $ nr = r + rd $ nc = c + cd $ if nr .eq. 0 .or. nc .eq. 0 .or. nr .gt. p1 .or. nc .gt. p1 .or. f$type( a'nr'_'nc' ) .nes. "" $ then $ gosub change_directions $ endif $ r = r + rd $ c = c + cd $ i = i + 1...
http://rosettacode.org/wiki/Special_variables
Special variables
Special variables have a predefined meaning within a computer programming language. Task List the special variables used within the language.
#NetRexx
NetRexx
/* NetRexx */ options replace format comments java crossref savelog symbols binary   class RCSpecialVariables   method RCSpecialVariables() x = super.toString y = this.toString say '<super>'x'</super>' say '<this>'y'</this>' say '<class>'RCSpecialVariables.class'</class>' say '<digits>'digits'</digits>' s...
http://rosettacode.org/wiki/Special_variables
Special variables
Special variables have a predefined meaning within a computer programming language. Task List the special variables used within the language.
#Nim
Nim
result = value return
http://rosettacode.org/wiki/Special_characters
Special characters
Special characters are symbols (single characters or sequences of characters) that have a "special" built-in meaning in the language and typically cannot be used in identifiers. Escape sequences are methods that the language uses to remove the special meaning from the symbol, enabling it to be used as a normal charact...
#Gambas
Gambas
-- comment here until end of line {- comment here -}
http://rosettacode.org/wiki/Special_characters
Special characters
Special characters are symbols (single characters or sequences of characters) that have a "special" built-in meaning in the language and typically cannot be used in identifiers. Escape sequences are methods that the language uses to remove the special meaning from the symbol, enabling it to be used as a normal charact...
#Go
Go
-- comment here until end of line {- comment here -}
http://rosettacode.org/wiki/Sorting_algorithms/Stooge_sort
Sorting algorithms/Stooge sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#BBC_BASIC
BBC BASIC
DIM test%(9) test%() = 4, 65, 2, -31, 0, 99, 2, 83, 782, 1 PROCstoogesort(test%(), 0, DIM(test%(),1)) FOR i% = 0 TO 9 PRINT test%(i%) ; NEXT PRINT END   DEF PROCstoogesort(l%(), i%, j%) LOCAL t% IF l%(j%) < l%(i%) SWAP l%(i%), l%(j%) IF j% - i% >...
http://rosettacode.org/wiki/Sorting_algorithms/Stooge_sort
Sorting algorithms/Stooge sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#BCPL
BCPL
get "libhdr"   let stoogesort(L, i, j) be $( if L!j < L!i then $( let x = L!i L!i := L!j L!j := x $) if j-i>1 then $( let t = (j - i + 1)/3 stoogesort(L, i, j-t) stoogesort(L, i+t, j) stoogesort(L, i, j-t) $) $)   let write(s, A, len) be $( writes(s) f...
http://rosettacode.org/wiki/Sorting_algorithms/Sleep_sort
Sorting algorithms/Sleep sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#C.23
C#
using System; using System.Collections.Generic; using System.Linq; using System.Threading;   class Program { static void ThreadStart(object item) { Thread.Sleep(1000 * (int)item); Console.WriteLine(item); }   static void SleepSort(IEnumerable<int> items) { foreach (var item i...
http://rosettacode.org/wiki/Sorting_algorithms/Selection_sort
Sorting algorithms/Selection sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#11l
11l
F selection_sort(&lst) L(e) lst V mn = min(L.index .< lst.len, key' x -> @lst[x]) (lst[L.index], lst[mn]) = (lst[mn], e)   V arr = [7, 6, 5, 9, 8, 4, 3, 1, 2, 0] selection_sort(&arr) print(arr)
http://rosettacode.org/wiki/Soundex
Soundex
Soundex is an algorithm for creating indices for words based on their pronunciation. Task The goal is for homophones to be encoded to the same representation so that they can be matched despite minor differences in spelling   (from the   soundex   Wikipedia article). Caution There is a major issue in many of the ...
#Ada
Ada
with Ada.Text_IO; use Ada.Text_IO; with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; with Ada.Characters.Handling; use Ada.Characters.Handling; procedure Soundex is type UStrings is array(Natural range <>) of Unbounded_String; function "+"(S:String) return Unbounded_String renames To_Unbounded_String;   f...
http://rosettacode.org/wiki/Sorting_algorithms/Shell_sort
Sorting algorithms/Shell sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#AppleScript
AppleScript
-- In-place Shell sort. -- Algorithm: Donald Shell, 1959. on ShellSort(theList, l, r) -- Sort items l thru r of theList. set listLength to (count theList) if (listLength < 2) then return -- Convert negative and/or transposed range indices. if (l < 0) then set l to listLength + l + 1 if (r < 0) then ...
http://rosettacode.org/wiki/Sparkline_in_unicode
Sparkline in unicode
A sparkline is a graph of successive values laid out horizontally where the height of the line is proportional to the values in succession. Task Use the following series of Unicode characters to create a program that takes a series of numbers separated by one or more whitespace or comma characters and generates a s...
#Groovy
Groovy
def sparkline(List<Number> list) { def (min, max) = [list.min(), list.max()] def div = (max - min) / 7 list.collect { (char)(0x2581 + (it-min) * div) }.join() } def sparkline(String text) { sparkline(text.split(/[ ,]+/).collect { it as Double }) }
http://rosettacode.org/wiki/Sorting_algorithms/Strand_sort
Sorting algorithms/Strand sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#Mathematica.2FWolfram_Language
Mathematica/Wolfram Language
StrandSort[ input_ ] := Module[ {results = {}, A = input}, While[Length@A > 0, sublist = {A[[1]]}; A = A[[2;;All]]; For[i = 1, i < Length@A, i++, If[ A[[i]] > Last@sublist, AppendTo[sublist, A[[i]]]; A = Delete[A, i];] ]; results = #[[Ordering@#]]&@Join[sublist, results];]; results ] StrandSort[{2, 3, 7, 5, 1...
http://rosettacode.org/wiki/Stable_marriage_problem
Stable marriage problem
Solve the Stable marriage problem using the Gale/Shapley algorithm. Problem description Given an equal number of men and women to be paired for marriage, each man ranks all the women in order of his preference and each woman ranks all the men in order of her preference. A stable set of engagements for marriage is o...
#Julia
Julia
  # This is not optimized, but tries to follow the pseudocode given the Wikipedia entry below. # Reference: https://en.wikipedia.org/wiki/Stable_marriage_problem#Algorithm   const males = ["abe", "bob", "col", "dan", "ed", "fred", "gav", "hal", "ian", "jon"] const females = ["abi", "bea", "cath", "dee", "eve", "fay", "...
http://rosettacode.org/wiki/Square_but_not_cube
Square but not cube
Task Show the first   30   positive integers which are squares but not cubes of such integers. Optionally, show also the first   3   positive integers which are both squares and cubes,   and mark them as such.
#VTL-2
VTL-2
10 N=0 20 S=1 30 C=1 40 #=60 50 C=C+1 60 #=C*C*C<(S*S)*50 70 #=C*C*C=(S*S)*110 80 N=N+1 90 ?=S*S 100 $=32 110 S=S+1 120 #=N<30*60
http://rosettacode.org/wiki/Square_but_not_cube
Square but not cube
Task Show the first   30   positive integers which are squares but not cubes of such integers. Optionally, show also the first   3   positive integers which are both squares and cubes,   and mark them as such.
#Wren
Wren
import "/math" for Math import "/fmt" for Fmt   var i = 1 var sqnc = [] // squares not cubes var sqcb = [] // squares and cubes while (sqnc.count < 30 || sqcb.count < 3) { var sq = i * i var cb = Math.cbrt(sq).round if (cb*cb*cb != sq) { sqnc.add(sq) } else { sqcb.add(sq) } i =...
http://rosettacode.org/wiki/Split_a_character_string_based_on_change_of_character
Split a character string based on change of character
Task Split a (character) string into comma (plus a blank) delimited strings based on a change of character   (left to right). Show the output here   (use the 1st example below). Blanks should be treated as any other character   (except they are problematic to display clearly).   The same applies to commas. Fo...
#SNOBOL4
SNOBOL4
  * Program: split_on_change_of_character.sbl * To run: sbl split_on_change_of_character.sbl * Description: Split a (character) string into comma (plus a blank) * delimited strings based on a change of character (left to right). * * Blanks should be treated as any other character * (except they are problematic to dis...
http://rosettacode.org/wiki/Split_a_character_string_based_on_change_of_character
Split a character string based on change of character
Task Split a (character) string into comma (plus a blank) delimited strings based on a change of character   (left to right). Show the output here   (use the 1st example below). Blanks should be treated as any other character   (except they are problematic to display clearly).   The same applies to commas. Fo...
#Standard_ML
Standard ML
(* * Head-Tail implementation of grouping *) fun group' ac nil = [ac] | group' nil (y::ys) = group' [y] ys | group' (x::ac) (y::ys) = if x=y then group' (y::x::ac) ys else (x::ac) :: group' [y] ys   fun group xs = group' nil xs   fun groupString str = String.concatWith ", " (map implode (group (explo...
http://rosettacode.org/wiki/Stack
Stack
Data Structure This illustrates a data structure, a means of storing data within a program. You may see other such structures in the Data Structures category. A stack is a container of elements with   last in, first out   access policy.   Sometimes it also called LIFO. The stack is accessed through its top. The ba...
#Forth
Forth
: stack ( size -- ) create here cell+ , cells allot ;   : push ( n st -- ) tuck @ ! cell swap +! ; : pop ( st -- n ) -cell over +! @ @ ; : empty? ( st -- ? ) dup @ - cell+ 0= ;   10 stack st   1 st push 2 st push 3 st push st empty? . \ 0 (false) st pop . st pop . st pop . \ 3 2 1 st empty? . \ -1 (true)
http://rosettacode.org/wiki/Spiral_matrix
Spiral matrix
Task Produce a spiral array. A   spiral array   is a square arrangement of the first   N2   natural numbers,   where the numbers increase sequentially as you go around the edges of the array spiraling inwards. For example, given   5,   produce this array: 0 1 2 3 4 15 16 17 18 5 14 23 24 19 6 13 22 21 ...
#E
E
/** Missing scalar multiplication, but we don't need it. */ def makeVector2(x, y) { return def vector { to x() { return x } to y() { return y } to add(other) { return makeVector2(x + other.x(), y + other.y()) } to clockwise() { return makeVector2(-y, x) } } }   /** Bugs: (1) The printing is speciali...
http://rosettacode.org/wiki/Special_variables
Special variables
Special variables have a predefined meaning within a computer programming language. Task List the special variables used within the language.
#OASYS
OASYS
val argv : string array (** The command line arguments given to the process. The first element is the command name used to invoke the program. The following elements are the command-line arguments given to the program. *)   val executable_name : string (** The name of the file containing the executable current...
http://rosettacode.org/wiki/Special_variables
Special variables
Special variables have a predefined meaning within a computer programming language. Task List the special variables used within the language.
#OASYS_Assembler
OASYS Assembler
val argv : string array (** The command line arguments given to the process. The first element is the command name used to invoke the program. The following elements are the command-line arguments given to the program. *)   val executable_name : string (** The name of the file containing the executable current...
http://rosettacode.org/wiki/Sorting_algorithms/Permutation_sort
Sorting algorithms/Permutation sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#11l
11l
F is_sorted(arr) L(i) 1..arr.len-1 I arr[i-1] > arr[i] R 0B R 1B   F permutation_sort(&arr) L !is_sorted(arr) arr.next_permutation()   V arr = [7, 6, 5, 9, 8, 4, 3, 1, 2, 0] permutation_sort(&arr) print(arr)
http://rosettacode.org/wiki/Special_characters
Special characters
Special characters are symbols (single characters or sequences of characters) that have a "special" built-in meaning in the language and typically cannot be used in identifiers. Escape sequences are methods that the language uses to remove the special meaning from the symbol, enabling it to be used as a normal charact...
#GUISS
GUISS
-- comment here until end of line {- comment here -}
http://rosettacode.org/wiki/Special_characters
Special characters
Special characters are symbols (single characters or sequences of characters) that have a "special" built-in meaning in the language and typically cannot be used in identifiers. Escape sequences are methods that the language uses to remove the special meaning from the symbol, enabling it to be used as a normal charact...
#Haskell
Haskell
-- comment here until end of line {- comment here -}
http://rosettacode.org/wiki/Sorting_algorithms/Stooge_sort
Sorting algorithms/Stooge sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#C
C
#include <stdio.h>   #define SWAP(r,s) do{ t=r; r=s; s=t; } while(0)   void StoogeSort(int a[], int i, int j) { int t;   if (a[j] < a[i]) SWAP(a[i], a[j]); if (j - i > 1) { t = (j - i + 1) / 3; StoogeSort(a, i, j - t); StoogeSort(a, i + t, j); StoogeSort(a, i, j - t); } }   ...
http://rosettacode.org/wiki/Sorting_algorithms/Sleep_sort
Sorting algorithms/Sleep sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#C.2B.2B
C++
  #include <chrono> #include <iostream> #include <thread> #include <vector>   int main(int argc, char* argv[]) { std::vector<std::thread> threads;   for (int i = 1; i < argc; ++i) { threads.emplace_back([i, &argv]() { int arg = std::stoi(argv[i]); std::this_thread::sleep_for(std::chrono::seconds(arg...
http://rosettacode.org/wiki/Sorting_algorithms/Sleep_sort
Sorting algorithms/Sleep sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#Clojure
Clojure
(ns sleepsort.core (require [clojure.core.async :as async :refer [chan go <! <!! >! timeout]]))   (defn sleep-sort [l] (let [c (chan (count l))] (doseq [i l] (go (<! (timeout (* 1000 i))) (>! c i))) (<!! (async/into [] (async/take (count l) c)))))
http://rosettacode.org/wiki/Sorting_algorithms/Selection_sort
Sorting algorithms/Selection sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#360_Assembly
360 Assembly
* Selection sort 26/06/2016 SELECSRT CSECT USING SELECSRT,R13 base register B 72(R15) skip savearea DC 17F'0' savearea STM R14,R12,12(R13) prolog ST R13,4(R15) " ST R15,8(R13) " ...
http://rosettacode.org/wiki/Soundex
Soundex
Soundex is an algorithm for creating indices for words based on their pronunciation. Task The goal is for homophones to be encoded to the same representation so that they can be matched despite minor differences in spelling   (from the   soundex   Wikipedia article). Caution There is a major issue in many of the ...
#ALGOL_68
ALGOL 68
PROC soundex = (STRING s) STRING: BEGIN PROC encode = (CHAR c) CHAR: BEGIN # We assume the alphabet is contiguous. # "-123-12*-22455-12623-1*2-2"[ABS to lower(c) - ABS "a" + 1] END; INT soundex code length = 4; STRING result := soundex code length ...
http://rosettacode.org/wiki/Sorting_algorithms/Shell_sort
Sorting algorithms/Shell sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#ARM_Assembly
ARM Assembly
  /* ARM assembly Raspberry PI */ /* program shellSort.s */   /************************************/ /* Constantes */ /************************************/ .equ STDOUT, 1 @ Linux output console .equ EXIT, 1 @ Linux syscall .equ WRITE, 4 @ Linux syscall /************************...
http://rosettacode.org/wiki/Sparkline_in_unicode
Sparkline in unicode
A sparkline is a graph of successive values laid out horizontally where the height of the line is proportional to the values in succession. Task Use the following series of Unicode characters to create a program that takes a series of numbers separated by one or more whitespace or comma characters and generates a s...
#Haskell
Haskell
import Data.List.Split (splitOneOf) import Data.Char (chr)     toSparkLine :: [Double] -> String toSparkLine xs = map cl xs where top = maximum xs bot = minimum xs range = top - bot cl x = chr $ 0x2581 + floor (min 7 ((x - bot) / range * 8))   makeSparkLine :: String -> (String, Stats) makeSparkLine x...
http://rosettacode.org/wiki/Sorting_algorithms/Strand_sort
Sorting algorithms/Strand sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#MAXScript
MAXScript
fn strandSort arr = ( arr = deepcopy arr local sub = #() local results = #() while arr.count > 0 do ( sub = #() append sub (amax arr) deleteitem arr (for i in 1 to arr.count where arr[i] == amax arr collect i)[1] local i = 1 while i <= arr.count do ( if arr[i] > sub[sub.count] do ( append sub...
http://rosettacode.org/wiki/Sorting_algorithms/Strand_sort
Sorting algorithms/Strand sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#NetRexx
NetRexx
/* NetRexx */ options replace format comments java crossref savelog symbols binary   import java.util.List   placesList = [String - "UK London", "US New York", "US Boston", "US Washington" - , "UK Washington", "US Birmingham", "UK Birmingham", "UK Boston" - ]   lists = [ - placesList - ...
http://rosettacode.org/wiki/Stable_marriage_problem
Stable marriage problem
Solve the Stable marriage problem using the Gale/Shapley algorithm. Problem description Given an equal number of men and women to be paired for marriage, each man ranks all the women in order of his preference and each woman ranks all the men in order of her preference. A stable set of engagements for marriage is o...
#Kotlin
Kotlin
  data class Person(val name: String) { val preferences = mutableListOf<Person>() var matchedTo: Person? = null   fun trySwap(p: Person) { if (prefers(p)) { matchedTo?.matchedTo = null matchedTo = p p.matchedTo = this } }   fun prefers(p: Person) =...
http://rosettacode.org/wiki/Square_but_not_cube
Square but not cube
Task Show the first   30   positive integers which are squares but not cubes of such integers. Optionally, show also the first   3   positive integers which are both squares and cubes,   and mark them as such.
#XPL0
XPL0
int C, N, N2, T; [C:= 0; N:= 1; loop [N2:= N*N; IntOut(0, N2); T:= fix(Pow(float(N2), 1./3.)); if T*T*T # N2 then [ChOut(0, ^ ); C:= C+1; if C >= 30 then quit; ] else Text(0, "* "); N:= N+1; ]; Text(0...
http://rosettacode.org/wiki/Square_but_not_cube
Square but not cube
Task Show the first   30   positive integers which are squares but not cubes of such integers. Optionally, show also the first   3   positive integers which are both squares and cubes,   and mark them as such.
#zkl
zkl
println("First 30 positive integers that are a square but not a cube:"); squareButNotCube:=(1).walker(*).tweak(fcn(n){ sq,cr := n*n, sq.toFloat().pow(1.0/3).round(); // cube root(64)<4 if(sq==cr*cr*cr) Void.Skip else sq }); squareButNotCube.walk(30).concat(",").println("\n");   println("First 15 positive integer...
http://rosettacode.org/wiki/Split_a_character_string_based_on_change_of_character
Split a character string based on change of character
Task Split a (character) string into comma (plus a blank) delimited strings based on a change of character   (left to right). Show the output here   (use the 1st example below). Blanks should be treated as any other character   (except they are problematic to display clearly).   The same applies to commas. Fo...
#Swift
Swift
public extension String { func splitOnChanges() -> [String] { guard !isEmpty else { return [] }   var res = [String]() var workingChar = first! var workingStr = "\(workingChar)"   for char in dropFirst() { if char != workingChar { res.append(workingStr) workingStr =...
http://rosettacode.org/wiki/Split_a_character_string_based_on_change_of_character
Split a character string based on change of character
Task Split a (character) string into comma (plus a blank) delimited strings based on a change of character   (left to right). Show the output here   (use the 1st example below). Blanks should be treated as any other character   (except they are problematic to display clearly).   The same applies to commas. Fo...
#Tailspin
Tailspin
  composer splitEquals <reps> <nextReps>* rule reps: <'(.)\1*'> rule nextReps: <reps> -> \(', ' ! $ ! \) end splitEquals   'gHHH5YY++///\' -> splitEquals -> !OUT::write  
http://rosettacode.org/wiki/Stack
Stack
Data Structure This illustrates a data structure, a means of storing data within a program. You may see other such structures in the Data Structures category. A stack is a container of elements with   last in, first out   access policy.   Sometimes it also called LIFO. The stack is accessed through its top. The ba...
#Fortran
Fortran
module mod_stack   implicit none type node ! data entry in each node real*8, private :: data ! pointer to the next node of the linked list type(node), pointer, private :: next end type node private node   type stack ! pointer to first element of stack. type(node), pointer, private :: f...
http://rosettacode.org/wiki/Spiral_matrix
Spiral matrix
Task Produce a spiral array. A   spiral array   is a square arrangement of the first   N2   natural numbers,   where the numbers increase sequentially as you go around the edges of the array spiraling inwards. For example, given   5,   produce this array: 0 1 2 3 4 15 16 17 18 5 14 23 24 19 6 13 22 21 ...
#Elixir
Elixir
defmodule RC do def spiral_matrix(n) do wide = length(to_char_list(n*n-1)) fmt = String.duplicate("~#{wide}w ", n) <> "~n" runs = Enum.flat_map(n..1, &[&1,&1]) |> tl delta = Stream.cycle([{0,1},{1,0},{0,-1},{-1,0}]) running(Enum.zip(runs,delta),0,-1,[]) |> Enum.with_index |> Enum.sort |> Enum...
http://rosettacode.org/wiki/Special_variables
Special variables
Special variables have a predefined meaning within a computer programming language. Task List the special variables used within the language.
#OCaml
OCaml
val argv : string array (** The command line arguments given to the process. The first element is the command name used to invoke the program. The following elements are the command-line arguments given to the program. *)   val executable_name : string (** The name of the file containing the executable current...
http://rosettacode.org/wiki/Sorting_algorithms/Permutation_sort
Sorting algorithms/Permutation sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#AArch64_Assembly
AArch64 Assembly
  /* ARM assembly AARCH64 Raspberry PI 3B */ /* program permutationSort64.s */   /*******************************************/ /* Constantes file */ /*******************************************/ /* for this file see task include a file in language AArch64 assembly */ .include "../includeConsta...
http://rosettacode.org/wiki/Sorting_algorithms/Permutation_sort
Sorting algorithms/Permutation sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#ActionScript
ActionScript
//recursively builds the permutations of permutable, appended to front, and returns the first sorted permutation it encounters function permutations(front:Array, permutable:Array):Array { //If permutable has length 1, there is only one possible permutation. Check whether it's sorted if (permutable.length==1) return...
http://rosettacode.org/wiki/Special_characters
Special characters
Special characters are symbols (single characters or sequences of characters) that have a "special" built-in meaning in the language and typically cannot be used in identifiers. Escape sequences are methods that the language uses to remove the special meaning from the symbol, enabling it to be used as a normal charact...
#HicEst
HicEst
\b backspace \d delete \e escape \f formfeed \l linefeed \n newline \r return \t horizontal tab \v vertical tab \' single quote \" double quote \\ backslash \ddd octal code \xdd hexadecimal code \^c control code
http://rosettacode.org/wiki/Special_characters
Special characters
Special characters are symbols (single characters or sequences of characters) that have a "special" built-in meaning in the language and typically cannot be used in identifiers. Escape sequences are methods that the language uses to remove the special meaning from the symbol, enabling it to be used as a normal charact...
#HTML
HTML
\b backspace \d delete \e escape \f formfeed \l linefeed \n newline \r return \t horizontal tab \v vertical tab \' single quote \" double quote \\ backslash \ddd octal code \xdd hexadecimal code \^c control code
http://rosettacode.org/wiki/Sorting_algorithms/Stooge_sort
Sorting algorithms/Stooge sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#C.23
C#
public static void Sort<T>(List<T> list) where T : IComparable { if (list.Count > 1) { StoogeSort(list, 0, list.Count - 1); } } private static void StoogeSort<T>(List<T> L, int i, int j) where T : IComparable { if (L[j].CompareTo(L[i])<0) { T tmp = L[i]; ...
http://rosettacode.org/wiki/Sorting_algorithms/Sleep_sort
Sorting algorithms/Sleep sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#CoffeeScript
CoffeeScript
  after = (s, f) -> setTimeout f, s*1000   # Setting Computer Science back at least a century, maybe more, # this algorithm sorts integers using a highly parallelized algorithm. sleep_sort = (arr) -> for n in arr do (n) -> after n, -> console.log n   do -> input = (parseInt(arg) for arg in process.argv[2...]) ...
http://rosettacode.org/wiki/Sorting_algorithms/Sleep_sort
Sorting algorithms/Sleep sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#Common_Lisp
Common Lisp
(defun sleeprint(n) (sleep (/ n 10)) (format t "~a~%" n))   (loop for arg in (cdr sb-ext:*posix-argv*) doing (sb-thread:make-thread (lambda() (sleeprint (parse-integer arg)))))   (loop while (not (null (cdr (sb-thread:list-all-threads)))))
http://rosettacode.org/wiki/Sorting_algorithms/Selection_sort
Sorting algorithms/Selection sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#AArch64_Assembly
AArch64 Assembly
  /* ARM assembly AARCH64 Raspberry PI 3B */ /* program selectionSort64.s */   /*******************************************/ /* Constantes file */ /*******************************************/ /* for this file see task include a file in language AArch64 assembly */ .include "../includeConstan...
http://rosettacode.org/wiki/Soundex
Soundex
Soundex is an algorithm for creating indices for words based on their pronunciation. Task The goal is for homophones to be encoded to the same representation so that they can be matched despite minor differences in spelling   (from the   soundex   Wikipedia article). Caution There is a major issue in many of the ...
#ANSI_Standard_BASIC
ANSI Standard BASIC
100 DECLARE EXTERNAL FUNCTION FNSoundex$ 110 120 DATA Ashcraft, Ashcroft, Gauss, Ghosh, Hilbert, Heilbronn, Lee, Lloyd 130 DATA Moses, Pfister, Robert, Rupert, Rubin, Tymczak, Soundex, Example 140 FOR i = 1 TO 16 150 READ name$ 160 PRINT """"; name$; """"; TAB(15); FNsoundex$(name$) 170 NEXT i 180 END 190 200 E...
http://rosettacode.org/wiki/Sorting_algorithms/Shell_sort
Sorting algorithms/Shell sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#Arturo
Arturo
shellSort: function [items][ a: new items h: size a   while [h > 0][ h: h / 2 loop h..dec size a 'i [ k: a\[i] j: i   while [and? [j >= h] [k < a\[j-h]]][ a\[j]: a\[j-h] j: j - h ] a\[j]: k ] ...
http://rosettacode.org/wiki/Sparkline_in_unicode
Sparkline in unicode
A sparkline is a graph of successive values laid out horizontally where the height of the line is proportional to the values in succession. Task Use the following series of Unicode characters to create a program that takes a series of numbers separated by one or more whitespace or comma characters and generates a s...
#J
J
spkln =: verb define y spkln~ 4 u:16b2581+i.8 NB. ▁▂▃▄▅▆▇█  : 'MIN MAX' =. (<./ , >./) y N =. # x x {~ <. (N-1) * (y-MIN) % MAX-MIN )
http://rosettacode.org/wiki/Sparkline_in_unicode
Sparkline in unicode
A sparkline is a graph of successive values laid out horizontally where the height of the line is proportional to the values in succession. Task Use the following series of Unicode characters to create a program that takes a series of numbers separated by one or more whitespace or comma characters and generates a s...
#Java
Java
  public class Sparkline { String bars="▁▂▃▄▅▆▇█"; public static void main(String[] args) { Sparkline now=new Sparkline(); float[] arr={1, 2, 3, 4, 5, 6, 7, 8, 7, 6, 5, 4, 3, 2, 1}; now.display1D(arr); System.out.println(now.getSparkline(arr)); float[] arr1={1.5f, 0.5f, 3.5f, 2.5f, 5.5f, 4.5f, 7.5f, 6.5f}...
http://rosettacode.org/wiki/Sorting_algorithms/Strand_sort
Sorting algorithms/Strand sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#Nim
Nim
proc mergeList[T](a, b: var seq[T]): seq[T] = result = @[] while a.len > 0 and b.len > 0: if a[0] < b[0]: result.add a[0] a.delete 0 else: result.add b[0] b.delete 0 result.add a result.add b   proc strand[T](a: var seq[T]): seq[T] = var i = 0 result = @[a[0]] a.delete 0 ...
http://rosettacode.org/wiki/Sorting_algorithms/Strand_sort
Sorting algorithms/Strand sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#OCaml
OCaml
let rec strand_sort (cmp : 'a -> 'a -> int) : 'a list -> 'a list = function [] -> [] | x::xs -> let rec extract_strand x = function [] -> [x], [] | x1::xs when cmp x x1 <= 0 -> let strand, rest = extract_strand x1 xs in x::strand, rest | x1::xs -> let strand, rest = extract_strand x ...
http://rosettacode.org/wiki/Stable_marriage_problem
Stable marriage problem
Solve the Stable marriage problem using the Gale/Shapley algorithm. Problem description Given an equal number of men and women to be paired for marriage, each man ranks all the women in order of his preference and each woman ranks all the men in order of her preference. A stable set of engagements for marriage is o...
#Lua
Lua
local Person = {} Person.__index = Person   function Person.new(inName) local o = { name = inName, prefs = nil, fiance = nil, _candidateIndex = 1, } return setmetatable(o, Person) end   function Person:indexOf(other) for i, p in pairs(self.pr...
http://rosettacode.org/wiki/Split_a_character_string_based_on_change_of_character
Split a character string based on change of character
Task Split a (character) string into comma (plus a blank) delimited strings based on a change of character   (left to right). Show the output here   (use the 1st example below). Blanks should be treated as any other character   (except they are problematic to display clearly).   The same applies to commas. Fo...
#tbas
tbas
SUB SPLITUNIQUE$(s$) DIM c$, d$, split$, i% c$ = LEFT$(s$, 1) split$ = "" FOR i% = 1 TO LEN(s$) d$ = MID$(s$, i%, 1) IF d$ <> c$ THEN split$ = split$ + ", " c$ = d$ END IF split$ = split$ + d$ NEXT RETURN split$ END SUB   PRINT SPLITUNIQUE$("gHHH5YY++///\") END
http://rosettacode.org/wiki/Split_a_character_string_based_on_change_of_character
Split a character string based on change of character
Task Split a (character) string into comma (plus a blank) delimited strings based on a change of character   (left to right). Show the output here   (use the 1st example below). Blanks should be treated as any other character   (except they are problematic to display clearly).   The same applies to commas. Fo...
#Tcl
Tcl
set string "gHHH5YY++///\\"   regsub -all {(.)\1*} $string {\0, } string regsub {, $} $string {} string puts $string
http://rosettacode.org/wiki/Stack
Stack
Data Structure This illustrates a data structure, a means of storing data within a program. You may see other such structures in the Data Structures category. A stack is a container of elements with   last in, first out   access policy.   Sometimes it also called LIFO. The stack is accessed through its top. The ba...
#Free_Pascal
Free Pascal
program Stack; {$IFDEF FPC}{$MODE DELPHI}{$IFDEF WINDOWS}{$APPTYPE CONSOLE}{$ENDIF}{$ENDIF} {$ASSERTIONS ON} uses Generics.Collections;   var lStack: TStack<Integer>; begin lStack := TStack<Integer>.Create; try lStack.Push(1); lStack.Push(2); lStack.Push(3); Assert(lStack.Peek = 3); // 3 shoul...
http://rosettacode.org/wiki/Spiral_matrix
Spiral matrix
Task Produce a spiral array. A   spiral array   is a square arrangement of the first   N2   natural numbers,   where the numbers increase sequentially as you go around the edges of the array spiraling inwards. For example, given   5,   produce this array: 0 1 2 3 4 15 16 17 18 5 14 23 24 19 6 13 22 21 ...
#Euphoria
Euphoria
function spiral(integer dimension) integer side, curr, curr2 sequence s s = repeat(repeat(0,dimension),dimension) side = dimension curr = 0 for i = 0 to floor(dimension/2) do for j = 1 to side-1 do s[i+1][i+j] = curr -- top curr2 = curr + side-1 s[i+j]...