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/Cocktail_sort
Sorting algorithms/Cocktail 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 ...
#Run_BASIC
Run BASIC
for i = 1 to 100 ' fill array a(i) = rnd(0) * 100 next i ' ------- sort ------- beg = 2 siz = 100 whatWay = 1 changed = 1 while changed changed = 0 FOR i = beg TO siz STEP whatWay IF a(i-1) > a(i) THEN hold = a(i) a(i) = a(i-1) a(i-1) = hold changed = i end if NEXT i siz = b...
http://rosettacode.org/wiki/Sockets
Sockets
For this exercise a program is open a socket to localhost on port 256 and send the message "hello socket world" before closing the socket. Catching any exceptions or errors is not required.
#Pike
Pike
import Stdio;   int main(){ object con = File(); con->connect("127.0.0.1",256); con->write("hello socket world"); con->close(); }
http://rosettacode.org/wiki/Sockets
Sockets
For this exercise a program is open a socket to localhost on port 256 and send the message "hello socket world" before closing the socket. Catching any exceptions or errors is not required.
#Prolog
Prolog
start(Port) :- socket('AF_INET',Socket), socket_connect(Socket, 'AF_INET'(localhost,Port), Input, Output), write(Output, 'hello socket world'), flush_output(Output), close(Output), close(Input).
http://rosettacode.org/wiki/Snake
Snake
This page uses content from Wikipedia. The original article was at Snake_(video_game). The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) Snake is a game where the player maneuvers a line which grows i...
#Rust
Rust
/* add to file Cargo.toml: [dependencies] winsafe = "0.0.8" rand = "0.8.4" */   #![windows_subsystem = "windows"]   use rand::Rng; use std::{cell::RefCell, rc::Rc}; use winsafe::{co, gui, prelude::*, COLORREF, HBRUSH, HPEN, SIZE};   const STEP: i32 = 3; // px, motion per frame. STEP and FPS determine the smoothness and...
http://rosettacode.org/wiki/Smith_numbers
Smith numbers
Smith numbers are numbers such that the sum of the decimal digits of the integers that make up that number is the same as the sum of the decimal digits of its prime factors excluding 1. By definition, all primes are excluded as they (naturally) satisfy this condition! Smith numbers are also known as   joke   numbers....
#JavaScript
JavaScript
(() => { 'use strict';   // isSmith :: Int -> Bool const isSmith = n => { const pfs = primeFactors(n); return (1 < pfs.length || n !== pfs[0]) && ( sumDigits(n) === pfs.reduce( (a, x) => a + sumDigits(x), 0 ) ); };   // ...
http://rosettacode.org/wiki/Solve_a_Hidato_puzzle
Solve a Hidato puzzle
The task is to write a program which solves Hidato (aka Hidoku) puzzles. The rules are: You are given a grid with some numbers placed in it. The other squares in the grid will be blank. The grid is not necessarily rectangular. The grid may have holes in it. The grid is always connected. The number “1” is always ...
#Python
Python
board = [] given = [] start = None   def setup(s): global board, given, start lines = s.splitlines() ncols = len(lines[0].split()) nrows = len(lines) board = [[-1] * (ncols + 2) for _ in xrange(nrows + 2)]   for r, row in enumerate(lines): for c, cell in enumerate(row.split()): ...
http://rosettacode.org/wiki/Sort_an_array_of_composite_structures
Sort an array of composite structures
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 ...
#ooRexx
ooRexx
  a = .array~new   a~append(.pair~new("06-07", "Ducks")) a~append(.pair~new("00-01", "Avalanche")) a~append(.pair~new("02-03", "Devils")) a~append(.pair~new("01-02", "Red Wings")) a~append(.pair~new("03-04", "Lightning")) a~append(.pair~new("04-05", "lockout")) a~append(.pair~new("05-06", "Hurricanes")) a~append(.pair~...
http://rosettacode.org/wiki/Sort_an_integer_array
Sort an integer array
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 ...
#Nanoquery
Nanoquery
% import sort % println sort({2,4,3,1,2}) [1, 2, 2, 3, 4]
http://rosettacode.org/wiki/Sort_an_integer_array
Sort an integer array
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 ...
#Neko
Neko
/** <doc><h2>Sort integer array, in Neko</h2> <p>Array sort function modified from Haxe codegen with -D neko-source</p> <p>The Neko target emits support code for Haxe basics, sort is included</p> <p>Tectonics:<br />prompt$ nekoc sort.neko<br />prompt$ neko sort</p> </doc> **/   var sort = function(a) { v...
http://rosettacode.org/wiki/Sort_disjoint_sublist
Sort disjoint sublist
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 ...
#Scala
Scala
import scala.compat.Platform   object SortedDisjointSubList extends App { val (list, subListIndex) = (List(7, 6, 5, 4, 3, 2, 1, 0), List(6, 1, 7))   def sortSubList[T: Ordering](indexList: List[Int], list: List[T]) = { val subListIndex = indexList.sorted val sortedSubListMap = subListIndex.zip(subListIndex....
http://rosettacode.org/wiki/Sort_using_a_custom_comparator
Sort using a custom comparator
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 ...
#Tcl
Tcl
proc sorter {a b} { set la [string length $a] set lb [string length $b] if {$la < $lb} { return 1 } elseif {$la > $lb} { return -1 } return [string compare [string tolower $a] [string tolower $b]] }   set strings {here are Some sample strings to be sorted} lsort -command sorter $...
http://rosettacode.org/wiki/Sorting_algorithms/Bubble_sort
Sorting algorithms/Bubble 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 ...
#Liberty_BASIC
Liberty BASIC
  itemCount = 20 dim item(itemCount) for i = 1 to itemCount item(i) = int(rnd(1) * 100) next i print "Before Sort" for i = 1 to itemCount print item(i) next i print: print counter = itemCount do hasChanged = 0 for i = 1 to counter - 1 i...
http://rosettacode.org/wiki/Sorting_algorithms/Gnome_sort
Sorting algorithms/Gnome 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 ...
#Smalltalk
Smalltalk
Smalltalk at: #gnomesort put: nil.   "Utility" OrderedCollection extend [ swap: a with: b [ |t| t := self at: a. self at: a put: b. self at: b put: t ] ].   "Gnome sort as block closure" gnomesort := [ :c | |i j| i := 2. j := 3. [ i <= (c size) ] whileTrue: [ (c at: (i-1)) <= (c a...
http://rosettacode.org/wiki/Sorting_algorithms/Cocktail_sort
Sorting algorithms/Cocktail 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 ...
#Rust
Rust
fn cocktail_sort<T: PartialOrd>(a: &mut [T]) { let len = a.len(); loop { let mut swapped = false; let mut i = 0; while i + 1 < len { if a[i] > a[i + 1] { a.swap(i, i + 1); swapped = true; } i += 1; } if s...
http://rosettacode.org/wiki/Sockets
Sockets
For this exercise a program is open a socket to localhost on port 256 and send the message "hello socket world" before closing the socket. Catching any exceptions or errors is not required.
#PureBasic
PureBasic
InitNetwork() ConnectionID = OpenNetworkConnection("localhost", 256) SendNetworkString(ConnectionID, "hello socket world") CloseNetworkConnection(ConnectionID)
http://rosettacode.org/wiki/Sockets
Sockets
For this exercise a program is open a socket to localhost on port 256 and send the message "hello socket world" before closing the socket. Catching any exceptions or errors is not required.
#Python
Python
import socket sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect(("localhost", 256)) sock.sendall("hello socket world") sock.close()
http://rosettacode.org/wiki/Snake
Snake
This page uses content from Wikipedia. The original article was at Snake_(video_game). The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) Snake is a game where the player maneuvers a line which grows i...
#Sidef
Sidef
class SnakeGame(w, h) { const readkey = frequire('Term::ReadKey') const ansi = frequire('Term::ANSIColor')   enum (VOID, HEAD, BODY, TAIL, FOOD)   define ( LEFT = [+0, -1], RIGHT = [+0, +1], UP = [-1, +0], DOWN = [+1, +0], )   define BG_COLOR = "on_blac...
http://rosettacode.org/wiki/Smith_numbers
Smith numbers
Smith numbers are numbers such that the sum of the decimal digits of the integers that make up that number is the same as the sum of the decimal digits of its prime factors excluding 1. By definition, all primes are excluded as they (naturally) satisfy this condition! Smith numbers are also known as   joke   numbers....
#jq
jq
def is_prime: . as $n | if ($n < 2) then false elif ($n % 2 == 0) then $n == 2 elif ($n % 3 == 0) then $n == 3 elif ($n % 5 == 0) then $n == 5 elif ($n % 7 == 0) then $n == 7 elif ($n % 11 == 0) then $n == 11 elif ($n % 13 == 0) then $n == 13 elif ($n % 17 == 0) then $n == 17...
http://rosettacode.org/wiki/Smith_numbers
Smith numbers
Smith numbers are numbers such that the sum of the decimal digits of the integers that make up that number is the same as the sum of the decimal digits of its prime factors excluding 1. By definition, all primes are excluded as they (naturally) satisfy this condition! Smith numbers are also known as   joke   numbers....
#Julia
Julia
# v0.6   function sumdigits(n::Integer) sum = 0 while n > 0 sum += n % 10 n = div(n, 10) end return sum end   using Primes issmith(n::Integer) = !isprime(n) && sumdigits(n) == sum(sumdigits(f) for f in factor(Vector, n))   smithnumbers = collect(n for n in 2:10000 if issmith(n)) println(...
http://rosettacode.org/wiki/Solve_a_Hidato_puzzle
Solve a Hidato puzzle
The task is to write a program which solves Hidato (aka Hidoku) puzzles. The rules are: You are given a grid with some numbers placed in it. The other squares in the grid will be blank. The grid is not necessarily rectangular. The grid may have holes in it. The grid is always connected. The number “1” is always ...
#Racket
Racket
  #lang racket (require math/array)   ;#f = not a legal position, #t = blank position (define board (array #[#[#t 33 35 #t #t #f #f #f] #[#t #t 24 22 #t #f #f #f] #[#t #t #t 21 #t #t #f #f] #[#t 26 #t 13 40 11 #f #f] #[27 #t #t #t 9 #t 1 #f] #[#f #f #t #t 18 #t #t #f] #[#f #f #f #f ...
http://rosettacode.org/wiki/Sort_an_array_of_composite_structures
Sort an array of composite structures
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 ...
#Oz
Oz
declare People = [person(name:joe value:3) person(name:bill value:4) person(name:alice value:20) person(name:harry value:3)]   SortedPeople = {Sort People fun {$ P1 P2} P1.name < P2.name end } in {ForAll ...
http://rosettacode.org/wiki/Sort_an_array_of_composite_structures
Sort an array of composite structures
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 ...
#PARI.2FGP
PARI/GP
vecsort([["name", "value"],["name2", "value2"]], 1, 2)
http://rosettacode.org/wiki/Sort_an_integer_array
Sort an integer array
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 ...
#Nemerle
Nemerle
using System.Console;   module IntSort { Main() : void { def nums = [1, 5, 3, 7, 2, 8, 3, 9]; def sorted = nums.Sort((x, y) => x.CompareTo(y));   WriteLine(nums); WriteLine(sorted); } }
http://rosettacode.org/wiki/Sort_an_integer_array
Sort an integer array
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   ia = int[] ia = [ 2, 4, 3, 1, 2, -1, 0, -2 ]   display(ia) Arrays.sort(ia) display(ia)   -- Display results method display(in = int[]) public static   sorted = Rexx('')   loop ix = 0 for in.length sorted = sorted || Rexx(in[ix]...
http://rosettacode.org/wiki/Sort_disjoint_sublist
Sort disjoint sublist
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 ...
#Scheme
Scheme
(use gauche.sequence) (define num-list '(7 6 5 4 3 2 1 0)) (define indices '(6 1 7)) (define table (alist->hash-table (map cons (sort indices) (sort indices < (lambda (x) (~ num-list x))))))   (map last (sort (map-with-index (lambda (i x) (list (hash-table-get table i i) x)) num-lis...
http://rosettacode.org/wiki/Sort_using_a_custom_comparator
Sort using a custom comparator
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 ...
#TUSCRIPT
TUSCRIPT
  $$ MODE TUSCRIPT setofstrings="this is a set of strings to sort This Is A Set Of Strings To Sort" unsorted=SPLIT (setofstrings,": :") PRINT "1. setofstrings unsorted" index="" LOOP l=unsorted PRINT l length=LENGTH (l),index=APPEND(index,length) ENDLOOP index =DIGIT_INDEX (index) sorted=INDEX_SORT (unsorted,index) PRI...
http://rosettacode.org/wiki/Sort_using_a_custom_comparator
Sort using a custom comparator
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 ...
#Ursala
Ursala
#import std #show+   data = <'this','is','a','list','of','strings','to','be','sorted'>   example = psort<not leql,lleq+ ~* ~&K31K30piK26 letters> data
http://rosettacode.org/wiki/Sorting_algorithms/Bubble_sort
Sorting algorithms/Bubble 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 ...
#Lisaac
Lisaac
Section Header   + name := BUBBLE_SORT;   - external := `#include <time.h>`;   Section Public   - main <- ( + a : ARRAY(INTEGER);   a := ARRAY(INTEGER).create 0 to 100; `srand(time(NULL))`; 0.to 100 do { i : INTEGER; a.put `rand()`:INTEGER to i; };   bubble a;   a.foreach { item : INTEGER; item.pr...
http://rosettacode.org/wiki/Sorting_algorithms/Gnome_sort
Sorting algorithms/Gnome 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 ...
#SNOBOL4
SNOBOL4
*** GNOME SORT ***************************************************************** * GNOME(V) -- gnome sort of the numerical vector V. *** HELPER FUNCTIONS *********************************************************** * IDXMAX(V) -- highest index of vector V. * IDXMIN(V) -- lowest index of vector V. * NUMBER(V) --...
http://rosettacode.org/wiki/Sorting_algorithms/Cocktail_sort
Sorting algorithms/Cocktail 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 ...
#Scala
Scala
object CocktailSort extends App { def sort(arr: Array[Int]) = { var swapped = false do { def swap(i: Int) { val temp = arr(i) arr(i) = arr(i + 1) arr(i + 1) = temp swapped = true }   swapped = false for (i <- 0 to (arr.length - 2)) if (arr(i) > arr(i + 1...
http://rosettacode.org/wiki/Sockets
Sockets
For this exercise a program is open a socket to localhost on port 256 and send the message "hello socket world" before closing the socket. Catching any exceptions or errors is not required.
#R
R
  s <- make.socket(port = 256) write.socket(s, "hello socket world") close.socket(s)  
http://rosettacode.org/wiki/Sockets
Sockets
For this exercise a program is open a socket to localhost on port 256 and send the message "hello socket world" before closing the socket. Catching any exceptions or errors is not required.
#Racket
Racket
#lang racket (let-values ([(in out) (tcp-connect "localhost" 256)]) (display "hello socket world\n" out) (close-output-port out))
http://rosettacode.org/wiki/Snake
Snake
This page uses content from Wikipedia. The original article was at Snake_(video_game). The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) Snake is a game where the player maneuvers a line which grows i...
#Wren
Wren
/* snake.wren */   import "random" for Random import "./dynamic" for Enum, Lower   foreign class Window { construct initscr() {}   foreign nodelay(bf) }   class Ncurses { foreign static cbreak()   foreign static noecho()   foreign static refresh()   foreign static getch()   foreign static mv...
http://rosettacode.org/wiki/Smith_numbers
Smith numbers
Smith numbers are numbers such that the sum of the decimal digits of the integers that make up that number is the same as the sum of the decimal digits of its prime factors excluding 1. By definition, all primes are excluded as they (naturally) satisfy this condition! Smith numbers are also known as   joke   numbers....
#Kotlin
Kotlin
// version 1.0.6   fun getPrimeFactors(n: Int): MutableList<Int> { val factors = mutableListOf<Int>() if (n < 2) return factors var factor = 2 var nn = n while (true) { if (nn % factor == 0) { factors.add(factor) nn /= factor if (nn == 1) return factors ...
http://rosettacode.org/wiki/Solve_a_Hidato_puzzle
Solve a Hidato puzzle
The task is to write a program which solves Hidato (aka Hidoku) puzzles. The rules are: You are given a grid with some numbers placed in it. The other squares in the grid will be blank. The grid is not necessarily rectangular. The grid may have holes in it. The grid is always connected. The number “1” is always ...
#Raku
Raku
my @adjacent = [-1, -1], [-1, 0], [-1, 1], [ 0, -1], [ 0, 1], [ 1, -1], [ 1, 0], [ 1, 1];   solveboard q:to/END/; __ 33 35 __ __ .. .. .. __ __ 24 22 __ .. .. .. __ __ __ 21 __ __ .. .. __ 26 __ 13 40 11 .. .. 27 __ __ __ 9 __ 1 .. ...
http://rosettacode.org/wiki/Sort_an_array_of_composite_structures
Sort an array of composite structures
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 ...
#Pascal
Pascal
@people = (['joe', 120], ['foo', 31], ['bar', 51]); @people = sort { $a->[0] cmp $b->[0] } @people;
http://rosettacode.org/wiki/Sort_an_integer_array
Sort an integer array
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 ...
#Nial
Nial
sort >= 9 6 8 7 1 10 = 10 9 8 7 6 1
http://rosettacode.org/wiki/Sort_an_integer_array
Sort an integer array
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
import algorithm   var a: array[0..8, int] = [2, 3, 5, 8, 4, 1, 6, 9, 7] a.sort(Ascending) for x in a: echo x
http://rosettacode.org/wiki/Sort_disjoint_sublist
Sort disjoint sublist
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 ...
#Sidef
Sidef
func disjointSort(values, indices) { values[indices.sort] = [values[indices]].sort... }   var values = [7, 6, 5, 4, 3, 2, 1, 0]; var indices = [6, 1, 7];   disjointSort(values, indices); say values;
http://rosettacode.org/wiki/Sort_using_a_custom_comparator
Sort using a custom comparator
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 ...
#Visual_Basic_.NET
Visual Basic .NET
Imports System   Module Sorting_Using_a_Custom_Comparator Function CustomComparator(ByVal x As String, ByVal y As String) As Integer Dim result As Integer result = y.Length - x.Length If result = 0 Then result = String.Compare(x, y, True) End If Return result ...
http://rosettacode.org/wiki/Sorting_algorithms/Bubble_sort
Sorting algorithms/Bubble 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 ...
#Lua
Lua
  function bubbleSort(A) local itemCount=#A local hasChanged repeat hasChanged = false itemCount=itemCount - 1 for i = 1, itemCount do if A[i] > A[i + 1] then A[i], A[i + 1] = A[i + 1], A[i] hasChanged = true end end until hasChanged == false end  
http://rosettacode.org/wiki/Sorting_algorithms/Gnome_sort
Sorting algorithms/Gnome 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 ...
#Swift
Swift
func gnomeSort<T: Comparable>(_ a: inout [T]) { var i = 1 var j = 2 while i < a.count { if a[i - 1] <= a[i] { i = j j += 1 } else { a.swapAt(i - 1, i) i -= 1 if i == 0 { i = j j += 1 } ...
http://rosettacode.org/wiki/Sorting_algorithms/Cocktail_sort
Sorting algorithms/Cocktail 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 ...
#Scilab
Scilab
function varargout=cocktailSort(list_in) swapped = %T; while swapped swapped = %F; for i = [1:length(list_in)-1] if list_in(i) > list_in(i+1) then list_in([i i+1])=list_in([i+1 i]); swapped = %T; end end if ~swapped ...
http://rosettacode.org/wiki/Sockets
Sockets
For this exercise a program is open a socket to localhost on port 256 and send the message "hello socket world" before closing the socket. Catching any exceptions or errors is not required.
#Raku
Raku
my $host = '127.0.0.1'; my $port = 256;   my $client = IO::Socket::INET.new(:$host, :$port); $client.print( 'hello socket world' ); $client.close;
http://rosettacode.org/wiki/Sockets
Sockets
For this exercise a program is open a socket to localhost on port 256 and send the message "hello socket world" before closing the socket. Catching any exceptions or errors is not required.
#Rhope
Rhope
Socket Send(0,0) |: [New@Net Client["localhost",256]]Put String["hello socket world"] :|
http://rosettacode.org/wiki/Snake
Snake
This page uses content from Wikipedia. The original article was at Snake_(video_game). The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance) Snake is a game where the player maneuvers a line which grows i...
#XPL0
XPL0
def Width=40, Height=25-1, \playing area including border StartLength = 10, \starting length of snake including head Morsels = 10; \number of food items constantly offered int Heading; \direction snake is heading def Up, Down, L...
http://rosettacode.org/wiki/Smith_numbers
Smith numbers
Smith numbers are numbers such that the sum of the decimal digits of the integers that make up that number is the same as the sum of the decimal digits of its prime factors excluding 1. By definition, all primes are excluded as they (naturally) satisfy this condition! Smith numbers are also known as   joke   numbers....
#Lua
Lua
-- Returns a boolean indicating whether n is prime function isPrime (n) if n < 2 then return false end if n < 4 then return true end if n % 2 == 0 then return false end for d = 3, math.sqrt(n), 2 do if n % d == 0 then return false end end return true end   -- Returns a table of the prime...
http://rosettacode.org/wiki/Solve_a_Hidato_puzzle
Solve a Hidato puzzle
The task is to write a program which solves Hidato (aka Hidoku) puzzles. The rules are: You are given a grid with some numbers placed in it. The other squares in the grid will be blank. The grid is not necessarily rectangular. The grid may have holes in it. The grid is always connected. The number “1” is always ...
#REXX
REXX
/*REXX program solves a Numbrix (R) puzzle, it also displays the puzzle and solution. */ maxR=0; maxC=0; maxX=0; minR=9e9; minC=9e9; minX=9e9; cells=0; @.= parse arg xxx; PZ='Hidato puzzle' /*get the cell definitions from the CL.*/ xxx=translate(xxx, , "/\;:_", ',') ...
http://rosettacode.org/wiki/Sort_an_array_of_composite_structures
Sort an array of composite structures
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 ...
#Perl
Perl
@people = (['joe', 120], ['foo', 31], ['bar', 51]); @people = sort { $a->[0] cmp $b->[0] } @people;
http://rosettacode.org/wiki/Sort_an_array_of_composite_structures
Sort an array of composite structures
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 ...
#Phix
Phix
sequence s = {{"grass","green"},{"snow","white"},{"sky","blue"},{"cherry","red"},{0,1.2},{3.4,-1}} ?sort(s) function compare_col2(sequence a, b) return compare(a[2],b[2]) end function ?custom_sort(compare_col2,s) ?sort_columns(s,{2}) -- 0.8.0+, same result as above w/o needing an explicit comparison routine
http://rosettacode.org/wiki/Sort_an_integer_array
Sort an integer array
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 ...
#Niue
Niue
2 6 1 0 3 8 sort .s 0 1 2 3 6 8
http://rosettacode.org/wiki/Sort_an_integer_array
Sort an integer array
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 ...
#Objeck
Objeck
bundle Default { class Sort { function : Main(args : System.String[]) ~ Nil { nums := Structure.IntVector->New([2,4,3,1,2]); nums->Sort(); } } }
http://rosettacode.org/wiki/Sort_disjoint_sublist
Sort disjoint sublist
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 ...
#Standard_ML
Standard ML
functor SortDisjointFn (A : MONO_ARRAY) : sig val sort : (A.elem * A.elem -> order) -> (A.array * int array) -> unit end = struct   structure DisjointView : MONO_ARRAY = struct type elem = A.elem type array = A.array * int array fun length (a, s) = Array.length s fun sub ((a, s), i) = ...
http://rosettacode.org/wiki/Sort_disjoint_sublist
Sort disjoint sublist
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 ...
#Swift
Swift
struct DisjointSublistView<T> : MutableCollectionType { let array : UnsafeMutablePointer<T> let indexes : [Int]   subscript (position: Int) -> T { get { return array[indexes[position]] } set { array[indexes[position]] = newValue } } var startIndex : Int { return 0 } var endIndex ...
http://rosettacode.org/wiki/Sort_using_a_custom_comparator
Sort using a custom comparator
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 ...
#Wren
Wren
import "/sort" for Cmp, Sort   var cmp = Fn.new { |s, t| if (s.count < t.count) return 1 if (s.count > t.count) return -1 return Cmp.insensitive.call(s, t) }   var strings = ["Here", "are", "some", "sample", "strings", "to", "be", "sorted"] System.print("Unsorted: %(strings)") Sort.insertion(strings, cmp) S...
http://rosettacode.org/wiki/Sort_using_a_custom_comparator
Sort using a custom comparator
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 ...
#zkl
zkl
s:=T("Cat","apple","Adam","zero","Xmas","quit","Level","add","Actor","base","butter"); r:=s.sort(fcn(a,b){ an,bn := a.len(),b.len(); if(an==bn)(a.toLower() < b.toLower()) else (an > bn) }); r.pump(Console.println);
http://rosettacode.org/wiki/Sorting_algorithms/Bubble_sort
Sorting algorithms/Bubble 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 ...
#Lucid
Lucid
bsort(a) = if iseod(first a) then a else follow(bsort(allbutlast(b)),last(b)) fi where b = bubble(a); bubble(a) = smaller(max, next a) where max = first a fby larger(max, next a); larger(x,y) = if iseod(y) then y elseif x end; follow(x,y) = if xdone then y upon xdo...
http://rosettacode.org/wiki/Sorting_algorithms/Gnome_sort
Sorting algorithms/Gnome 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 ...
#Tcl
Tcl
package require Tcl 8.5 package require struct::list   proc gnomesort {a} { set i 1 set j 2 set size [llength $a] while {$i < $size} { if {[lindex $a [expr {$i - 1}]] <= [lindex $a $i]} { set i $j incr j } else { struct::list swap a [expr {$i - 1}]...
http://rosettacode.org/wiki/Sorting_algorithms/Cocktail_sort
Sorting algorithms/Cocktail 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 ...
#Seed7
Seed7
const proc: cocktailSort (inout array elemType: arr) is func local var boolean: swapped is FALSE; var integer: i is 0; var elemType: help is elemType.value; begin repeat swapped := FALSE; for i range 1 to length(arr) - 1 do if arr[i] > arr[i + 1] then help := arr[i]; ...
http://rosettacode.org/wiki/Sockets
Sockets
For this exercise a program is open a socket to localhost on port 256 and send the message "hello socket world" before closing the socket. Catching any exceptions or errors is not required.
#Ring
Ring
  Load "guilib.ring"   new qApp { oClient = new Client { client() } exec() }   Class Client   win1 oTcpSocket   func client   win1 = new qwidget()   new qpushbutton(win1) { setgeometry(50,50,100,30) settext("...
http://rosettacode.org/wiki/Sockets
Sockets
For this exercise a program is open a socket to localhost on port 256 and send the message "hello socket world" before closing the socket. Catching any exceptions or errors is not required.
#Ruby
Ruby
require 'socket' sock = TCPSocket.open("localhost", 256) sock.write("hello socket world") sock.close
http://rosettacode.org/wiki/Smith_numbers
Smith numbers
Smith numbers are numbers such that the sum of the decimal digits of the integers that make up that number is the same as the sum of the decimal digits of its prime factors excluding 1. By definition, all primes are excluded as they (naturally) satisfy this condition! Smith numbers are also known as   joke   numbers....
#M2000_Interpreter
M2000 Interpreter
  Module Checkit { Set Fast ! Form 80, 40 Refresh Function Smith(max=10000) { Function SumDigit(a$) { def long sum For i=1 to len(a$) {sum+=val(mid$(a$,i, 1)) } =sum } x=max \\...
http://rosettacode.org/wiki/Smith_numbers
Smith numbers
Smith numbers are numbers such that the sum of the decimal digits of the integers that make up that number is the same as the sum of the decimal digits of its prime factors excluding 1. By definition, all primes are excluded as they (naturally) satisfy this condition! Smith numbers are also known as   joke   numbers....
#MAD
MAD
NORMAL MODE IS INTEGER PRINT COMMENT$ SMITH NUMBERS$   R GENERATE PRIMES UP TO 10,000 USING SIEVE METHOD BOOLEAN SIEVE DIMENSION SIEVE(10000) DIMENSION PRIMES(1500)   THROUGH SET, FOR I=2, 1, I.G.10000 SET SIEVE(I) = 1B   ...
http://rosettacode.org/wiki/Solve_a_Hidato_puzzle
Solve a Hidato puzzle
The task is to write a program which solves Hidato (aka Hidoku) puzzles. The rules are: You are given a grid with some numbers placed in it. The other squares in the grid will be blank. The grid is not necessarily rectangular. The grid may have holes in it. The grid is always connected. The number “1” is always ...
#Ruby
Ruby
# Solve a Hidato Puzzle # class Hidato Cell = Struct.new(:value, :used, :adj) ADJUST = [[-1, -1], [-1, 0], [-1, 1], [0, -1], [0, 1], [1, -1], [1, 0], [1, 1]]   def initialize(board, pout=true) @board = [] board.each_line do |line| @board << line.split.map{|n| Cell[Integer(n), false] rescue nil} + [n...
http://rosettacode.org/wiki/Sort_an_array_of_composite_structures
Sort an array of composite structures
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 ...
#Phixmonti
Phixmonti
include ..\Utilitys.pmt   def minverse reverse enddef   getid minverse var f   ( ( "grass" "green" ) ( "snow" "white" ) ( "sky" "blue" ) ( "cherry" "red" ) ( 0 1.2 ) ( 3.4 -1 ) ) dup   sort print nl   /# sorted by second component #/ f map sort f map print
http://rosettacode.org/wiki/Sort_an_array_of_composite_structures
Sort an array of composite structures
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
: (sort '(("def" 456) ("abc" 789) ("ghi" 123))) -> (("abc" 789) ("def" 456) ("ghi" 123))
http://rosettacode.org/wiki/Sort_an_integer_array
Sort an integer array
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 ...
#Objective-C
Objective-C
NSArray *nums = @[@2, @4, @3, @1, @2]; NSArray *sorted = [nums sortedArrayUsingSelector:@selector(compare:)];
http://rosettacode.org/wiki/Sort_an_integer_array
Sort an integer array
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 nums = [|2; 4; 3; 1; 2|] Array.sort compare nums
http://rosettacode.org/wiki/Sort_disjoint_sublist
Sort disjoint sublist
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 ...
#Tcl
Tcl
package require Tcl 8.5 proc disjointSort {values indices args} { # Ensure that we have a unique list of integers, in order # We assume there are no end-relative indices set indices [lsort -integer -unique $indices] # Map from those indices to the values to sort set selected {} foreach i $indice...
http://rosettacode.org/wiki/Sorting_algorithms/Bubble_sort
Sorting algorithms/Bubble 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 ...
#M2000_Interpreter
M2000 Interpreter
  Module Bubble { function bubblesort { dim a() \\ [] is a stack object, interpreter pass current stack pointer, and set a new stack for current stack \\ array( stackobject ) get a stack object and return an array a()=array([]) ...
http://rosettacode.org/wiki/Sorting_algorithms/Gnome_sort
Sorting algorithms/Gnome 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 ...
#TI-83_BASIC
TI-83 BASIC
:1→P :L1→L2 :While P<dim(L2) :If PP=1 :Then :P+1→P :Else :If L2(P)≥L2(P-1) :Then :P+1→P :Else :L2(P)→Q :L2(P-1)→L2(P) :Q→L2(P-1) :P-1→P :End :End :End :If L2(dim(L2))<L2(dim(L2)-1) :Then :L2(dim(L2))→Q :L2(dim(L2)-1)→L2(dim(L2)) :Q→L2(dim(L2)-1) :End :DelVar P :DelVar Q :Return
http://rosettacode.org/wiki/Sorting_algorithms/Cocktail_sort
Sorting algorithms/Cocktail 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 ...
#Sidef
Sidef
func cocktailsort(a) { var swapped = false func cmpsw(i) { if (a[i] > a[i+1]) { a[i, i+1] = a[i+1, i] swapped = true } } var max = a.end do { {|i| cmpsw(i) } << ^max swapped.not! && break {|i| cmpsw(max-i) } << 1..max } while (swapp...
http://rosettacode.org/wiki/Sockets
Sockets
For this exercise a program is open a socket to localhost on port 256 and send the message "hello socket world" before closing the socket. Catching any exceptions or errors is not required.
#Rust
Rust
use std::io::prelude::*; use std::net::TcpStream;   fn main() { // Open a tcp socket connecting to 127.0.0.1:256, no error handling (unwrap) let mut my_stream = TcpStream::connect("127.0.0.1:256").unwrap();   // Write 'hello socket world' to the stream, ignoring the result of write let _ = my_stream.wri...
http://rosettacode.org/wiki/Sockets
Sockets
For this exercise a program is open a socket to localhost on port 256 and send the message "hello socket world" before closing the socket. Catching any exceptions or errors is not required.
#Scala
Scala
import java.net.Socket   object sendSocketData {   def sendData(host: String, msg: String) { val sock = new Socket(host, 256) sock.getOutputStream().write(msg.getBytes()) sock.getOutputStream().flush() sock.close() }   sendData("localhost", "hello socket world") }
http://rosettacode.org/wiki/Smith_numbers
Smith numbers
Smith numbers are numbers such that the sum of the decimal digits of the integers that make up that number is the same as the sum of the decimal digits of its prime factors excluding 1. By definition, all primes are excluded as they (naturally) satisfy this condition! Smith numbers are also known as   joke   numbers....
#Maple
Maple
isSmith := proc(n::posint) local factors, sumofDigits, sumofFactorDigits, x; if isprime(n) then return false; else sumofDigits := add(x, x = convert(n, base, 10)); sumofFactorDigits := add(map(x -> op(convert(x, base, 10)), [op(NumberTheory:-PrimeFactors(n))])); return evalb(sumofDigits = sumofFactorDigi...
http://rosettacode.org/wiki/Smith_numbers
Smith numbers
Smith numbers are numbers such that the sum of the decimal digits of the integers that make up that number is the same as the sum of the decimal digits of its prime factors excluding 1. By definition, all primes are excluded as they (naturally) satisfy this condition! Smith numbers are also known as   joke   numbers....
#Mathematica.2FWolfram_Language
Mathematica/Wolfram Language
smithQ[n_] := Not[PrimeQ[n]] && Total[IntegerDigits[n]] == Total[IntegerDigits /@ Flatten[ConstantArray @@@ FactorInteger[n]],2]; Select[Range[2, 10000], smithQ]
http://rosettacode.org/wiki/Solve_a_Hidato_puzzle
Solve a Hidato puzzle
The task is to write a program which solves Hidato (aka Hidoku) puzzles. The rules are: You are given a grid with some numbers placed in it. The other squares in the grid will be blank. The grid is not necessarily rectangular. The grid may have holes in it. The grid is always connected. The number “1” is always ...
#Rust
Rust
  use std::cmp::{max, min}; use std::fmt; use std::ops;   #[derive(Debug, Clone, PartialEq)] struct Board { cells: Vec<Vec<Option<u32>>>, }   impl Board { fn new(initial_board: Vec<Vec<u32>>) -> Self { let b = initial_board .iter() .map(|r| { r.iter() ...
http://rosettacode.org/wiki/Sort_an_array_of_composite_structures
Sort an array of composite structures
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 ...
#PowerShell
PowerShell
  $list = @{ "def" = "one" "abc" = "two" "jkl" = "three" "abcdef" = "four" "ghi" = "five" "ghijkl" = "six" } $list.GetEnumerator() | sort {-($PSItem.Name).length}, Name  
http://rosettacode.org/wiki/Sort_an_integer_array
Sort an integer array
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 ...
#Octave
Octave
sortedv = sort(v);
http://rosettacode.org/wiki/Sort_disjoint_sublist
Sort disjoint sublist
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 ...
#TUSCRIPT
TUSCRIPT
  $$ MODE TUSCRIPT values="7'6'5'4'3'2'1'0" indices="7'2'8" v_unsorted=SELECT (values,#indices) v_sort=DIGIT_SORT (v_unsorted) i_sort=DIGIT_SORT (indices) LOOP i=i_sort,v=v_sort values=REPLACE (values,#i,v) ENDLOOP PRINT values  
http://rosettacode.org/wiki/Sort_disjoint_sublist
Sort disjoint sublist
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 ...
#Ursala
Ursala
#import std #import nat   disjoint_sort = ^|(~&,num); ("i","v"). (-:(-:)"v"@p nleq-<~~lSrSX ~&rlPlw~|/"i" "v")*lS "v"   #cast %nL   t = disjoint_sort({6,1,7},<7,6,5,4,3,2,1,0>)
http://rosettacode.org/wiki/Sorting_algorithms/Bubble_sort
Sorting algorithms/Bubble 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 ...
#M4
M4
divert(-1)   define(`randSeed',141592653) define(`setRand', `define(`randSeed',ifelse(eval($1<10000),1,`eval(20000-$1)',`$1'))') define(`rand_t',`eval(randSeed^(randSeed>>13))') define(`random', `define(`randSeed',eval((rand_t^(rand_t<<18))&0x7fffffff))randSeed')   define(`set',`define(`$1[$2]',`$3')') define(`ge...
http://rosettacode.org/wiki/Sorting_algorithms/Gnome_sort
Sorting algorithms/Gnome 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 ...
#True_BASIC
True BASIC
  RANDOMIZE  !RAMDOMZE TIMER en QBASIC DIM array(-5 TO 12) CALL iniciarray(array()) PRINT "unsort: "; CALL escritura(array()) CALL gnomeSort(array()) PRINT PRINT " sort: "; CALL escritura(array()) END   SUB escritura (array()) FOR i = LBOUND(array) TO UBOUND(array) PRINT array(i); ...
http://rosettacode.org/wiki/Sorting_algorithms/Cocktail_sort
Sorting algorithms/Cocktail 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 ...
#Slate
Slate
s@(Sequence traits) cocktailSort [ |swapped| swapped: False. s size <= 1 ifTrue: [^ s]. [{0 to: s size - 2. s size - 2 downTo: 0} do: [|:range| range do: [|:index| (s at: index) > (s at: index + 1) ifTrue: [s swap: index with: index + 1. swapped: True]]. swapped ifFalse: [^ s]. swapped: Fal...
http://rosettacode.org/wiki/Sockets
Sockets
For this exercise a program is open a socket to localhost on port 256 and send the message "hello socket world" before closing the socket. Catching any exceptions or errors is not required.
#Scheme
Scheme
(let ((s (socket PF_INET SOCK_STREAM 0))) (connect s AF_INET (inet-pton AF_INET "127.0.0.1") 256) (display "hello socket world" s))
http://rosettacode.org/wiki/Sockets
Sockets
For this exercise a program is open a socket to localhost on port 256 and send the message "hello socket world" before closing the socket. Catching any exceptions or errors is not required.
#Seed7
Seed7
$ include "seed7_05.s7i"; include "socket.s7i";   const proc: main is func local var file: sock is STD_NULL; begin sock := openInetSocket(256); writeln(sock, "hello socket world"); close(sock); end func;
http://rosettacode.org/wiki/Smith_numbers
Smith numbers
Smith numbers are numbers such that the sum of the decimal digits of the integers that make up that number is the same as the sum of the decimal digits of its prime factors excluding 1. By definition, all primes are excluded as they (naturally) satisfy this condition! Smith numbers are also known as   joke   numbers....
#Modula-2
Modula-2
MODULE SmithNumbers; FROM FormatString IMPORT FormatString; FROM Terminal IMPORT WriteString,WriteLn,ReadChar;   PROCEDURE SumDigits(n : INTEGER) : INTEGER; VAR sum : INTEGER; BEGIN sum := 0; WHILE n > 0 DO sum := sum + (n MOD 10); n := n DIV 10; END; RETURN sum; END SumDigits;   VAR ...
http://rosettacode.org/wiki/Solve_a_Hidato_puzzle
Solve a Hidato puzzle
The task is to write a program which solves Hidato (aka Hidoku) puzzles. The rules are: You are given a grid with some numbers placed in it. The other squares in the grid will be blank. The grid is not necessarily rectangular. The grid may have holes in it. The grid is always connected. The number “1” is always ...
#Seed7
Seed7
$ include "seed7_05.s7i";   var set of integer: given is {}; var array array integer: board is 0 times 0 times 0; var integer: startRow is 0; var integer: startColumn is 0;   const proc: setup (in array string: input) is func local var integer: r is 0; var integer: c is 0; var array string: row is 0 times...
http://rosettacode.org/wiki/Sort_an_array_of_composite_structures
Sort an array of composite structures
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
Structure MyPair ; Define a structured data type Name$ Value.i EndStructure   Dim People.MyPair(2) ; Allocate some elements   People(0)\Name$ = "John" ; Start filling them in People(0)\Value = 100   People(1)\Name$ = "Emma" People(1)\Value = 200   People(2)\Name$ = "Johnny" People(2)\Value = 175...
http://rosettacode.org/wiki/Sort_an_integer_array
Sort an integer array
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 ...
#Oforth
Oforth
[ 8, 2, 5, 9, 1, 3, 6, 7, 4 ] sort
http://rosettacode.org/wiki/Sort_an_integer_array
Sort an integer array
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 ...
#ooRexx
ooRexx
a = .array~of(4, 1, 6, -2, 99, -12) say "The sorted numbers are" say a~sortWith(.numericComparator~new)~makeString
http://rosettacode.org/wiki/Sort_disjoint_sublist
Sort disjoint sublist
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 ...
#Wren
Wren
import "/sort" for Sort   // sorts values in place, leaves indices unsorted var sortDisjoint = Fn.new { |values, indices| var sublist = [] for (ix in indices) sublist.add(values[ix]) Sort.quick(sublist) var i = 0 var indices2 = Sort.merge(indices) for (ix in indices2) { values[ix] = subl...
http://rosettacode.org/wiki/Sorting_algorithms/Bubble_sort
Sorting algorithms/Bubble 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 ...
#Maple
Maple
arr := Array([17,3,72,0,36,2,3,8,40,0]): len := numelems(arr): while(true) do change := false: len--; for i from 1 to len do if (arr[i] > arr[i+1]) then temp := arr[i]: arr[i] := arr[i+1]: arr[i+1] := temp: change := true: end if: end do: if (not change) then break end if: end do: arr;
http://rosettacode.org/wiki/Sorting_algorithms/Gnome_sort
Sorting algorithms/Gnome 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 ...
#uBasic.2F4tH
uBasic/4tH
PRINT "Gnome sort:" n = FUNC (_InitArray) PROC _ShowArray (n) PROC _Gnomesort (n) PROC _ShowArray (n) PRINT   END     _Gnomesort PARAM (1) ' Gnome sort LOCAL (2) b@=1 c@=2   DO WHILE b@ < a@ IF @(b@-1) > @(b@) THEN PROC _Swap (b@, b@-1) b@ = b@ - 1 IF b@ THEN ...
http://rosettacode.org/wiki/Sorting_algorithms/Cocktail_sort
Sorting algorithms/Cocktail 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 ...
#Smalltalk
Smalltalk
OrderedCollection extend [ swap: indexA and: indexB [ |t| t := self at: indexA. self at: indexA put: (self at: indexB). self at: indexB put: t ] cocktailSort [ |swapped| [ swapped := false. 1 to: (self size - 1) do: [ :i | (self at: i) > (self at: (i+1)) ifTrue: [ ...
http://rosettacode.org/wiki/Sockets
Sockets
For this exercise a program is open a socket to localhost on port 256 and send the message "hello socket world" before closing the socket. Catching any exceptions or errors is not required.
#SenseTalk
SenseTalk
  set SocketID to "localhost:256" open socket SocketID write "Hello socket world!" to socket SocketID close socket SocketID  
http://rosettacode.org/wiki/Sockets
Sockets
For this exercise a program is open a socket to localhost on port 256 and send the message "hello socket world" before closing the socket. Catching any exceptions or errors is not required.
#Sidef
Sidef
var host = Socket.gethostbyname('localhost'); var in = Socket.sockaddr_in(256, host); var proto = Socket.getprotobyname('tcp');   var sock = Socket.open(Socket.AF_INET, Socket.SOCK_STREAM, proto); sock.connect(in); sock.send('hello socket world', 0, in); sock.close;
http://rosettacode.org/wiki/Smith_numbers
Smith numbers
Smith numbers are numbers such that the sum of the decimal digits of the integers that make up that number is the same as the sum of the decimal digits of its prime factors excluding 1. By definition, all primes are excluded as they (naturally) satisfy this condition! Smith numbers are also known as   joke   numbers....
#Nim
Nim
import strformat   func primeFactors(n: int): seq[int] = result = newSeq[int]() var n = n var i = 2 while n mod i == 0: result.add(i) n = n div i i = 3 while i * i <= n: while n mod i == 0: result.add(i) n = n div i inc i, 2 if n != 1: result.add(n)   func sumDigits(n: int)...
http://rosettacode.org/wiki/Smith_numbers
Smith numbers
Smith numbers are numbers such that the sum of the decimal digits of the integers that make up that number is the same as the sum of the decimal digits of its prime factors excluding 1. By definition, all primes are excluded as they (naturally) satisfy this condition! Smith numbers are also known as   joke   numbers....
#Objeck
Objeck
use Collection;   class Test { function : Main(args : String[]) ~ Nil { for(n := 1; n < 10000; n+=1;) { factors := PrimeFactors(n); if(factors->Size() > 1) { sum := SumDigits(n); each(i : factors) { sum -= SumDigits(factors->Get(i)); };   if(sum = 0) { ...
http://rosettacode.org/wiki/Solve_a_Hidato_puzzle
Solve a Hidato puzzle
The task is to write a program which solves Hidato (aka Hidoku) puzzles. The rules are: You are given a grid with some numbers placed in it. The other squares in the grid will be blank. The grid is not necessarily rectangular. The grid may have holes in it. The grid is always connected. The number “1” is always ...
#Tailspin
Tailspin
  def input: '__ 33 35 __ __ . . . __ __ 24 22 __ . . . __ __ __ 21 __ __ . . __ 26 __ 13 40 11 . . 27 __ __ __ 9 __ 1 . . . __ __ 18 __ __ . . . . . __ 7 __ __ . . . . . . 5 __';   templates hidato composer setup data givenInput <[<={}|{row: <row>, col: <col>}>*]> local @: ...