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/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
... | #Python | Python | people = [('joe', 120), ('foo', 31), ('bar', 51)]
sorted(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
... | #R | R | sortbyname <- function(x, ...) x[order(names(x), ...)]
x <- c(texas=68.9, ohio=87.8, california=76.2, "new york"=88.2)
sortbyname(x) |
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
... | #Order | Order | #include <order/interpreter.h>
ORDER_PP( 8seq_sort(8less, 8seq(2, 4, 3, 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
... | #Oz | Oz | declare
Nums = [2 4 3 1 2]
Sorted = {List.sort Nums Value.'<'}
in
{Show Sorted} |
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
... | #XPL0 | XPL0 | include xpllib; \for Sort routine
int Values, Indices, J, I, T;
[Values:= [7, 6, 5, 4, 3, 2, 1, 0];
Indices:= [6, 1, 7];
Sort(Indices, 3);
for J:= 3-1 downto 0 do \bubble sort values at Indices
for I:= 0 to J-1 do
if Values(Indices(I)) > Values(Indices(I+1)) then
[T:= Values(Indices(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
... | #zkl | zkl | values :=T(7, 6, 5, 4, 3, 2, 1, 0);
indices:=T(6, 1, 7);
indices.apply(values.get).sort() // a.get(0) == a[0]
.zip(indices.sort()) //-->(v,i) == L(L(0,1),L(1,6),L(6,7))
.reduce(fcn(newList,[(v,i)]){ newList[i]=v; newList },values.copy())
.println(); // new list |
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
... | #Mathematica.2FWolfram_Language | Mathematica/Wolfram Language | bubbleSort[{w___, x_, y_, z___}] /; x > y := bubbleSort[{w, y, x, z}]
bubbleSort[sortedList_] := sortedList
bubbleSort[{10, 3, 7, 1, 4, 3, 8, 13, 9}] |
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
... | #Ursala | Ursala | gnome_sort "p" =
@NiX ^=lx -+ # iteration
~&r?\~& @lNXrX ->llx2rhPlrPCTxPrtPX~&lltPlhPrCXPrX ~&ll&& @llPrXh not "p", # backward bubble
->~&rhPlCrtPX ~&r&& ~&lZ!| @bh "p"+- # forward scan |
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
... | #Swift | Swift | extension Collection where Element: Comparable {
public func cocktailSorted() -> [Element] {
var swapped = false
var ret = Array(self)
guard count > 1 else {
return ret
}
repeat {
for i in 0...ret.count-2 where ret[i] > ret[i + 1] {
(ret[i], ret[i + 1]) = (ret[i + 1], ret[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
... | #Tcl | Tcl | package require Tcl 8.5
package require struct::list
proc cocktailsort {A} {
set len [llength $A]
set swapped true
while {$swapped} {
set swapped false
for {set i 0} {$i < $len - 1} {incr i} {
set j [expr {$i + 1}]
if {[lindex $A $i] > [lindex $A $j]} {
... |
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.
| #Slate | Slate | [ | socket |
[ | addr stream |
addr: (Net SocketAddress newOn: '127.0.0.1:256').
socket: (Net Socket newFor: addr domain type: Net Socket Types Stream protocol: Net Socket Protocols Default).
socket connectTo: addr.
stream: (Net SocketStream newOn: socket).
stream nextPutAll: ('hello socket world'... |
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.
| #Smalltalk | Smalltalk | PackageLoader fileInPackage: 'TCP'!
Object subclass: #HelloSocket
instanceVariableNames: 'ss'
classVariableNames: ''
poolDictionaries: ''
category: 'SimpleEcho'!
!HelloSocket class methodsFor: 'instance creation'!
port: anInteger
| ses |
ses := super new.
ses init: anInteger.
^ses
!!
!HelloSocke... |
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.... | #PARI.2FGP | PARI/GP | isSmith(n)=my(f=factor(n)); if(#f~==1 && f[1,2]==1, return(0)); sum(i=1, #f~, sumdigits(f[i, 1])*f[i, 2]) == sumdigits(n);
select(isSmith, [1..9999]) |
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.... | #Pascal | Pascal | program SmithNum;
{$IFDEF FPC}
{$MODE objFPC} //result and useful for x64
{$CODEALIGN PROC=64}
{$ENDIF}
uses
sysutils;
type
tdigit = byte;
tSum = LongInt;
const
base = 10;
//maxDigitCnt *(base-1) <= High(tSum)
//maxDigitCnt <= High(tSum) DIV (base-1);
maxDigitCnt = 16;
StartPrimNo = 6;
cseg... |
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 ... | #Tcl | Tcl | proc init {initialConfiguration} {
global grid max filled
set max 1
set y 0
foreach row [split [string trim $initialConfiguration "\n"] "\n"] {
set x 0
set rowcontents {}
foreach cell $row {
if {![string is integer -strict $cell]} {set cell -1}
lappend rowcontents $cell
set max [expr {... |
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
... | #Racket | Racket |
#lang racket
(define data '([Joe 5531] [Adam 2341] [Bernie 122] [Walter 1234] [David 19]))
(sort data < #:key cadr)
;; --> '((David 19) (Bernie 122) (Walter 1234) (Adam 2341) (Joe 5531))
;; Demonstrating a "key" that is not just a direct element
(sort data string<? #:key (compose1 symbol->string car))
;; --> '(... |
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
... | #Raku | Raku | my class Employee {
has Str $.name;
has Rat $.wage;
}
my $boss = Employee.new( name => "Frank Myers" , wage => 6755.85 );
my $driver = Employee.new( name => "Aaron Fast" , wage => 2530.40 );
my $worker = Employee.new( name => "John Dude" , wage => 2200.00 );
my $salesman = Employee.new( n... |
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
... | #PARI.2FGP | PARI/GP | vecsort(v) |
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
... | #MATLAB | MATLAB | function list = bubbleSort(list)
hasChanged = true;
itemCount = numel(list);
while(hasChanged)
hasChanged = false;
itemCount = itemCount - 1;
for index = (1:itemCount)
if(list(index) > list(index+1))
list([index index+1]) = list([index+1 index]);... |
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
... | #VBA | VBA | Private Function gnomeSort(s As Variant) As Variant
Dim i As Integer: i = 1
Dim j As Integer: j = 2
Dim tmp As Integer
Do While i < UBound(s)
If s(i) <= s(i + 1) Then
i = j
j = j + 1
Else
tmp = s(i)
s(i) = s(i + 1)
s(i + 1) = tm... |
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
... | #uBasic.2F4tH | uBasic/4tH | PRINT "Cocktail sort:"
n = FUNC (_InitArray)
PROC _ShowArray (n)
PROC _Cocktailsort (n)
PROC _ShowArray (n)
PRINT
END
_Cocktailsort PARAM (1) ' Cocktail sort
LOCAL (2)
b@ = 0
DO WHILE b@ = 0
b@ = 1
FOR c@=1 TO a@-1
IF @(c@) < @(c@-1) THEN PROC _Swap (c@, c@-1) : b@ = 0... |
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.
| #Symsyn | Symsyn |
'127.0.0.1' $addr
connect $addr 256 sok
'hello socket world' [sok]
close sok
|
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.
| #Standard_ML | Standard ML | val txt = Word8VectorSlice.full (Byte.stringToBytes "hello world" ) ;
val set = fn socket => fn ipnr => fn portnr => fn text =>
(
Socket.connect (socket, INetSock.toAddr ( Option.valOf (NetHostDB.fromString(ipnr) ) , portnr )) ;
Socket.sendVec(socket, text) before Socket.close socket
)
;
|
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.
| #Tcl | Tcl | set io [socket localhost 256]
puts -nonewline $io "hello socket world"
close $io |
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.... | #Perl | Perl | use ntheory qw/:all/;
my @smith;
forcomposites {
push @smith, $_ if sumdigits($_) == sumdigits(join("",factor($_)));
} 10000-1;
say scalar(@smith), " Smith numbers below 10000.";
say "@smith"; |
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.... | #Phix | Phix | with javascript_semantics
function sum_digits(integer n, base=10)
integer res = 0
while n do
res += remainder(n,base)
n = floor(n/base)
end while
return res
end function
function smith(integer n)
sequence p = prime_factors(n,true,-1)
if length(p)=1 then return false end if
... |
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 ... | #Wren | Wren | import "/sort" for Sort
import "/fmt" for Fmt
var board = []
var given = []
var start = []
var setUp = Fn.new { |input|
var nRows = input.count
var puzzle = List.filled(nRows, null)
for (i in 0...nRows) puzzle[i] = input[i].split(" ")
var nCols = puzzle[0].count
var list = []
board = List.fi... |
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
... | #REXX | REXX | /*REXX program sorts an array of composite structures (which has two classes of data).*/
#=0 /*number elements in structure (so far)*/
name='tan' ; value= 0; call add name,value /*tan peanut M&M's are 0% of total*/
name='orange'; value=10; call add name,value ... |
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
... | #Peloton | Peloton | Construct a list of numbers
<@ LETCNSLSTLIT>L|65^84^1^25^77^4^47^2^42^44^41^25^69^3^51^45^4^39^</@>
Numbers sort as strings
<@ ACTSRTENTLST>L</@>
<@ SAYDMPLST>L</@>
<@ ACTSRTENTLSTLIT>L|__StringDescending</@>
<@ SAYDMPLST>L</@>
Construct another list of numbers
<@ LETCNSLSTLIT>list|65^84^1^25^77^4^47^2^42^44^41^... |
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
... | #Perl | Perl | @nums = (2,4,3,1,2);
@sorted = sort {$a <=> $b} @nums; |
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
... | #MAXScript | MAXScript | fn bubbleSort arr =
(
while true do
(
changed = false
for i in 1 to (arr.count - 1) do
(
if arr[i] > arr[i+1] then
(
swap arr[i] arr[i+1]
changed = true
)
)
if not changed then exit
)
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
... | #VBScript | VBScript | function gnomeSort( a )
dim i
dim j
i = 1
j = 2
do while i < ubound( a ) + 1
if a(i-1) <= a(i) then
i = j
j = j + 1
else
swap a(i-1), a(i)
i = i - 1
if i = 0 then
i = j
j = j + 1
end if
end if
loop
gnomeSort = a
end function
sub swap( byref x, byref y )
dim temp
temp = x
x = ... |
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
... | #Ursala | Ursala | #import std
ctsort = ^=+ +^|(==?/~&l+ @r+ ~&x++ @x,^/~&)+ ("p". =><> ~&r?\~&C "p"?lrhPX/~&C ~&rhPlrtPCC)^~/not ~& |
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.
| #Toka | Toka | needs sockets
#! A simple abstraction layer that makes writing trivial servers easy
value| server.socket server.connection server.action |
[ ( n- ) pBind to server.socket ] is server.setSocket
[ ( - ) server.socket pAccept to server.connection ] is server.acceptConnection
[ ( - ) server.connection pClose drop... |
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.
| #TXR | TXR | (let* ((server (first (getaddrinfo "localhost" 256)))
(sock (open-socket server.family sock-stream)))
(sock-connect sock server)
(put-string "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.... | #PicoLisp | PicoLisp | (de factor (N)
(make
(let (D 2 L (1 2 2 . (4 2 4 2 4 6 2 6 .)) M (sqrt N))
(while (>= M D)
(if (=0 (% N D))
(setq M (sqrt (setq N (/ N (link D)))))
(inc 'D (pop 'L)) ) )
(link N) ) ) )
(de sumdigits (N)
(sum format (chop N)) )
(de smith (X)
(m... |
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.... | #PL.2FI | PL/I | smith: procedure options(main);
/* find the digit sum of N */
digitSum: procedure(nn) returns(fixed);
declare (n, nn, s) fixed;
s = 0;
do n=nn repeat(n/10) while(n>0);
s = s + mod(n,10);
end;
return(s);
end digitSum;
/* find and count factors of N */... |
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 ... | #zkl | zkl | hi:= // 0==empty cell, X==not a cell
#<<<
"0 33 35 0 0 X X X
0 0 24 22 0 X X X
0 0 0 21 0 0 X X
0 26 0 13 40 11 X X
27 0 0 0 9 0 1 X
X X 0 0 18 0 0 X
X X X X 0 7 0 0
X X X X X X 5 0";
#<<<
board,given,... |
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
... | #Ring | Ring |
aList= sort([:Eight = 8, :Two = 2, :Five = 5, :Nine = 9, :One = 1,
:Three = 3, :Six = 6, :Seven = 7, :Four = 4, :Ten = 10] , 2)
for item in aList
? item[1] + space(10-len(item[1])) + item[2]
next
|
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
... | #Ruby | Ruby | Person = Struct.new(:name,:value) do
def to_s; "name:#{name}, value:#{value}" end
end
list = [Person.new("Joe",3),
Person.new("Bill",4),
Person.new("Alice",20),
Person.new("Harry",3)]
puts list.sort_by{|x|x.name}
puts
puts list.sort_by(&:value) |
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
... | #Phix | Phix | ?sort({9, 10, 3, 1, 4, 5, 8, 7, 6, 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
... | #Phixmonti | Phixmonti | include ..\Utilitys.pmt
( 9 10 3 1 4 5 8 7 6 2 ) sort print |
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
... | #MMIX | MMIX | Ja IS $127
LOC Data_Segment
DataSeg GREG @
Array IS @-Data_Segment
OCTA 999,200,125,1,1020,40,4,5,60,100
ArrayLen IS (@-Array-Data_Segment)/8
NL IS @-Data_Segment
BYTE #a,0
LOC @+(8-@)&7
Buffer IS @-Data_Segment
LOC #1000
GREG @
sor... |
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
... | #Vlang | Vlang | fn main() {
mut a := [170, 45, 75, -90, -802, 24, 2, 66]
println("before: $a")
gnome_sort(mut a)
println("after: $a")
}
fn gnome_sort(mut a []int) {
for i, j := 1, 2; i < a.len; {
if a[i-1] > a[i] {
a[i-1], a[i] = a[i], a[i-1]
i--
if i > 0 {
... |
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
... | #Vala | Vala | void swap(int[] array, int i1, int i2) {
if (array[i1] == array[i2])
return;
var tmp = array[i1];
array[i1] = array[i2];
array[i2] = tmp;
}
void cocktail_sort(int[] array) {
while(true) {
bool flag = false;
int[] start = {1, array.length - 1};
int[] end = {array.length, 0};
int[] inc = {... |
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.
| #UNIX_Shell | UNIX Shell | echo "hello socket world" | nc localhost 256 |
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.
| #Ursa | Ursa | decl port p
p.connect "localhost" 256
out "hello socket world" endl p
p.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.
| #Visual_Basic_.NET | Visual Basic .NET | Imports System
Imports System.IO
Imports System.Net.Sockets
Public Class Program
Public Shared Sub Main(ByVal args As String[])
Dim tcp As New TcpClient("localhost", 256)
Dim writer As New StreamWriter(tcp.GetStream())
writer.Write("hello socket world")
writer.Flush()
... |
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.... | #PL.2FM | PL/M | 100H:
/* CP/M BDOS FUNCTIONS */
BDOS: PROCEDURE (F,A); DECLARE F BYTE, A ADDRESS; GO TO 5; END BDOS;
EXIT: PROCEDURE; GO TO 0; END EXIT;
PRINT: PROCEDURE (S); DECLARE S ADDRESS; CALL BDOS(9,S); END PRINT;
/* PRINT NUMBER */
PR$NUM: PROCEDURE (N);
DECLARE S (6) BYTE INITIAL (' $');
DECLARE N ADDRESS, I B... |
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
... | #Run_BASIC | Run BASIC | sqliteconnect #mem, ":memory:" ' create in memory db
mem$ = "CREATE TABLE people(num integer, name text,city text)"
#mem execute(mem$)
data "1","George","Redding","2","Fred","Oregon","3","Ben","Seneca","4","Steve","Fargo","5","Frank","Houston"
for i = 1 to 5 ... |
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
... | #Rust | Rust | use std::cmp::Ordering;
#[derive(Debug)]
struct Employee {
name: String,
category: String,
}
impl Employee {
fn new(name: &str, category: &str) -> Self {
Employee {
name: name.into(),
category: category.into(),
}
}
}
impl PartialEq for Employee {
fn eq(&... |
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
... | #PHP | PHP | <?php
$nums = array(2,4,3,1,2);
sort($nums);
?> |
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
... | #PicoLisp | PicoLisp | (sort (2 4 3 1 2))
-> (1 2 2 3 4) |
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
... | #Modula-2 | Modula-2 | PROCEDURE BubbleSort(VAR a: ARRAY OF INTEGER);
VAR
changed: BOOLEAN;
temp, count, i: INTEGER;
BEGIN
count := HIGH(a);
REPEAT
changed := FALSE;
DEC(count);
FOR i := 0 TO count DO
IF a[i] > a[i+1] THEN
temp := a[i];
a[i] := a[i+1];
a[i+1] := temp;
cha... |
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
... | #Wren | Wren | var gnomeSort = Fn.new { |a, asc|
var size = a.count
var i = 1
var j = 2
while (i < size) {
if ((asc && a[i-1] <= a[i]) || (!asc && a[i-1] >= a[i])) {
i = j
j = j + 1
} else {
var t = a[i-1]
a[i-1] = a[i]
a[i] = t
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
... | #VBA | VBA | Function cocktail_sort(ByVal s As Variant) As Variant
Dim swapped As Boolean
Dim f As Integer, t As Integer, d As Integer, tmp As Integer
swapped = True
f = 1
t = UBound(s) - 1
d = 1
Do While swapped
swapped = 0
For i = f To t Step d
If Val(s(i)) > Val(s(i + 1)) T... |
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.
| #Wren | Wren | /* sockets.wren */
var AF_UNSPEC = 0
var SOCK_STREAM = 1
foreign class AddrInfo {
foreign static getAddrInfo(name, service, req, pai)
construct new() {}
foreign family
foreign family=(f)
foreign sockType
foreign sockType=(st)
foreign protocol
foreign addr
foreign ... |
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.... | #PureBasic | PureBasic | DisableDebugger
#ECHO=#True ; #True: Print all results
Global NewList f.i()
Procedure.i ePotenz(Wert.i)
Define.i var=Wert, i
While var
i+1
var/10
Wend
ProcedureReturn i
EndProcedure
Procedure.i n_Element(Wert.i,Stelle.i=1)
If Stelle>0
ProcedureReturn (Wert%Int(Pow(10,Stelle))-Wer... |
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
... | #Scala | Scala | case class Pair(name:String, value:Double)
val input = Array(Pair("Krypton", 83.798), Pair("Beryllium", 9.012182), Pair("Silicon", 28.0855))
input.sortBy(_.name) // Array(Pair(Beryllium,9.012182), Pair(Krypton,83.798), Pair(Silicon,28.0855))
// alternative versions:
input.sortBy(struct => (struct.name, struct.value))... |
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
... | #PL.2FI | PL/I | DCL (T(10)) FIXED BIN(31); /* scratch space of length N/2 */
MERGE: PROCEDURE (A,LA,B,LB,C);
DECLARE (A(*),B(*),C(*)) FIXED BIN(31);
DECLARE (LA,LB) FIXED BIN(31) NONASGN;
DECLARE (I,J,K) FIXED BIN(31);
I=1; J=1; K=1;
DO WHILE ((I <= LA) & (J <= LB));
IF(A(I) <= B(J)) THEN
DO; C(K)=A(I... |
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
... | #Modula-3 | Modula-3 | MODULE Bubble;
PROCEDURE Sort(VAR a: ARRAY OF INTEGER) =
VAR sorted: BOOLEAN;
temp, len: INTEGER := LAST(a);
BEGIN
WHILE NOT sorted DO
sorted := TRUE;
DEC(len);
FOR i := FIRST(a) TO len DO
IF a[i+1] < a[i] THEN
temp := a[i];
a[i] := a[i + 1];
a[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
... | #XPL0 | XPL0 | code ChOut=8, IntOut=11;
proc GnomeSort(A(0..Size-1)); \Sort array A
int A, Size;
int I, J, T;
[I:= 1;
J:= 2;
while I < Size do
if A(I-1) <= A(I) then
[\ for descending sort, use >= for comparison
I:= J;
J:= J+1;
]
else
[T:= A(I-1); A(I-1):= A(I); A(I):= T; \swap... |
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
... | #VBScript | VBScript | function cocktailSort( byval a )
dim swapped
dim i
do
swapped = false
for i = 0 to ubound( a ) - 1
if a(i) > a(i+1) then
swap a(i), a(i+1)
swapped = true
end if
next
if not swapped then exit do
swapped = false
for i = ubound( a ) - 1 to 0 step -1
if a(i) > a( i+1) then
swap a(i), a(... |
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.
| #X86_Assembly | X86 Assembly |
;using sockets on linux with the 0x80 inturrprets.
;
;assemble
; nasm -o socket.o -f elf32 -g socket.asm
;link
; ld -o socket socket.o
;
;
;Just some assigns for better readability
%assign SOCK_STREAM 1
%assign AF_INET 2
%assign SYS_socketcall 102
%assign SYS_SOCKET 1
%assign SYS... |
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.... | #Python | Python | from sys import stdout
def factors(n):
rt = []
f = 2
if n == 1:
rt.append(1);
else:
while 1:
if 0 == ( n % f ):
rt.append(f);
n //= f
if n == 1:
return rt
else:
f += 1
retu... |
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
... | #Seed7 | Seed7 | $ include "seed7_05.s7i";
const type: pair is new struct
var string: name is "";
var string: value is "";
end struct;
const func integer: compare (in pair: pair1, in pair: pair2) is
return compare(pair1.name, pair2.name);
const func string: str (in pair: aPair) is
return "(" <& aPair.name <& ", " <&... |
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
... | #Sidef | Sidef | # Declare an array of pairs
var people = [['joe', 120], ['foo', 31], ['bar', 51]];
# Sort the array in-place by name
people.sort! {|a,b| a[0] <=> b[0] };
# Alternatively, we can use the `.sort_by{}` method
var sorted = people.sort_by { |item| item[0] };
# Display the sorted array
say 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
... | #Pop11 | Pop11 | lvars ar = {2 4 3 1 2};
;;; Convert array to list.
;;; destvector leaves its results and on the pop11 stack + an integer saying how many there were
destvector(ar);
;;; conslist uses the items left on the stack plus the integer, to make a list of those items.
lvars ls = conslist();
;;; Sort it
sort(ls) -> ls;
;;; Conver... |
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
... | #Potion | Potion | (7, 5, 1, 2, 3, 8, 9) sort join(", ") print |
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
... | #N.2Ft.2Froff | N/t/roff |
.ig
Bubble sort algorithm in Troff
==============================
:For: Rosetta Code
:Author: Stephanie Björk (Katt)
:Date: December 1, 2017
..
.ig
Array implementation: \(*A
---------------------------
This is an array implementation that takes advantage of Troff's numerical
registers. Registers ``Ax``, where ``x... |
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
... | #zkl | zkl | fcn gnomeSort(a){
i,j,size := 1,2,a.len();
while(i < size){
if(a[i-1] > a[i]){ // for descending sort, use < for comparison
a.swap(i-1,i);
i = i - 1;
if(i) continue;
}
i = j;
j = j + 1;
}//while
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
... | #Vlang | Vlang | fn cocktail(mut arr []int) {
input := 'Input'
output := 'Output'
println('${input : -7s}: ${arr.str()}')
for {
mut swapped := false
for i := 0; i < arr.len - 1; i++ {
if arr[i] > arr[i + 1] {
temp := arr[i]
arr[i] = arr[i + 1]
arr[i + 1] = temp
swapped = true
}
}
if !swapped {
break... |
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.
| #X86-64_Assembly | X86-64 Assembly |
option casemap:none
option literals:on
ifndef __SOCKET_CLASS__
__SOCKET_CLASS__ equ 1
if @Platform eq windows64
WSADATA struct
wVersion dw ?
wHighVersion dw ?
iMaxSockets dw ?
iMaxUdpDg dw ?
szDescription db 256 dup (?)
szSystemStatus db 128 dup (?)
lpVendo... |
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.... | #Racket | Racket | #lang racket
(require math/number-theory)
(define (sum-of-digits n)
(let inr ((n n) (s 0))
(if (zero? n) s (let-values (([q r] (quotient/remainder n 10))) (inr q (+ s r))))))
(define (smith-number? n)
(and (not (prime? n))
(= (sum-of-digits n)
(for/sum ((pe (in-list (factorize n))))
... |
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.... | #Raku | Raku | constant @primes = 2, |(3, 5, 7 ... *).grep: *.is-prime;
multi factors ( 1 ) { 1 }
multi factors ( Int $remainder is copy ) {
gather for @primes -> $factor {
# if remainder < factor², we're done
if $factor * $factor > $remainder {
take $remainder if $remainder > 1;
last;
}
# How many... |
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
... | #Simula | Simula | BEGIN
CLASS COMPARABLE;;
COMPARABLE CLASS PAIR(N,V); TEXT N,V;;
CLASS COMPARATOR;
VIRTUAL:
PROCEDURE COMPARE IS
INTEGER PROCEDURE COMPARE(A, B); REF(COMPARABLE) A, B;;
BEGIN
END**OF**COMPARATOR;
COMPARATOR CLASS PAIRBYNAME;
BEGIN
INTEGER PROCEDURE COMP... |
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
... | #SQL | SQL | -- setup
CREATE TABLE pairs (name VARCHAR(16), VALUE VARCHAR(16));
INSERT INTO pairs VALUES ('Fluffy', 'cat');
INSERT INTO pairs VALUES ('Fido', 'dog');
INSERT INTO pairs VALUES ('Francis', 'fish');
-- order them by name
SELECT * FROM pairs ORDER BY 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
... | #PowerBASIC | PowerBASIC | ARRAY SORT x() |
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
... | #PowerShell | PowerShell | 34,12,23,56,1,129,4,2,73 | Sort-Object |
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
... | #Nanoquery | Nanoquery | def bubble_sort(seq)
changed = true
while changed
changed = false
for i in range(0, len(seq) - 2)
if seq[i] > seq[i + 1]
temp = seq[i]
seq[i] = seq[i + 1]
seq[i + 1] = temp
changed = true
end
end
end
return seq
end
if main
import Nanoquery.Util; random = new(Random)
testset = l... |
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
... | #Wren | Wren | var cocktailSort = Fn.new { |a|
var last = a.count - 1
while (true) {
var swapped = false
for (i in 0...last) {
if (a[i] > a[i+1]) {
var t = a[i]
a[i] = a[i+1]
a[i+1] = t
swapped = true
}
}
if... |
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.
| #zkl | zkl | var s=Network.TCPClientSocket.connectTo("localhost",256);
s.write("hello socket world"); //-->18
s.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.
| #Zsh | Zsh | zmodload zsh/net/tcp
ztcp localhost 256
print hello socket world >&$REPLY |
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.... | #REXX | REXX | /*REXX program finds (and maybe displays) Smith (or joke) numbers up to a given N.*/
parse arg N . /*obtain optional argument from the CL.*/
if N=='' | N=="," then N=10000 /*Not specified? Then use the default.*/
tell= (N>0); N=abs(N) - 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
... | #Swift | Swift | extension Sequence {
func sorted<Value>(
on: KeyPath<Element, Value>,
using: (Value, Value) -> Bool
) -> [Element] where Value: Comparable {
return withoutActuallyEscaping(using, do: {using -> [Element] in
return self.sorted(by: { using($0[keyPath: on], $1[keyPath: on]) })
})
}
}
struct Pe... |
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
... | #Prolog | Prolog | ?- msort([10,5,13,3, 85,3,1], L).
L = [1,3,3,5,10,13,85]. |
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
... | #PureBasic | PureBasic | Dim numbers(20)
For i = 0 To 20
numbers(i) = Random(1000)
Next
SortArray(numbers(), #PB_Sort_Ascending) |
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
... | #Nemerle | Nemerle | using System;
using System.Console;
module Bubblesort
{
Bubblesort[T] (x : list[T]) : list[T]
where T : IComparable
{
def isSorted(y)
{
|[_] => true
|y1::y2::ys => (y1.CompareTo(y2) < 0) && isSorted(y2::ys)
}
def sort(y)
{
|[y... |
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
... | #XPL0 | XPL0 | code ChOut=8, IntOut=11;
proc CocktailSort(A, L); \Sort array A of length L
int A, L;
int Swapped, I, T;
[loop [Swapped:= false;
for I:= 0 to L-2 do
if A(I) > A(I+1) then \test if elements are in wrong order
[T:= A(I); A(I):= A(I+1); A(I+1):= T; \elements change ... |
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.... | #Ring | Ring |
# Project : Smith numbers
see "All the Smith Numbers < 1000 are:" + nl
for prime = 1 to 1000
decmp = []
sum1 = sumDigits(prime)
decomp(prime)
sum2 = 0
if len(decmp)>1
for n=1 to len(decmp)
cstr = string(decmp[n])
for m= 1 to len(cstr)
sum2 = sum2 + n... |
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.... | #Ruby | Ruby | require "prime"
class Integer
def smith?
return false if prime?
digits.sum == prime_division.map{|pr,n| pr.digits.sum * n}.sum
end
end
n = 10_000
res = 1.upto(n).select(&:smith?)
puts "#{res.size} smith numbers below #{n}:
#{res.first(5).join(", ")},... #{res.last(5).join(", ")}" |
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
... | #Tcl | Tcl | set people {{joe 120} {foo 31} {bar 51}}
# sort by the first element of each pair
lsort -index 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
... | #UNIX_Shell | UNIX Shell | list="namez:order!
name space:in
name1:sort
name:Please"
newline="
"
dumplist() {
(
IFS=$newline
for pair in $list; do
(
IFS=:
set -- $pair
echo " $1 => $2"
)
done
)
}
echo "Original list:"
dumplist
list=`IFS=$newline; printf %s "$list" | sort -t: -k1,1`
echo "Sorted list:"
dumplist |
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
... | #Python | Python | nums = [2,4,3,1,2]
nums.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
... | #Quackery | Quackery | /O> [] 20 times [ 10 random join ]
... dup echo cr
... sort
... echo cr
...
[ 5 2 5 0 4 5 1 5 1 1 0 3 7 2 0 9 6 1 8 7 ]
[ 0 0 0 1 1 1 1 2 2 3 4 5 5 5 5 6 7 7 8 9 ]
|
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
... | #NetRexx | NetRexx | /* NetRexx */
options replace format comments java crossref savelog symbols binary
placesList = [String -
"UK London", "US New York" -
, "US Boston", "US Washington" -
, "UK Washington", "US Birmingham" -
, "UK Birmingham", "UK Boston" -
]
sortedList = bubbleSort(String[] Arrays.copyOf... |
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
... | #zkl | zkl | fcn cocktailSort(a){
swapped,begin,end:=False,-1,a.len() - 2;
do{
swapped,begin=False,begin + 1;
foreach i in ([begin .. end]){
if(a[i]>a[i+1]){ a.swap(i,i+1); swapped=True; }
}
if(not swapped) break;
swapped,end=False,end - 1;
foreach i in ([end..begin,-1]){
if(a[i]... |
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.... | #Rust | Rust | fn main () {
//We just need the primes below 100
let primes = vec![2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97];
let mut solution = Vec::new();
let mut number;
for i in 4..10000 {
//Factorize each number below 10.000
let mut prime_fa... |
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.... | #Scala | Scala | object SmithNumbers extends App {
def sumDigits(_n: Int): Int = {
var n = _n
var sum = 0
while (n > 0) {
sum += (n % 10)
n /= 10
}
sum
}
def primeFactors(_n: Int): List[Int] = {
var n = _n
val result = new collection.mutable.ListBuffer[Int]
val i = 2
while (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
... | #Ursala | Ursala | #import std
#cast %sWLW
examples =
(
-<&l <('z','a'),('x','c'),('y','b')>, # sorted by the left
-<&r <('z','a'),('x','c'),('y','b')>) # sorted by the right |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.