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/Sorting_algorithms/Pancake_sort
Sorting algorithms/Pancake 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
V tutor = 1B   F pancakesort(&data) I data.len <= 1 R I :tutor print() L(size) (data.len .< 1).step(-1) V maxindex = max(0 .< size, key' x -> @data[x]) I maxindex + 1 != size I maxindex != 0 I :tutor print(‘With: #. doflip #.’.format(data.map(x -> St...
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...
#Lingo
Lingo
str = "Hello " & QUOTE & "world!" & QUOTE put str -- "Hello "world!""
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...
#Lua
Lua
Markup : () Sequence {} List " String \ Escape for following character (* *) Comment block base^^number`s ` Context [[]] Indexed reference   Within expression: \ At end of line: Continue on next line, skipping white space
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 ...
#Eiffel
Eiffel
  class STOOGE_SORT feature stoogesort (ar: ARRAY[INTEGER]; i,j: INTEGER) -- Sorted array in ascending order. require ar_not_empty: ar.count >= 0 i_in_range: i>=1 j_in_range: j <= ar.count boundary_set: i<=j local t: REAL_64 third: INTEGER swap: INTEGER do if ar[j]< ar[i] then sw...
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 ...
#F.23
F#
  let sleepSort (values: seq<int>) = values |> Seq.map (fun x -> async { do! Async.Sleep x Console.WriteLine x }) |> Async.Parallel |> Async.Ignore |> Async.RunSynchronously  
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 ...
#Factor
Factor
  USING: threads calendar concurrency.combinators ;   : sleep-sort ( seq -- ) [ dup seconds sleep . ] parallel-each ;  
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 ...
#ARM_Assembly
ARM Assembly
  /* ARM assembly Raspberry PI */ /* program selectionSort.s */   /************************************/ /* Constantes */ /************************************/ .equ STDOUT, 1 @ Linux output console .equ EXIT, 1 @ Linux syscall .equ WRITE, 4 @ Linux syscall /********************...
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 ...
#BQN
BQN
ToUpper ← -⟜(32×1="a{"⊸⍋) Split ← ((⊢-˜+`׬)∘=⊔⊢) replace ← ⟨ "AEIOUYHW" "BFPV" "CGJKQSXZ" "DT" "L" "MN" "R" ⟩   Soundex ← ⊑∾{'0'+»⟜0‿0‿0⊑¨0⊸≠⊸/(0≠⊑)⊸↓⊑¨(¯1+·+`1»≠⟜«)⊸⊔∾/¨<˘⍉>replace∊˜¨<ToUpper 𝕩}   names ← ' ' Split "Lloyd Woolcock Donnell Baragwanath Williams Ashcroft Euler Ellery Gauss Ghosh Hilbert H...
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 ...
#C.2B.2B
C++
  #include <time.h> #include <iostream>   //-------------------------------------------------------------------------------------------------- using namespace std;   //-------------------------------------------------------------------------------------------------- const int MAX = 126; class shell { public: shell(...
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...
#NetRexx
NetRexx
/* NetRexx */ options replace format comments java crossref symbols nobinary   runSample(arg) return   -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ method sparkline(spark) private static spark = spark.changestr(',', ' ') bars = '\u2581 \u2582 \u2583 \u2584 \u2585 \u2586 \u2587 \u...
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 ...
#PicoLisp
PicoLisp
(de strandSort (Lst) (let Res NIL # Result list (while Lst (let Sub (circ (car Lst)) # Build sublist as fifo (setq Lst (filter '((X) (or (> (car Sub) X) (nil (fifo 'Sub 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 ...
#PL.2FI
PL/I
strand: procedure options (main); /* 27 Oct. 2012 */ declare A(100) fixed, used(100) bit (1), sorted fixed controlled; declare (temp, work) fixed controlled; declare (i, j, k, n) fixed binary;   n = hbound(A, 1); used = '1'b; A = random()*99;   put edit (A) (f(3));   do while (allocation(sorted)...
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...
#Phix
Phix
constant men = {"abe","bob","col","dan","ed","fred","gav","hal","ian","jon"} enum abe , bob , col , dan , ed , fred , gav , hal , ian , jon constant hen = {"abi","bea","cath","dee","eve","fay","gay","hope","ivy","jan"} enum abi , bea , cath , dee , eve , fay , gay , hope , ivy , jan -- Given a...
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...
#Haskell
Haskell
type Stack a = [a]   create :: Stack a create = []   push :: a -> Stack a -> Stack a push = (:)   pop :: Stack a -> (a, Stack a) pop [] = error "Stack empty" pop (x:xs) = (x,xs)   empty :: Stack a -> Bool empty = null   peek :: Stack a -> a peek [] = error "Stack empty" peek (x:_) = x
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 ...
#Go
Go
package main   import ( "fmt" "strconv" )   var n = 5   func main() { if n < 1 { return } top, left, bottom, right := 0, 0, n-1, n-1 sz := n * n a := make([]int, sz) i := 0 for left < right { // work right, along top for c := left; c <= right; c++ { ...
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.
#REXX
REXX
/*REXX program demonstrates REXX special variables: RC, RESULT, SIGL */ /*line two. */ /*line three.*/ say copies('═',79) rc=1/3 /*line four. */ signal youWho /*line five. */ myLoo='this got skipped' /*line six. */...
http://rosettacode.org/wiki/Sorting_algorithms/Radix_sort
Sorting algorithms/Radix 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 ...
#ATS
ATS
(* Stable integer-keyed radix sorts for unsigned and signed integers of the various typekinds.   The radix is 256. *)   (*------------------------------------------------------------------*)   #include "share/atspre_staload.hats" staload UN = "prelude/SATS/unsafe.sats"   (*----------------------------------------...
http://rosettacode.org/wiki/Sorting_algorithms/Patience_sort
Sorting algorithms/Patience 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 patience_sort(&arr) I arr.len < 2 {R}   [[T(arr[0])]] piles L(el) arr L(&pile) piles I pile.last > el pile.append(el) L.break L.was_no_break piles.append([el])   L(i) 0 .< arr.len V min = piles[0].last V minPileIndex = 0 L(j) 1 .< pil...
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 ...
#Clojure
Clojure
  (use '[clojure.contrib.combinatorics :only (permutations)])   (defn permutation-sort [s] (first (filter (partial apply <=) (permutations s))))   (permutation-sort [2 3 5 3 5])  
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 ...
#CoffeeScript
CoffeeScript
# This code takes a ridiculously inefficient algorithm and rather futilely # optimizes one part of it. Permutations are computed lazily.   sorted_copy = (a) -> # This returns a sorted copy of an array by lazily generating # permutations of indexes and stopping when the indexes yield # a sorted array. indexes =...
http://rosettacode.org/wiki/Sorting_algorithms/Pancake_sort
Sorting algorithms/Pancake 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 mergeSort64.s */   /*******************************************/ /* Constantes file */ /*******************************************/ /* for this file see task include a file in language AArch64 assembly */ .include "../includeConstantesAR...
http://rosettacode.org/wiki/Sorting_algorithms/Pancake_sort
Sorting algorithms/Pancake 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 ...
#Action.21
Action!
PROC PrintArray(INT ARRAY a INT size) INT i   Put('[) FOR i=0 TO size-1 DO IF i>0 THEN Put(' ) FI PrintI(a(i)) OD Put(']) PutE() RETURN   PROC Flip(INT ARRAY a INT last) INT i,n,tmp   n=(last-1)/2 FOR i=0 TO n DO tmp=a(i) a(i)=a(last-i) a(last-i)=tmp OD RETURN   PROC PancakeSor...
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...
#Mathematica.2FWolfram_Language
Mathematica/Wolfram Language
Markup : () Sequence {} List " String \ Escape for following character (* *) Comment block base^^number`s ` Context [[]] Indexed reference   Within expression: \ At end of line: Continue on next line, skipping white space
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...
#MBS
MBS
USER>Set S1="Hello, World!" Write S1 Hello, World! USER>Set S2=""Hello, World!"" Write S2 SET S2=""Hello, World!"" Write S2 ^ <SYNTAX> USER>Set S3="""Hello, World!"" she typed." Write S3 "Hello, World!" she typed. USER>Set S4="""""""Wow""""""" Write S4 """Wow"""
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...
#MUMPS
MUMPS
USER>Set S1="Hello, World!" Write S1 Hello, World! USER>Set S2=""Hello, World!"" Write S2 SET S2=""Hello, World!"" Write S2 ^ <SYNTAX> USER>Set S3="""Hello, World!"" she typed." Write S3 "Hello, World!" she typed. USER>Set S4="""""""Wow""""""" Write S4 """Wow"""
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 ...
#Elena
Elena
import extensions; import system'routines;   extension op { stoogeSort() = self.stoogeSort(0, self.Length - 1);   stoogeSort(IntNumber i, IntNumber j) { if(self[j]<self[i]) { self.exchange(i,j) }; if (j - i > 1) { int t := (j - i + 1) ...
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 ...
#Elixir
Elixir
defmodule Sort do def stooge_sort(list) do stooge_sort(List.to_tuple(list), 0, length(list)-1) |> Tuple.to_list end   defp stooge_sort(tuple, i, j) do if (vj = elem(tuple, j)) < (vi = elem(tuple, i)) do tuple = put_elem(tuple,i,vj) |> put_elem(j,vi) end if j - i > 1 do t = div(j - 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 ...
#Fortran
Fortran
  program sleepSort use omp_lib implicit none integer::nArgs,myid,i,stat integer,allocatable::intArg(:) character(len=5)::arg   !$omp master nArgs=command_argument_count() if(nArgs==0)stop ' : No argument is given !' allocate(intArg(nArgs)) do i=1,nArgs call get_command_a...
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 ...
#FreeBASIC
FreeBASIC
' version 21-10-2016 ' compile with: fbc -s console ' compile with: fbc -s console -exx (for bondry check on the array's) ' not very well suited for large numbers and large array's ' positive numbers only   Sub sandman(sleepy() As ULong) Dim As Long lb = LBound(sleepy) Dim As Long ub = UBound(sleepy) Dim A...
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 ...
#Arturo
Arturo
selectionSort: function [items][ sorted: new [] tmp: new items while [not? empty? tmp][ minIndex: index tmp min tmp 'sorted ++ tmp\[minIndex] remove 'tmp .index minIndex ] return sorted ]   print selectionSort [3 1 2 8 5 7 9 4 6]
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 ...
#C
C
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h>   /* for ASCII only */ static char code[128] = { 0 }; void add_code(const char *s, int c) { while (*s) { code[(int)*s] = code[0x20 ^ (int)*s] = c; s++; } }   void init() { static const char *cls[] = { "AEIOU", "", "BFPV", "CGJKQSXZ",...
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 ...
#COBOL
COBOL
******************************************************* IDENTIFICATION DIVISION. ******************************************************* PROGRAM-ID. SHELLSRT. **********************...
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...
#Nim
Nim
import rdstdin, sequtils, strutils   const bar = ["\u2581", "\u2582", "\u2583", "\u2584", "\u2585", "\u2586", "\u2587", "\u2588"] const barcount = float(bar.high)   while true: let line = readLineFromStdin "Numbers please separated by space/commas: " numbers = line.split({' ', ','}).filterIt(it.len != 0).map(...
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...
#OCaml
OCaml
let before_first_bar = 0x2580 let num_bars = 8   let sparkline numbers = let max_num = List.fold_left max 0. numbers in let scale = float_of_int num_bars /. max_num in let bars = Buffer.create num_bars in let add_bar number = let scaled = scale *. number |> Float.round |> int_of_float in if scaled <= 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 ...
#PureBasic
PureBasic
Procedure strandSort(List a()) Protected NewList subList() Protected NewList results()   While ListSize(a()) > 0 ClearList(subList()) AddElement(subList()) FirstElement(a()) subList() = a() DeleteElement(a()) ForEach a() If a() >= subList() AddElement(subList()) subLi...
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...
#PicoLisp
PicoLisp
(setq *Boys (list (de abe abi eve cath ivy jan dee fay bea hope gay) (de bob cath hope abi dee eve fay bea jan ivy gay) (de col hope eve abi dee bea fay ivy gay cath jan) (de dan ivy fay dee gay hope eve jan bea cath abi) (de ed jan dee bea cath fay eve abi ivy hope gay) (de...
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...
#Icon_and_Unicon
Icon and Unicon
procedure main() stack := [] # new empty stack push(stack,1) # add item push(stack,"hello",table(),set(),[],5) # add more items of mixed types in order left to right y := top(stack) # peek x := pop(stack) ...
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 ...
#Groovy
Groovy
enum Direction { East([0,1]), South([1,0]), West([0,-1]), North([-1,0]); private static _n private final stepDelta private bound   private Direction(delta) { stepDelta = delta }   public static setN(int n) { Direction._n = n North.bound = 0 South.bound = n-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.
#Ruby
Ruby
import scala._ // Wild card -- all of scala is imported import scala.{ Predef => _, _ } // Exception, everything except Predef def f[M[_]] // Higher kinded type parameter def f(m: M[_]) // Existential type _ + _ // Anonymous function placeholder parameter m _ // Eta expansion of me...
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.
#Scala
Scala
import scala._ // Wild card -- all of scala is imported import scala.{ Predef => _, _ } // Exception, everything except Predef def f[M[_]] // Higher kinded type parameter def f(m: M[_]) // Existential type _ + _ // Anonymous function placeholder parameter m _ // Eta expansion of me...
http://rosettacode.org/wiki/Sorting_algorithms/Radix_sort
Sorting algorithms/Radix 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
Radix_Sort(data){ loop, parse, data, `, n := StrLen(A_LoopField)>n?StrLen(A_LoopField):n loop % n { bucket := [] , i := A_Index loop, parse, data, `, bucket[SubStr(A_LoopField,1-i)] .= (bucket[SubStr(A_LoopField,1-i)]?",":"") A_LoopField data := "" for i, v in bucket data .= (data?",":"") v } return...
http://rosettacode.org/wiki/Sorting_algorithms/Patience_sort
Sorting algorithms/Patience 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 patienceSort64.s */   /*******************************************/ /* Constantes file */ /*******************************************/ /* for this file see task include a file in language AArch64 assembly */ .include "../includeConstante...
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 ...
#Common_Lisp
Common Lisp
(defun factorial (n) (loop for result = 1 then (* i result) for i from 2 to n finally (return result)))   (defun nth-permutation (k sequence) (if (zerop (length sequence)) (coerce () (type-of sequence)) (let ((seq (etypecase sequence (vector (copy-seq sequence)) ...
http://rosettacode.org/wiki/Sorting_algorithms/Pancake_sort
Sorting algorithms/Pancake 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
with Ada.Text_IO; procedure Pancake_Sort is generic type Element_Type is private; type Index_Type is range <>; type Array_Type is array (Index_Type range <>) of Element_Type; with function ">" (Left, Right : Element_Type) return Boolean is <>; procedure Pancake_Sort (Data: in out Array_Typ...
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...
#Nim
Nim
var f = open(r"C:\texts\text.txt") # a raw string, so ``\t`` is no tab
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...
#OASYS_Assembler
OASYS Assembler
; Comment (to end of line) - Introduces a negative number (not used for subtraction) = Load an include file or define a macro & Prefix for a method % Prefix for a global variable ! Prefix for an object . Prefix for a property ' Prefix for a vocabulary word ? Prefix for a class; check if an object is o...
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 ...
#Euphoria
Euphoria
function stooge(sequence s, integer i, integer j) object temp integer t if compare(s[j], s[i]) < 0 then temp = s[i] s[i] = s[j] s[j] = temp end if if j - i > 1 then t = floor((j - i + 1)/3) s = stooge(s, i , j-t) s = stooge(s, i+t, j ) s = st...
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 ...
#Go
Go
package main   import ( "fmt" "log" "os" "strconv" "time" )   func main() { out := make(chan uint64) for _, a := range os.Args[1:] { i, err := strconv.ParseUint(a, 10, 64) if err != nil { log.Fatal(err) } go func(n uint64) { time.Sleep(time.Duration(n) * time.Millisecond) out <- n }(i) } for...
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 ...
#Groovy
Groovy
  @Grab(group = 'org.codehaus.gpars', module = 'gpars', version = '1.2.1') import groovyx.gpars.GParsPool   GParsPool.withPool args.size(), { args.eachParallel { sleep(it.toInteger() * 10) println it } }  
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 ...
#AutoHotkey
AutoHotkey
MsgBox % SelecSort("") MsgBox % SelecSort("xxx") MsgBox % SelecSort("3,2,1") MsgBox % SelecSort("dog,000000,xx,cat,pile,abcde,1,cat,zz,xx,z")   SelecSort(var) { ; SORT COMMA SEPARATED LIST StringSplit a, var, `, ; make array, size = a0   Loop % a0-1 { i := A_Index, mn ...
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 ...
#C.23
C#
using System; using System.Collections.Generic; using System.Linq;   namespace Soundex { internal static class Program { private static void Main() { var testWords = new TestWords { {"Soundex", "S532"}, ...
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 ...
#Common_Lisp
Common Lisp
(defun gap-insertion-sort (array predicate gap) (let ((length (length array))) (if (< length 2) array (do ((i 1 (1+ i))) ((eql i length) array) (do ((x (aref array i)) (j i (- j gap))) ((or (< (- j gap) 0) (not (funcall predicate x (aref array (1- j))))) ...
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...
#Perl
Perl
binmode(STDOUT, ":utf8"); our @sparks=map {chr} 0x2581 .. 0x2588; sub sparkline(@) { my @n=map {0+$_} grep {length} @_ or return ""; my($min,$max)=($n[0])x2; if (@n>1) { for (@n[1..$#n]) { if ($_<$min) { $min=$_ } elsif ($_>$max) { $max=$_ } } } my $sparkli...
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 ...
#Python
Python
def merge_list(a, b): out = [] while len(a) and len(b): if a[0] < b[0]: out.append(a.pop(0)) else: out.append(b.pop(0)) out += a out += b return out   def strand(a): i, s = 0, [a.pop(0)] while i < len(a): if a[i] > s[-1]: s.append(a.pop(i)) else: i += 1 return s   def strand_sort(a): out = ...
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...
#Prolog
Prolog
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % facts prefere(abe,[ abi, eve, cath, ivy, jan, dee, fay, bea, hope, gay]). prefere( bob,[ cath, hope, abi, dee, eve, fay, bea, jan, ivy, gay]). prefere( col,[ hope, eve, abi, dee, bea, fay, ivy, gay, cath, jan]). prefere( dan,[ ivy, fay, dee, gay, hope, eve...
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...
#Io
Io
Node := Object clone do( next := nil obj := nil )   Stack := Object clone do( node := nil   pop := method( obj := node obj node = node next obj )   push := method(obj, nn := Node clone nn obj = obj nn next = self node self node = nn ) )
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 ...
#Haskell
Haskell
import Data.List import Control.Monad grade xs = map snd. sort $ zip xs [0..] values n = cycle [1,n,-1,-n] counts n = (n:).concatMap (ap (:) return) $ [n-1,n-2..1] reshape n = unfoldr (\xs -> if null xs then Nothing else Just (splitAt n xs)) spiral n = reshape n . grade. scanl1 (+). concat $ zipWith replicate (counts ...
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.
#Smalltalk
Smalltalk
Smalltalk keys
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.
#Tcl
Tcl
# contains arguments passed to the ursa # interpreter on the command line string<> args   # iodevice that points to the console by default iodevice console   # contains "\n" string endl   # represents false boolean false   # represents true boolean true
http://rosettacode.org/wiki/Sorting_algorithms/Radix_sort
Sorting algorithms/Radix 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 ...
#B4X
B4X
Sub RadixSort (Old() As Int) Dim i, j As Int Dim tmp(Old.Length) As Int For shift = 31 To 0 Step - 1 j = 0 For i = 0 To Old.Length - 1 Dim move As Boolean = Bit.ShiftLeft(Old(i), shift) >= 0 If (shift = 0 And move = False) Or (shift <> 0 And move) Then Old(i - j) = Old(i) Else tmp(j) = Old(i) ...
http://rosettacode.org/wiki/Sorting_algorithms/Radix_sort
Sorting algorithms/Radix 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 PROCradixsort(test%(), 10, 10) FOR i% = 0 TO 9 PRINT test%(i%) ; NEXT PRINT END   DEF PROCradixsort(a%(), n%, r%) LOCAL d%, e%, i%, l%, m%, b%(), bucket%() DIM b%(n%-1), bucket%(r%-1) FOR...
http://rosettacode.org/wiki/Sorting_algorithms/Quicksort
Sorting algorithms/Quicksort
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 _quicksort(&array, start, stop) -> N I stop - start > 0 V pivot = array[start] V left = start V right = stop L left <= right L array[left] < pivot left++ L array[right] > pivot right-- I left <= right swap(&array[left], &array[r...
http://rosettacode.org/wiki/Sorting_algorithms/Patience_sort
Sorting algorithms/Patience 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
----------------------------------------------------------------------   with Ada.Text_IO;   procedure patience_sort_task is use Ada.Text_IO;   function next_power_of_two (n : in Natural) return Positive is -- This need not be a fast implementation. pow2 : Positive; begin pow2 := 1; while p...
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 ...
#Crystal
Crystal
def sorted?(items : Array) prev = items[0] items.each do |item| if item < prev return false end prev = item end return true end   def permutation_sort(items : Array) items.each_permutation do |permutation| if sorted?(permutation) return permuta...
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 ...
#D
D
import std.stdio, std.algorithm, permutations2;   void permutationSort(T)(T[] items) pure nothrow @safe @nogc { foreach (const perm; items.permutations!false) if (perm.isSorted) break; }   void main() { auto data = [2, 7, 4, 3, 5, 1, 0, 9, 8, 6, -1]; data.permutationSort; data.writel...
http://rosettacode.org/wiki/Sorting_algorithms/Pancake_sort
Sorting algorithms/Pancake 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
PROC flip = ([]INT s, INT n) []INT: BEGIN [UPB s]INT ss := s; INT temp; FOR i TO n OVER 2 DO temp := ss[i]; ss[i] := ss[n-i+1]; ss[n-i+1] := temp OD; ss END;   PROC pancake sort = ([]INT s) []INT: BEGIN INT m; [UPB s]INT ss := s; FOR i...
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...
#Objeck
Objeck
  \b //Backspace \n //Line Feed \r //Carriage Return \t //Tab \0 //Null \' //Single Quote \" //Double Q
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...
#OCaml
OCaml
\\ backslash \" double quote \' single quote \n line feed \r carriage return \t tab \b backspace \ (backslash followed by a space) space \DDD where D is a decimal digit; the character with code DDD in decimal \xHH where H is a hex digit; the character with code HH in hex
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 ...
#Factor
Factor
USING: kernel locals math prettyprint sequences ; IN: rosetta-code.stooge-sort   <PRIVATE   :: (stooge-sort) ( seq i j -- ) j i [ seq nth ] bi@ < [ j i seq exchange ] when j i - 1 > [ j i - 1 + 3 /i :> t seq i j t - (stooge-sort) seq i t + j (stooge-sort) seq i j t - ...
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 ...
#Fortran
Fortran
program Stooge implicit none   integer :: i integer :: array(50) = (/ (i, i = 50, 1, -1) /) ! Reverse sorted array   call Stoogesort(array) write(*,"(10i5)") array   contains   recursive subroutine Stoogesort(a) integer, intent(in out) :: a(:) integer :: j, t, temp   j = size(a) if(a(j) < a(1)) then...
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 ...
#Haskell
Haskell
import System.Environment import Control.Concurrent import Control.Monad   sleepSort :: [Int] -> IO () sleepSort values = do chan <- newChan forM_ values (\time -> forkIO (threadDelay (50000 * time) >> writeChan chan time)) forM_ values (\_ -> readChan chan >>= print)   main :: IO () main = getA...
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 ...
#Icon_and_Unicon
Icon and Unicon
procedure main(A) every insert(t:=set(),mkThread(t,!A)) every spawn(!t) # start threads as closely grouped as possible while (*t > 0) do write(<<@) end   procedure mkThread(t,n) # 10ms delay scale factor return create (delay(n*10),delete(t,&current),n@>&main) end
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 ...
#AWK
AWK
function getminindex(gl, gi, gs) { min = gl[gi] gm = gi for(gj=gi; gj <= gs; gj++) { if ( gl[gj] < min ) { min = gl[gj] gm = gj } } return gm }   { line[NR] = $0 } END { # sort it with selection sort for(i=1; i <= NR; i++) { mi = getminindex(line, i, NR) t = line[i] line[i]...
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 ...
#C.2B.2B
C++
  #include <iostream> // required for debug code in main() only #include <iomanip> // required for debug code in main() only #include <string>   std::string soundex( char const* s ) { static char const code[] = { 0, -1, 1, 2, 3, -1, 1, 2, 0, -1, 2, 2, 4, 5, 5, -1, 1, 2, 6, 2, 3, -1, 1, 0, 2, 0,...
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 ...
#D
D
import std.stdio: writeln;   void shellSort(T)(T[] seq) pure nothrow { int inc = seq.length / 2; while (inc) { foreach (ref i, el; seq) { while (i >= inc && seq[i - inc] > el) { seq[i] = seq[i - inc]; i -= inc; } seq[i] = el; } ...
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...
#Phix
Phix
with javascript_semantics requires("1.0.2") -- (a fix for JS) include builtins\unicode_console.e constant tests = {"0 1 19 20", "0 0 1 1", "0 999 4000 4999 7000 7999", "1 1 2 2 3 3", "1 2 3 4 5 6 7 8 7 6 5 4 3 2 1", "1.5, 0.5 3.5, 2.5 5.5, 4.5 7.5, 6.5"} for i=1...
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 ...
#Racket
Racket
  #lang racket (require mzlib/list) (define (merge xs ys) (merge-sorted-lists xs ys <=))   (define (strand-sort xs) (let loop ([xs xs] [ys '[]]) (cond [(empty? xs) ys] [else (define-values (sorted unsorted) (extract-strand xs)) (loop unsorted (merge sorted ys))])))   (define (extract-str...
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 ...
#Raku
Raku
sub infix:<M> (@x-in, @y-in) { my @x = | @x-in; my @y = | @y-in; flat @x, @y, reverse gather while @x and @y { take do given @x[*-1] cmp @y[*-1] { when More { pop @x } when Less { pop @y } when Same { pop(@x), pop(@y) } } ...
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...
#PureBasic
PureBasic
#coupleCount = 10   DataSection ;guys Data.s "abe: abi, eve, cath, ivy, jan, dee, fay, bea, hope, gay" Data.s "bob: cath, hope, abi, dee, eve, fay, bea, jan, ivy, gay" Data.s "col: hope, eve, abi, dee, bea, fay, ivy, gay, cath, jan" Data.s "dan: ivy, fay, dee, gay, hope, eve, jan, bea, cath, abi" Data.s "ed...
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...
#Ioke
Ioke
Stack = Origin mimic do( initialize = method(@elements = []) pop = method(@elements pop!) empty = method(@elements empty?) push = method(element, @elements push!(element)) )
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 ...
#Icon_and_Unicon
Icon and Unicon
procedure main(A) # spiral matrix N := 0 < integer(\A[1]|5) # N=1... (dfeault 5) WriteMatrix(SpiralMatrix(N)) end   procedure WriteMatrix(M) #: write the matrix every x := M[r := 1 to *M, c := 1 to *M[r]] do writes(right(\x|"-", 3), if c = *M[r] then "\n" else "") return end   procedure ...
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.
#UNIX_Shell
UNIX Shell
# contains arguments passed to the ursa # interpreter on the command line string<> args   # iodevice that points to the console by default iodevice console   # contains "\n" string endl   # represents false boolean false   # represents true boolean true
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.
#Ursa
Ursa
# contains arguments passed to the ursa # interpreter on the command line string<> args   # iodevice that points to the console by default iodevice console   # contains "\n" string endl   # represents false boolean false   # represents true boolean true
http://rosettacode.org/wiki/Sorting_algorithms/Radix_sort
Sorting algorithms/Radix 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> #include <limits.h> #include <stdlib.h> #include <time.h>   // Get size of statically allocated array #define ARR_LEN(ARR) (sizeof ARR / sizeof *ARR) // Generate random number in the interval [M,N] #define RAND_RNG(M,N) (M + rand() / (RAND_MAX / (N - M + 1) + 1));   static void swap(unsigned *a, unsi...
http://rosettacode.org/wiki/Sorting_algorithms/Quicksort
Sorting algorithms/Quicksort
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
* Quicksort 14/09/2015 & 23/06/2016 QUICKSOR CSECT USING QUICKSOR,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/Sorting_algorithms/Patience_sort
Sorting algorithms/Patience 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 patience sort. on patienceSort(theList, l, r) -- Sort items l thru r of theList. set listLen to (count theList) if (listLen < 2) then return -- Convert any negative and/or transposed range indices. if (l < 0) then set l to listLen + l + 1 if (r < 0) then set r to listLen + r + 1 if (...
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 ...
#E
E
def swap(container, ixA, ixB) { def temp := container[ixA] container[ixA] := container[ixB] container[ixB] := temp }   /** Reverse order of elements of 'sequence' whose indexes are in the interval [ixLow, ixHigh] */ def reverseRange(sequence, var ixLow, var ixHigh) { while (ixLow < ixHigh) { swa...
http://rosettacode.org/wiki/Sorting_algorithms/Pancake_sort
Sorting algorithms/Pancake 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
on pancake_sort(aList) script o property lst : aList property len : (count my lst)   on flip(n) if (n < len) then set my lst to (reverse of items 1 thru n of my lst) & (items (n + 1) thru len of my lst) else set my lst to reverse of my ...
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...
#Ol
Ol
#[]\(){}',|` () List []{} Reserved for feature use #\ Character constant ' Quote ` Backquote , Unquote | Used by code blocks (like multiline comment, symbol name container)
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...
#PARI.2FGP
PARI/GP
is square(9)
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 ...
#FreeBASIC
FreeBASIC
' version 23-10-2016 ' compile with: fbc -s console   Sub stoogesort(s() As Long, l As Long, r As Long)   If s(r) < s(l) Then Swap s(r), s(l) End If   If r - l > 1 Then Var t = (r - l +1) \ 3 stoogesort(s(), l , r - t) stoogesort(s(), l + t, r ) stoogesort(s(), ...
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 ...
#J
J
scheduledumb=: {{ id=:'dumb',":x:6!:9'' wd 'pc ',id (t)=: u {{u y[erase n}} t=. id,'_timer' wd 'ptimer ',":n p.y }}     ssort=: {{ R=: '' poly=. 1,>./ y poly{{ y{{R=:R,m[y}}scheduledumb m y}}"0 y {{echo R}} scheduledumb poly"0 >:>./ y EMPTY }}
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 ...
#Java
Java
import java.util.concurrent.CountDownLatch;   public class SleepSort { public static void sleepSortAndPrint(int[] nums) { final CountDownLatch doneSignal = new CountDownLatch(nums.length); for (final int num : nums) { new Thread(new Runnable() { public void run() { doneSignal.countDown(); try { ...
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 ...
#BBC_BASIC
BBC BASIC
DEF PROC_SelectionSort(Size%) FOR I% = 1 TO Size%-1 lowest% = I% FOR J% = (I% + 1) TO Size% IF data%(J%) < data%(lowest%) lowest% = J% NEXT J% IF I%<>lowest% SWAP data%(I%),data%(lowest%) NEXT I% ENDPROC
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 ...
#Cach.C3.A9_ObjectScript
Caché ObjectScript
  Class Utils.Phonetic [ Abstract ] {   ClassMethod ToSoundex(String As %String) As %String [ Language = mvbasic ] { Return Soundex(String) }   }  
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 ...
#Dart
Dart
  void main() { List<int> a = shellSort([1100, 2, 56, 200, -52, 3, 99, 33, 177, -199]); print('$a'); }   shellSort(List<int> array) { int n = array.length;   // Start with a big gap, then reduce the gap for (int gap = n~/2; gap > 0; gap ~/= 2) { // Do a gapped insertion sort...
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 ...
#Delphi
Delphi
Procedure ShellSort(var buf:Array of Integer); const gaps:array[0..7] of Integer = (701, 301, 132, 57, 23, 10, 4, 1);   var whichGap, i, j, n, gap, temp : Integer;   begin n := high(buf); for whichGap := 0 to high(gaps) do begin gap := gaps[whichGap]; for i := gap to n do begin temp := buf[i];   ...
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...
#PicoLisp
PicoLisp
(de sparkLine (Lst) (let (Min (apply min Lst) Max (apply max Lst) Rng (- Max Min)) (for N Lst (prin (char (+ 9601 (*/ (- N Min) 7 Rng)) ) ) ) (prinl) ) )
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...
#Python
Python
# -*- coding: utf-8 -*-   # Unicode: 9601, 9602, 9603, 9604, 9605, 9606, 9607, 9608 bar = '▁▂▃▄▅▆▇█' barcount = len(bar)   def sparkline(numbers): mn, mx = min(numbers), max(numbers) extent = mx - mn sparkline = ''.join(bar[min([barcount - 1, int((n - mn) / extent * barcount...
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 ...
#REXX
REXX
/*REXX program sorts a random list of words (or numbers) using the strand sort algorithm*/ parse arg size minv maxv old /*obtain optional arguments from the CL*/ if size=='' | size=="," then size=20 /*Not specified? Then use the default.*/ if minv=='' | minv=="," then minv= 0 ...