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/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
... | #NetRexx | NetRexx | /* NetRexx */
options replace format comments java crossref savelog symbols binary
import java.util.List
i1 = ArrayList(Arrays.asList([Integer(3), Integer(3), Integer(1), Integer(2), Integer(4), Integer(3), Integer(5), Integer(6)]))
say i1.toString
say gnomeSort(i1).toString
return
method isTrue public constant... |
http://rosettacode.org/wiki/Sorting_algorithms/Bead_sort | Sorting algorithms/Bead 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
... | #Standard_ML | Standard ML | fun columns l =
case List.filter (not o null) l of
[] => []
| l => map hd l :: columns (map tl l)
fun replicate (n, x) = List.tabulate (n, fn _ => x)
fun bead_sort l =
map length (columns (columns (map (fn e => replicate (e, 1)) l))) |
http://rosettacode.org/wiki/Sorting_algorithms/Bead_sort | Sorting algorithms/Bead 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
proc beadsort numList {
# Special case: empty list is empty when sorted.
if {![llength $numList]} return
# Set up the abacus...
foreach n $numList {
for {set i 0} {$i<$n} {incr i} {
dict incr vals $i
}
}
# Make the beads fall...
foreach n [dict values $vals] ... |
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
... | #M2000_Interpreter | M2000 Interpreter |
Module cocktailSort {
k=(3,2,1)
print k
cocktailSort(k)
print k
k=("c","b","a")
print k
cocktailSortString(k)
print k
Dim a(5)
a(0)=1,2,5,6,3
print a()
cocktailSort(a())
print a()
End
Sub cocktailSort(a)
\\ this is like Link a to a() but using new for a() - shadow any a()
push &a : read new &a()
... |
http://rosettacode.org/wiki/Sokoban | Sokoban | Demonstrate how to find a solution to a given Sokoban level. For the purpose of this task (formally, a PSPACE-complete problem) any method may be used. However a move-optimal or push-optimal (or any other -optimal) solutions is preferred.
Sokoban levels are usually stored as a character array where
space is an empty... | #11l | 11l | [String] data
V nrows = 0
V px = 0
V py = 0
V sdata = ‘’
V ddata = ‘’
F init(board)
:data = board.split("\n")
:nrows = max(:data.map(r -> r.len))
V maps = [‘ ’ = ‘ ’, ‘.’ = ‘.’, ‘@’ = ‘ ’, ‘#’ = ‘#’, ‘$’ = ‘ ’]
V mapd = [‘ ’ = ‘ ’, ‘.’ = ‘ ’, ‘@’ = ‘@’, ‘#’ = ‘ ’, ‘$’ = ‘*’]
L(row) :data
V r ... |
http://rosettacode.org/wiki/Solve_a_Holy_Knight%27s_tour | Solve a Holy Knight's tour |
Chess coaches have been known to inflict a kind of torture on beginners by taking a chess board, placing pennies on some squares and requiring that a Knight's tour be constructed that avoids the squares with pennies.
This kind of knight's tour puzzle is similar to Hidato.
The present task is to produce a solution ... | #D | D | import std.stdio, std.conv, std.string, std.range, std.algorithm,
std.typecons, std.typetuple;
struct HolyKnightPuzzle {
private alias InputCellBaseType = char;
private enum InputCell : InputCellBaseType { available = '#', unavailable = '.', start='1' }
private alias Cell = uint;
private enum... |
http://rosettacode.org/wiki/SOAP | SOAP | In this task, the goal is to create a SOAP client which accesses functions defined at http://example.com/soap/wsdl, and calls the functions soapFunc( ) and anotherSoapFunc( ).
This task has been flagged for clarification. Code on this page in its current state may be flagged incorrect once this task has been clarified... | #Clojure | Clojure | (require '[clj-soap.core :as soap])
(let [client (soap/client-fn "http://example.com/soap/wsdl")]
(client :soapFunc)
(client :anotherSoapFunc)) |
http://rosettacode.org/wiki/SOAP | SOAP | In this task, the goal is to create a SOAP client which accesses functions defined at http://example.com/soap/wsdl, and calls the functions soapFunc( ) and anotherSoapFunc( ).
This task has been flagged for clarification. Code on this page in its current state may be flagged incorrect once this task has been clarified... | #ColdFusion | ColdFusion | <cfset client = createObject("webservice","http://example.com/soap/wsdl")>
<cfset result = client.soapFunc("hello")>
<cfset result = client.anotherSoapFunc(34234)> |
http://rosettacode.org/wiki/SOAP | SOAP | In this task, the goal is to create a SOAP client which accesses functions defined at http://example.com/soap/wsdl, and calls the functions soapFunc( ) and anotherSoapFunc( ).
This task has been flagged for clarification. Code on this page in its current state may be flagged incorrect once this task has been clarified... | #Diego | Diego | apt_knowledge(webservices); // Commanding apt_protocol(SOAP); will also apt_knowledge(webservices);
set_namespace(rosettacode);
add_webserv(ws)_protocol(SOAP)_wdsl(http://example.com/soap/wsdl)_me();
invoke_webserv(ws)_soapFunc(hello)_msg()_result()_me();
me_msg()_invoke(ws)_anotherSoapFunc(32234); ... |
http://rosettacode.org/wiki/Solve_a_Hopido_puzzle | Solve a Hopido puzzle | Hopido puzzles are similar to Hidato. The most important difference is that the only moves allowed are: hop over one tile diagonally; and over two tiles horizontally and vertically. It should be possible to start anywhere in the path, the end point isn't indicated and there are no intermediate clues. Hopido Design Pos... | #Julia | Julia | using .Hidato # Note that the . here means to look locally for the module rather than in the libraries
const hopid = """
. 0 0 . 0 0 .
0 0 0 0 0 0 0
0 0 0 0 0 0 0
. 0 0 0 0 0 .
. . 0 0 0 . .
. . . 0 . . . """
const hopidomoves = [[-3, 0], [0, -3], [-2, -2], [-2, 2], [2, -2], [0, 3], [3, 0], [2, 2]]
bo... |
http://rosettacode.org/wiki/Solve_a_Hopido_puzzle | Solve a Hopido puzzle | Hopido puzzles are similar to Hidato. The most important difference is that the only moves allowed are: hop over one tile diagonally; and over two tiles horizontally and vertically. It should be possible to start anywhere in the path, the end point isn't indicated and there are no intermediate clues. Hopido Design Pos... | #Kotlin | Kotlin | // version 1.2.0
val board = listOf(
".00.00.",
"0000000",
"0000000",
".00000.",
"..000..",
"...0..."
)
val moves = listOf(
-3 to 0, 0 to 3, 3 to 0, 0 to -3,
2 to 2, 2 to -2, -2 to 2, -2 to -2
)
lateinit var grid: List<IntArray>
var totalToFill = 0
fun solve(r: Int, c: Int, c... |
http://rosettacode.org/wiki/Smallest_number_k_such_that_k%2B2%5Em_is_composite_for_all_m_less_than_k | Smallest number k such that k+2^m is composite for all m less than k | Generate the sequence of numbers a(k), where each k is the smallest positive integer such that k + 2m is composite for every positive integer m less than k.
For example
Suppose k == 7; test m == 1 through m == 6. If any are prime, the test fails.
Is 7 + 21 (9) prime? False
Is 7 + 22 (11) prime? True
So 7 is not a... | #Julia | Julia | using Lazy
using Primes
a(k) = all(m -> !isprime(k + big"2"^m), 1:k-1)
A033939 = @>> Lazy.range(2) filter(isodd) filter(a)
println(take(5, A033939)) # List: (773 2131 2491 4471 5101)
|
http://rosettacode.org/wiki/Smallest_number_k_such_that_k%2B2%5Em_is_composite_for_all_m_less_than_k | Smallest number k such that k+2^m is composite for all m less than k | Generate the sequence of numbers a(k), where each k is the smallest positive integer such that k + 2m is composite for every positive integer m less than k.
For example
Suppose k == 7; test m == 1 through m == 6. If any are prime, the test fails.
Is 7 + 21 (9) prime? False
Is 7 + 22 (11) prime? True
So 7 is not a... | #Perl | Perl | use strict;
use warnings;
use bigint;
use ntheory 'is_prime';
my $cnt;
LOOP: for my $k (2..1e10) {
next unless 1 == $k % 2;
for my $m (1..$k-1) {
next LOOP if is_prime $k + (1<<$m)
}
print "$k ";
last if ++$cnt == 5;
} |
http://rosettacode.org/wiki/Smallest_number_k_such_that_k%2B2%5Em_is_composite_for_all_m_less_than_k | Smallest number k such that k+2^m is composite for all m less than k | Generate the sequence of numbers a(k), where each k is the smallest positive integer such that k + 2m is composite for every positive integer m less than k.
For example
Suppose k == 7; test m == 1 through m == 6. If any are prime, the test fails.
Is 7 + 21 (9) prime? False
Is 7 + 22 (11) prime? True
So 7 is not a... | #Phix | Phix | with javascript_semantics
atom t0 = time()
include mpfr.e
mpz z = mpz_init()
function a(integer k)
if k=1 then return false end if
for m=1 to k-1 do
mpz_ui_pow_ui(z,2,m)
mpz_add_si(z,z,k)
if mpz_prime(z) then return false end if
end for
return true
end function
integer k = 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
... | #C.23 | C# | using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
struct Entry
{
public Entry(string name, double value) { Name = name; Value = value; }
public string Name;
public double Value;
}
static void Main(string[] args)
{
var Eleme... |
http://rosettacode.org/wiki/Sorting_algorithms/Counting_sort | Sorting algorithms/Counting 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 counting_sort(
mut data: Vec<usize>,
min: usize,
max: usize,
) -> Vec<usize> {
// create and fill counting bucket with 0
let mut count: Vec<usize> = Vec::with_capacity(data.len());
count.resize(data.len(), 0);
for num in &data {
count[num - min] = count[num - min] + 1;
}
... |
http://rosettacode.org/wiki/Sorting_algorithms/Counting_sort | Sorting algorithms/Counting 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 | def countSort(input: List[Int], min: Int, max: Int): List[Int] =
input.foldLeft(Array.fill(max - min + 1)(0)) { (arr, n) =>
arr(n - min) += 1
arr
}.zipWithIndex.foldLeft(List[Int]()) {
case (lst, (cnt, ndx)) => List.fill(cnt)(ndx + min) ::: lst
}.reverse |
http://rosettacode.org/wiki/Solve_the_no_connection_puzzle | Solve the no connection puzzle | You are given a box with eight holes labelled A-to-H, connected by fifteen straight lines in the pattern as shown below:
A B
/│\ /│\
/ │ X │ \
/ │/ \│ \
C───D───E───F
\ │\ /│ /
\ │ X │ /
\│/ \│/
G H
You ar... | #Elixir | Elixir | # It solved if connected A and B, connected G and H (according to the video).
# require HLPsolver
adjacent = for i <- -2..2, j <- -2..2, not(i in -1..1 and j in -1..1), do: {i,j}
layout = ~S"""
A - B
/|\ /|\
/ | X | \
/ |/ \| \
C - D - E - F
\ |\ /| /
\ | X | /
\|/ \|/... |
http://rosettacode.org/wiki/Solve_the_no_connection_puzzle | Solve the no connection puzzle | You are given a box with eight holes labelled A-to-H, connected by fifteen straight lines in the pattern as shown below:
A B
/│\ /│\
/ │ X │ \
/ │/ \│ \
C───D───E───F
\ │\ /│ /
\ │ X │ /
\│/ \│/
G H
You ar... | #Factor | Factor | USING: assocs interpolate io kernel math math.combinatorics
math.ranges math.parser multiline pair-rocket sequences
sequences.generalizations ;
STRING: diagram
${} ${}
/|\ /|\
/ | X | \
/ |/ \| \
${} - ${} - ${} - ${}
\ |\ /| /
\ | X | /
\|/ \|/
${} ${}
;
CONSTANT: adjacency
H{
0 => ... |
http://rosettacode.org/wiki/Solve_a_Numbrix_puzzle | Solve a Numbrix puzzle | Numbrix puzzles are similar to Hidato.
The most important difference is that it is only possible to move 1 node left, right, up, or down (sometimes referred to as the Von Neumann neighborhood).
Published puzzles also tend not to have holes in the grid and may not always indicate the end node.
Two examples follow:
Exam... | #Phix | Phix | with javascript_semantics
sequence board, knownx, knowny
integer size, limit, nchars, tries
string fmt, blank
constant ROW = 1, COL = 2
constant moves = {{-1,0},{0,-1},{0,1},{1,0}}
function onboard(integer row, integer col)
return row>=1 and row<=size and col>=nchars and col<=nchars*size
end function
functi... |
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
... | #COBOL | COBOL | PROGRAM-ID. sort-ints.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 array-area VALUE "54321".
03 array PIC 9 OCCURS 5 TIMES.
01 i PIC 9.
PROCEDURE DIVISION.
main-line.
PERFORM display-array
... |
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
... | #Common_Lisp | Common Lisp | CL-USER> (sort #(9 -2 1 2 8 0 1 2) #'<)
#(-2 0 1 1 2 2 8 9) |
http://rosettacode.org/wiki/Sort_a_list_of_object_identifiers | Sort a list of object identifiers |
Sorting Algorithm
This is a sorting algorithm. It may be applied to a set of data in order to sort it.
For comparing various sorts, see compare sorts.
For other sorting algorithms, see sorting algorithms, or:
O(n logn) sorts
Heap sort |
Merge sort |
Patience sort |
Quick sort
O(n log2n) sorts
Shell Sort
... | #jq | jq | def data: [
"1.3.6.1.4.1.11.2.17.19.3.4.0.10",
"1.3.6.1.4.1.11.2.17.5.2.0.79",
"1.3.6.1.4.1.11.2.17.19.3.4.0.4",
"1.3.6.1.4.1.11150.3.4.0.1",
"1.3.6.1.4.1.11.2.17.19.3.4.0.1",
"1.3.6.1.4.1.11150.3.4.0"
];
data | map( split(".") | map(tonumber) ) | sort | map(join(".")) |
http://rosettacode.org/wiki/Sort_a_list_of_object_identifiers | Sort a list of object identifiers |
Sorting Algorithm
This is a sorting algorithm. It may be applied to a set of data in order to sort it.
For comparing various sorts, see compare sorts.
For other sorting algorithms, see sorting algorithms, or:
O(n logn) sorts
Heap sort |
Merge sort |
Patience sort |
Quick sort
O(n log2n) sorts
Shell Sort
... | #Julia | Julia | oidlist = ["1.3.6.1.4.1.11.2.17.19.3.4.0.10",
"1.3.6.1.4.1.11.2.17.5.2.0.79",
"1.3.6.1.4.1.11.2.17.19.3.4.0.4",
"1.3.6.1.4.1.11150.3.4.0.1",
"1.3.6.1.4.1.11.2.17.19.3.4.0.1",
"1.3.6.1.4.1.11150.3.4.0"]
sort!(oidlist; lt=lexless,
by=x -> parse.(Int, String.(sp... |
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
... | #Go | Go | package main
import (
"fmt"
"sort"
)
func main() {
// givens
values := []int{7, 6, 5, 4, 3, 2, 1, 0}
indices := map[int]int{6: 0, 1: 0, 7: 0}
orderedValues := make([]int, len(indices))
orderedIndices := make([]int, len(indices))
i := 0
for j := range indices {
// valida... |
http://rosettacode.org/wiki/Sort_stability | Sort stability |
Sorting Algorithm
This is a sorting algorithm. It may be applied to a set of data in order to sort it.
For comparing various sorts, see compare sorts.
For other sorting algorithms, see sorting algorithms, or:
O(n logn) sorts
Heap sort |
Merge sort |
Patience sort |
Quick sort
O(n log2n) sorts
Shell Sort
... | #REXX | REXX | /*REXX program sorts a (stemmed) array using a (stable) bubble─sort algorithm. */
call gen@ /*generate the array elements (strings)*/
call show 'before sort' /*show the before array elements. */
say copies('▒', 50) ... |
http://rosettacode.org/wiki/Sort_stability | Sort stability |
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 = [["UK", "London"],
["US", "New York"],
["US", "Birmingham"],
["UK", "Birmingham"]]
see sort(aList,2)
|
http://rosettacode.org/wiki/Sort_three_variables | Sort three variables |
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 | with javascript_semantics
object {x,y,z} = {"lions, tigers, and","bears, oh my","(from the \"Wizard of OZ\")"}
?{x,y,z}
{x,y,z} = sort({x,y,z}) ?{x,y,z}
{x,y,z} = {77444,-12,0} ?{x,y,z}
{x,y,z} = sort({x,y,z}) ?{x,y,z}
|
http://rosettacode.org/wiki/Sort_three_variables | Sort three variables |
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
//Sort strings
$x = 'lions, tigers, and';
$y = 'bears, oh my!';
$z = '(from the "Wizard of OZ")';
$items = [$x, $y, $z];
sort($items);
list($x, $y, $z) = $items;
echo <<<EOT
Case 1:
x = $x
y = $y
z = $z
EOT;
//Sort numbers
$x = 77444;
$y = -12;
$z = 0;
$items = [$x, $y, $z];
sort($items);
list($x,... |
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
... | #Kotlin | Kotlin | import java.util.Arrays
fun main(args: Array<String>) {
val strings = arrayOf("Here", "are", "some", "sample", "strings", "to", "be", "sorted")
fun printArray(message: String, array: Array<String>) = with(array) {
print("$message [")
forEachIndexed { index, string ->
print(if (in... |
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
... | #Lua | Lua | test = { "Here", "we", "have", "some", "sample", "strings", "to", "be", "sorted" }
function stringSorter(a, b)
if string.len(a) == string.len(b) then
return string.lower(a) < string.lower(b)
end
return string.len(a) > string.len(b)
end
table.sort(test, stringSorter)
-- print sorted table
for k,v in pairs(test)... |
http://rosettacode.org/wiki/Sorting_algorithms/Comb_sort | Sorting algorithms/Comb sort | Sorting algorithms/Comb sort
You are encouraged to solve this task according to the task description, using any language you may know.
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 algor... | #TI-83_BASIC | TI-83 BASIC | :L1→L2
:dim(L2)→A
:While A>5 and B=0
:int(A/1.3)→A
:1→C
:0→B
:While (C+A)≥dim(L2)
:If L2(C)>L2(C+A)
:Then
:L2(C)→D
:L2(C+A)→L2(C)
:D→L2(C+A)
:1→B
:End
:C+1→C
:End
:DelVar A
:DelVar B
:DelVar C
:DelVar D
:L1→L3
:L2→L1
:prgmSORTINS
:L3→L1
:DelVar L3
:Return
|
http://rosettacode.org/wiki/Sorting_algorithms/Bogosort | Sorting algorithms/Bogosort |
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 performs a type of bogo sort on numbers in an array. */
parse arg list /*obtain optional list from C.L. */
if list='' then list=-21 333 0 444.4 /*Not defined? Then use default.*/
#=words(list) /*the number of numbers in list. */
do i=1 for words... |
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
... | #Elena | Elena | import system'routines;
import extensions;
extension op
{
bubbleSort()
{
var list := self.clone();
bool madeChanges := true;
int itemCount := list.Length;
while (madeChanges)
{
madeChanges := false;
itemCount -= 1;
for(int i := 0, ... |
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
... | #Nim | Nim | proc gnomeSort[T](a: var openarray[T]) =
var
n = a.len
i = 1
j = 2
while i < n:
if a[i-1] > a[i]:
swap a[i-1], a[i]
dec i
if i > 0: continue
i = j
inc j
var a = @[4, 65, 2, -31, 0, 99, 2, 83, 782]
gnomeSort a
echo a |
http://rosettacode.org/wiki/Sorting_algorithms/Bead_sort | Sorting algorithms/Bead 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 | Option Base 1
Private Function sq_add(arr As Variant, x As Double) As Variant
Dim res() As Variant
ReDim res(UBound(arr))
For i = 1 To UBound(arr)
res(i) = arr(i) + x
Next i
sq_add = res
End Function
Private Function beadsort(ByVal a As Variant) As Variant
Dim poles() As Variant
... |
http://rosettacode.org/wiki/Sorting_algorithms/Bead_sort | Sorting algorithms/Bead 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 beadSort = Fn.new { |a|
var res = []
var max = a.reduce { |acc, i| (i > acc) ? i : acc }
var trans = [0] * max
for (i in a) {
for (n in 0...i) trans[n] = trans[n] + 1
}
for (i in a) {
res.add(trans.count { |n| n > 0 })
for (n in 0...trans.count) trans[n] = trans[n] - ... |
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
... | #Maple | Maple | arr := Array([17,3,72,0,36,2,3,8,40,0]):
len := numelems(arr):
swap := proc(arr, a, b)
local temp := arr[a]:
arr[a] := arr[b]:
arr[b] := temp:
end proc:
while(true) do
swapped := false:
for i to len-1 do
if arr[i] > arr[i+1] then:
swap(arr, i, i+1):
swapped := true:
end if:
end do:
if (not swapped) the... |
http://rosettacode.org/wiki/Sokoban | Sokoban | Demonstrate how to find a solution to a given Sokoban level. For the purpose of this task (formally, a PSPACE-complete problem) any method may be used. However a move-optimal or push-optimal (or any other -optimal) solutions is preferred.
Sokoban levels are usually stored as a character array where
space is an empty... | #Befunge | Befunge |
589*+0g"0"-25**689*+0g"0"-+50p v # Sokoban - (c) Matthew Westcott 2000 # 03
83*>10p99*2->:00p10gg"x"-#v_v p01g<> ## # # # # # # # # # # # # # # # # # # #
<< ^ -1g01_^#!: -1g00< > v # # # # # # # # # # # # # # # # # # # # #
|-"8"_v#-"2":_v#-"6":_v#-"4":~< <0 #
> 1 0>$1+2 0>$2+3%\0>$1+3%40v $4<#
v -"0... |
http://rosettacode.org/wiki/Solve_a_Holy_Knight%27s_tour | Solve a Holy Knight's tour |
Chess coaches have been known to inflict a kind of torture on beginners by taking a chess board, placing pennies on some squares and requiring that a Knight's tour be constructed that avoids the squares with pennies.
This kind of knight's tour puzzle is similar to Hidato.
The present task is to produce a solution ... | #Elixir | Elixir | # require HLPsolver
adjacent = [{-1,-2},{-2,-1},{-2,1},{-1,2},{1,2},{2,1},{2,-1},{1,-2}]
"""
. . 0 0 0
. . 0 . 0 0
. 0 0 0 0 0 0 0
0 0 0 . . 0 . 0
0 . 0 . . 0 0 0
1 0 0 0 0 0 0
. . 0 0 . 0
. . . 0 0 0
"""
|> HLPsolver.solve(adjacent)
"""
_ _ _ _ _ 1 _ 0
_ _ _ _ _ 0 _ 0
_ _ _ _ 0 0 0 0 0 ... |
http://rosettacode.org/wiki/Solve_a_Holy_Knight%27s_tour | Solve a Holy Knight's tour |
Chess coaches have been known to inflict a kind of torture on beginners by taking a chess board, placing pennies on some squares and requiring that a Knight's tour be constructed that avoids the squares with pennies.
This kind of knight's tour puzzle is similar to Hidato.
The present task is to produce a solution ... | #Go | Go | package main
import "fmt"
var moves = [][2]int{
{-1, -2}, {1, -2}, {-1, 2}, {1, 2}, {-2, -1}, {-2, 1}, {2, -1}, {2, 1},
}
var board1 = " xxx " +
" x xx " +
" xxxxxxx" +
"xxx x x" +
"x x xxx" +
"sxxxxxx " +
" xx x " +
" xxx "
var board2 = ".....s.x....." +
".....x.... |
http://rosettacode.org/wiki/SOAP | SOAP | In this task, the goal is to create a SOAP client which accesses functions defined at http://example.com/soap/wsdl, and calls the functions soapFunc( ) and anotherSoapFunc( ).
This task has been flagged for clarification. Code on this page in its current state may be flagged incorrect once this task has been clarified... | #F.23 | F# | open Microsoft.FSharp.Data.TypeProviders
type Wsdl = WsdlService<"http://example.com/soap/wsdl">
let result = Wsdl.soapFunc("hello")
let result2 = Wsdl.anotherSoapFunc(34234) |
http://rosettacode.org/wiki/SOAP | SOAP | In this task, the goal is to create a SOAP client which accesses functions defined at http://example.com/soap/wsdl, and calls the functions soapFunc( ) and anotherSoapFunc( ).
This task has been flagged for clarification. Code on this page in its current state may be flagged incorrect once this task has been clarified... | #Go | Go | package main
import (
"fmt"
"github.com/tiaguinho/gosoap"
"log"
)
type CheckVatResponse struct {
CountryCode string `xml:"countryCode"`
VatNumber string `xml:"vatNumber"`
RequestDate string `xml:"requestDate"`
Valid string `xml:"valid"`
Name string `xml:"name"`
Add... |
http://rosettacode.org/wiki/Solve_a_Hopido_puzzle | Solve a Hopido puzzle | Hopido puzzles are similar to Hidato. The most important difference is that the only moves allowed are: hop over one tile diagonally; and over two tiles horizontally and vertically. It should be possible to start anywhere in the path, the end point isn't indicated and there are no intermediate clues. Hopido Design Pos... | #Mathematica.2FWolfram_Language | Mathematica/Wolfram Language | puzz = ".00.00.\n0000000\n0000000\n.00000.\n..000..\n...0...";
puzz //= StringSplit[#, "\n"] & /* Map[Characters];
puzz //= Transpose /* Map[Reverse];
pos = Position[puzz, "0", {2}];
moves = Select[Select[Tuples[pos, 2], MatchQ[EuclideanDistance @@ #, 2 Sqrt[2] | 3] &], OrderedQ];
g = Graph[UndirectedEdge @@@ moves];
o... |
http://rosettacode.org/wiki/Solve_a_Hopido_puzzle | Solve a Hopido puzzle | Hopido puzzles are similar to Hidato. The most important difference is that the only moves allowed are: hop over one tile diagonally; and over two tiles horizontally and vertically. It should be possible to start anywhere in the path, the end point isn't indicated and there are no intermediate clues. Hopido Design Pos... | #Nim | Nim | import algorithm, sequtils, strformat
const Moves = [(-3, 0), (0, 3), ( 3, 0), ( 0, -3),
( 2, 2), (2, -2), (-2, 2), (-2, -2)]
type
Hopido = object
grid: seq[seq[int]]
nRows, nCols: int
totalToFill : Natural
Neighbor = (int, int, int)
proc initHopido(board: openArray[string]):... |
http://rosettacode.org/wiki/Smallest_number_k_such_that_k%2B2%5Em_is_composite_for_all_m_less_than_k | Smallest number k such that k+2^m is composite for all m less than k | Generate the sequence of numbers a(k), where each k is the smallest positive integer such that k + 2m is composite for every positive integer m less than k.
For example
Suppose k == 7; test m == 1 through m == 6. If any are prime, the test fails.
Is 7 + 21 (9) prime? False
Is 7 + 22 (11) prime? True
So 7 is not a... | #Raku | Raku | put (1..∞).hyper(:250batch).map(* × 2 + 1).grep( -> $k { !(1 ..^ $k).first: ($k + 1 +< *).is-prime } )[^5] |
http://rosettacode.org/wiki/Smallest_number_k_such_that_k%2B2%5Em_is_composite_for_all_m_less_than_k | Smallest number k such that k+2^m is composite for all m less than k | Generate the sequence of numbers a(k), where each k is the smallest positive integer such that k + 2m is composite for every positive integer m less than k.
For example
Suppose k == 7; test m == 1 through m == 6. If any are prime, the test fails.
Is 7 + 21 (9) prime? False
Is 7 + 22 (11) prime? True
So 7 is not a... | #Wren | Wren | import "./gmp" for Mpz
// returns true if k is a sequence member, false otherwise
var a = Fn.new { |k|
if (k == 1) return false
for (m in 1...k) {
var n = Mpz.one.lsh(m).add(k)
if (n.probPrime(15) > 0) return false
}
return true
}
var count = 0
var k = 1
while (count < 5) {
if (a... |
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
... | #C.2B.2B | C++ | g++ -std=c++11 sort.cpp
|
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
... | #Clojure | Clojure |
;; Gathered with Google Squared
(def *langs* [["Clojure" 2007] ["Common Lisp" 1984] ["Java" 1995] ["Haskell" 1990]
["Lisp" 1958] ["Scheme" 1975]])
user> (sort-by second *langs*) ; using a keyfn
(["Lisp" 1958] ["Scheme" 1975] ["Common Lisp" 1984] ["Haskell" 1990] ["Java" 1995] ["Clojure" 2007])
|
http://rosettacode.org/wiki/Sorting_algorithms/Counting_sort | Sorting algorithms/Counting 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 counting_sort(a, min, max) {
var cnt = ([0] * (max - min + 1))
a.each {|i| cnt[i-min]++ }
cnt.map {|i| [min++] * i }.flat
}
var a = 100.of { 100.irand }
say counting_sort(a, 0, 100) |
http://rosettacode.org/wiki/Sorting_algorithms/Counting_sort | Sorting algorithms/Counting 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) countingSort &min: min &max: max
[| counts index |
min `defaultsTo: (s reduce: #min: `er).
max `defaultsTo: (s reduce: #max: `er).
counts: ((0 to: max - min) project: [| :_ | 0]).
s do: [| :value | counts at: value - min infect: [| :count | count + 1]].
index: 0.
min to: max do: [| :valu... |
http://rosettacode.org/wiki/Solve_the_no_connection_puzzle | Solve the no connection puzzle | You are given a box with eight holes labelled A-to-H, connected by fifteen straight lines in the pattern as shown below:
A B
/│\ /│\
/ │ X │ \
/ │/ \│ \
C───D───E───F
\ │\ /│ /
\ │ X │ /
\│/ \│/
G H
You ar... | #Fortran | Fortran | ! This is free and unencumbered software released into the public domain,
! via the Unlicense.
! For more information, please refer to <http://unlicense.org/>
program no_connection_puzzle
implicit none
! The names of the holes.
integer, parameter :: a = 1
integer, parameter :: b = 2
integer, parameter :... |
http://rosettacode.org/wiki/Solve_a_Numbrix_puzzle | Solve a Numbrix puzzle | Numbrix puzzles are similar to Hidato.
The most important difference is that it is only possible to move 1 node left, right, up, or down (sometimes referred to as the Von Neumann neighborhood).
Published puzzles also tend not to have holes in the grid and may not always indicate the end node.
Two examples follow:
Exam... | #Prolog | Prolog | /*
* Solver
*/
solve([A|T]) :-
numlist(1,81,S),
select(A,S,R),
solve_([A|T],R).
solve_([_],[]).
solve_([A,B|T],R) :-
move(A,B),
select(B,R,Rt),
solve_([B|T],Rt).
move(A,B) :- lr(A,B) ; lr(B,A) ; ud(A,B) ; ud(B,A).
% create the left-right mapping rules at compile time
term_expansion(lr(0,0),LrList) :-
f... |
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
... | #Crystal | Crystal |
a = [5, 4, 3, 2, 1]
puts a.sort
# => [1, 2, 3, 4, 5]
puts a
# => [5, 4, 3, 2, 1]
a.sort!
puts a
# => [1, 2, 3, 4, 5]
|
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
... | #D | D | import std.stdio, std.algorithm;
void main() {
auto data = [2, 4, 3, 1, 2];
data.sort(); // in-place
assert(data == [1, 2, 2, 3, 4]);
} |
http://rosettacode.org/wiki/Sort_a_list_of_object_identifiers | Sort a list of object identifiers |
Sorting Algorithm
This is a sorting algorithm. It may be applied to a set of data in order to sort it.
For comparing various sorts, see compare sorts.
For other sorting algorithms, see sorting algorithms, or:
O(n logn) sorts
Heap sort |
Merge sort |
Patience sort |
Quick sort
O(n log2n) sorts
Shell Sort
... | #Kotlin | Kotlin | // version 1.0.6
class Oid(val id: String): Comparable<Oid> {
override fun compareTo(other: Oid): Int {
val splits1 = this.id.split('.')
val splits2 = other.id.split('.')
val minSize = if (splits1.size < splits2.size) splits1.size else splits2.size
for (i in 0 until minSize) {
... |
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
... | #Groovy | Groovy | def sparseSort = { a, indices = ([] + (0..<(a.size()))) ->
indices.sort().unique()
a[indices] = a[indices].sort()
a
} |
http://rosettacode.org/wiki/Sort_stability | Sort stability |
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 | ary = [["UK", "London"],
["US", "New York"],
["US", "Birmingham"],
["UK", "Birmingham"]]
p ary.sort {|a,b| a[1] <=> b[1]}
# MRI reverses the Birminghams:
# => [["UK", "Birmingham"], ["US", "Birmingham"], ["UK", "London"], ["US", "New York"]] |
http://rosettacode.org/wiki/Sort_stability | Sort stability |
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 main() {
let country_city = [
("UK", "London"),
("US", "New York"),
("US", "Birmingham"),
("UK", "Birmingham"),
];
let mut city_sorted = country_city.clone();
city_sorted.sort_by_key(|k| k.1);
let mut country_sorted = country_city.clone();
country_sorted.so... |
http://rosettacode.org/wiki/Sort_stability | Sort stability |
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 | scala> val list = List((1, 'c'), (1, 'b'), (2, 'a'))
list: List[(Int, Char)] = List((1,c), (1,b), (2,a))
scala> val srt1 = list.sortWith(_._2 < _._2)
srt1: List[(Int, Char)] = List((2,a), (1,b), (1,c))
scala> val srt2 = srt1.sortBy(_._1) // Ordering[Int] is implicitly defined
srt2: List[(Int, Char)] = List((1,b), (... |
http://rosettacode.org/wiki/Sort_three_variables | Sort three variables |
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 | (let (X 77444 Y -12 Z 0)
(println X Y Z)
(mapc set '(X Y Z) (sort (list X Y Z)))
(println X Y Z) ) |
http://rosettacode.org/wiki/Sort_three_variables | Sort three variables |
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
... | #Plain_English | Plain English | To run:
Start up.
Sort three numbers.
Wait for the escape key.
Shut down.
To sort three numbers:
Put 77444 into an x number.
Put -12 into a y number.
Put 0 into a z number.
Write "===Before sorting===" on the console.
Write "x: " then the x on the console.
Write "y: " then the y on the console.
Write "z: " then the z... |
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
... | #M2000_Interpreter | M2000 Interpreter |
Module Checkit {
Class Quick {
Private:
partition=lambda-> {
Read &A(), p, r : i = p-1 : x=A(r)
For j=p to r-1 {If .LE(A(j), x) Then i++:Swap A(i),A(j)
} : Swap A(i+1), A(r) : Push i+2, i
}
Public:
LE=Lambda->Numb... |
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
... | #Maple | Maple | Compare_fn:= proc(s1, s2)
local len1, len2;
len1 := StringTools:-Length(s1);
len2 := StringTools:-Length(s2);
if (len1 > len2) then
return true;
elif (len1 < len2) then
return false;
else # ascending lexicographic order for strings of equal length / case insensitive
StringTools:-CompareCI(s1, s2);
end if;
... |
http://rosettacode.org/wiki/Sorting_algorithms/Comb_sort | Sorting algorithms/Comb sort | Sorting algorithms/Comb sort
You are encouraged to solve this task according to the task description, using any language you may know.
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 algor... | #uBasic.2F4tH | uBasic/4tH | PRINT "Comb sort:"
n = FUNC (_InitArray)
PROC _ShowArray (n)
PROC _Combsort (n)
PROC _ShowArray (n)
PRINT
END
_Combsort PARAM (1) ' Combsort subroutine
LOCAL(4)
b@ = a@
c@ = 1
DO WHILE (b@ > 1) + c@
b@ = (b@ * 10) / 13
IF (b@ = 9) + (b@ = 10) THEN b@ = 11
IF b@... |
http://rosettacode.org/wiki/Sorting_algorithms/Bogosort | Sorting algorithms/Bogosort |
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 |
# Project : Sorting algorithms/Bogosort
test = [4, 65, 2, 31, 0, 99, 2, 83, 782, 1]
shuffles = 0
while ! sorted(test)
shuffles = shuffles + 1
shuffle(test)
end
see "" + shuffles + " shuffles required to sort " + len(test) + " items:" + nl
showarray(test)
func shuffle(d)
for i = len(d) to... |
http://rosettacode.org/wiki/Sorting_algorithms/Bogosort | Sorting algorithms/Bogosort |
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 | def shuffle(l)
l.sort_by { rand }
end
def bogosort(l)
l = shuffle(l) until in_order(l)
l
end
def in_order(l)
(0..l.length-2).all? {|i| l[i] <= l[i+1] }
end |
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
... | #Elixir | Elixir | defmodule Sort do
def bsort(list) when is_list(list) do
t = bsort_iter(list)
if t == list, do: t, else: bsort(t)
end
def bsort_iter([x, y | t]) when x > y, do: [y | bsort_iter([x | t])]
def bsort_iter([x, y | t]), do: [x | bsort_iter([y | t])]
def bsort_iter(list), do: list
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
... | #Objeck | Objeck |
function : GnomeSort(a : Int[]) {
i := 1;
j := 2;
while(i < a->Size()) {
if (a[i-1] <= a[i]) {
i := j;
j += 1;
}
else {
tmp := a[i-1];
a[i-1] := a[i];
a[i] := tmp;
i -= 1;
if(i = 0) {
i := j;
j += 1;
};
};
};
}
|
http://rosettacode.org/wiki/Sorting_algorithms/Bead_sort | Sorting algorithms/Bead 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 | include c:\cxpl\codes;
proc BeadSort(Array, Length); \Sort Array into increasing order
int Array, Length; \Array contents range 0..31; number of items
int Row, I, J, T, C;
[Row:= Reserve(Length*4); \each Row has room for 32 beads
for I:= 0 to Length-1 do \each Row gets Array(I) number of ... |
http://rosettacode.org/wiki/Sorting_algorithms/Bead_sort | Sorting algorithms/Bead 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 columns(m){ // m is list of lists of zeros/beads, # beads is n, eg (0,0,0)==3
m
.apply("len") // (0,0,0)-->3
.reduce("max") // largest bead stack
.walker() // [0..max]
.apply('wrap(i){ m.filter('wrap(s){ s.len() > i }).len().pump(List,0) });
}
fcn beadSort(data){
data.apply("pump",List,... |
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
... | #Mathematica.2FWolfram_Language | Mathematica/Wolfram Language | cocktailSort[A_List] := Module[ { swapped = True },
While[ swapped == True,
swapped=False;
For[ i = 1, i< Length[A]-1,i++,
If[ A[[i]] > A[[i+1]], A[[i;;i+1]] = A[[i+1;;i;;-1]]; swapped=True;]
];
If[swapped == False, Break[]];
swapped=False;
For [ i= Length[A]-1, i > 0, i--,
If[ A[[i]] > A[[i+1]], A[[i;;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.
| #Ada | Ada | with GNAT.Sockets; use GNAT.Sockets;
procedure Socket_Send is
Client : Socket_Type;
begin
Initialize;
Create_Socket (Socket => Client);
Connect_Socket (Socket => Client,
Server => (Family => Family_Inet,
Addr => Inet_Addr ("127.0.0.1"),
... |
http://rosettacode.org/wiki/Smarandache_prime-digital_sequence | Smarandache prime-digital sequence | The Smarandache prime-digital sequence (SPDS for brevity) is the sequence of primes whose digits are themselves prime.
For example 257 is an element of this sequence because it is prime itself and its digits: 2, 5 and 7 are also prime.
Task
Show the first 25 SPDS primes.
Show the hundredth SPDS prime.
See also
... | #11l | 11l | F divisors(n)
V divs = [1]
L(ii) 2 .< Int(n ^ 0.5) + 3
I n % ii == 0
divs.append(ii)
divs.append(Int(n / ii))
divs.append(n)
R Array(Set(divs))
F is_prime(n)
R divisors(n).len == 2
F digit_check(n)
I String(n).len < 2
R 1B
E
L(digit) String(n)
I !is_... |
http://rosettacode.org/wiki/Sokoban | Sokoban | Demonstrate how to find a solution to a given Sokoban level. For the purpose of this task (formally, a PSPACE-complete problem) any method may be used. However a move-optimal or push-optimal (or any other -optimal) solutions is preferred.
Sokoban levels are usually stored as a character array where
space is an empty... | #C | C | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <stdint.h>
#include <assert.h>
#include <stdbool.h>
int w, h, n_boxes;
uint8_t *board, *goals, *live;
typedef uint16_t cidx_t;
typedef uint32_t hash_t;
/* board configuration is represented by an array of cell indices
of pl... |
http://rosettacode.org/wiki/Solve_a_Holy_Knight%27s_tour | Solve a Holy Knight's tour |
Chess coaches have been known to inflict a kind of torture on beginners by taking a chess board, placing pennies on some squares and requiring that a Knight's tour be constructed that avoids the squares with pennies.
This kind of knight's tour puzzle is similar to Hidato.
The present task is to produce a solution ... | #Haskell | Haskell | import Data.Array
(Array, (//), (!), assocs, elems, bounds, listArray)
import Data.Foldable (forM_)
import Data.List (intercalate, transpose)
import Data.Maybe
type Position = (Int, Int)
type KnightBoard = Array Position (Maybe Int)
toSlot :: Char -> Maybe Int
toSlot '0' = Just 0
toSlot '1' = Just 1
toSlot... |
http://rosettacode.org/wiki/SOAP | SOAP | In this task, the goal is to create a SOAP client which accesses functions defined at http://example.com/soap/wsdl, and calls the functions soapFunc( ) and anotherSoapFunc( ).
This task has been flagged for clarification. Code on this page in its current state may be flagged incorrect once this task has been clarified... | #Icon_and_Unicon | Icon and Unicon | import soap
procedure main(A)
soap := SoapClient(A[1] | "http://example.com/soap/wsdl") # Allow override of default
write("soapFunc: ",soap.call("soapFunc"))
write("anotherSoapFunc: ",soap.call("anotherSoapFunc"))
end |
http://rosettacode.org/wiki/SOAP | SOAP | In this task, the goal is to create a SOAP client which accesses functions defined at http://example.com/soap/wsdl, and calls the functions soapFunc( ) and anotherSoapFunc( ).
This task has been flagged for clarification. Code on this page in its current state may be flagged incorrect once this task has been clarified... | #Julia | Julia | using LibCURL
function callSOAP(url, infilename, outfilename)
rfp = open(infilename, "r")
wfp = open(outfilename, "w+")
header = curl_slist_append(header, "Content-Type:text/xml")
header = curl_slist_append(header, "SOAPAction: rsc");
header = curl_slist_append(header, "Transfer-Encoding: chunke... |
http://rosettacode.org/wiki/SOAP | SOAP | In this task, the goal is to create a SOAP client which accesses functions defined at http://example.com/soap/wsdl, and calls the functions soapFunc( ) and anotherSoapFunc( ).
This task has been flagged for clarification. Code on this page in its current state may be flagged incorrect once this task has been clarified... | #Kotlin | Kotlin | // libcurl.def
headers = /usr/include/curl/curl.h
linkerOpts.linux = -L/usr/lib/x86_64-linux-gnu -lcurl
|
http://rosettacode.org/wiki/SOAP | SOAP | In this task, the goal is to create a SOAP client which accesses functions defined at http://example.com/soap/wsdl, and calls the functions soapFunc( ) and anotherSoapFunc( ).
This task has been flagged for clarification. Code on this page in its current state may be flagged incorrect once this task has been clarified... | #Mathematica.2FWolfram_Language | Mathematica/Wolfram Language | InstallService["http://example.com/soap/wsdl"];
soapFunc["Hello"];
anotherSoapFunc[12345]; |
http://rosettacode.org/wiki/Solve_a_Hopido_puzzle | Solve a Hopido puzzle | Hopido puzzles are similar to Hidato. The most important difference is that the only moves allowed are: hop over one tile diagonally; and over two tiles horizontally and vertically. It should be possible to start anywhere in the path, the end point isn't indicated and there are no intermediate clues. Hopido Design Pos... | #Perl | Perl | #!/usr/bin/perl
use strict; # http://www.rosettacode.org/wiki/Solve_a_Hopido_puzzle
use warnings;
$_ = do { local $/; <DATA> };
s/./$&$&/g; # double chars
my $w = /\n/ && $-[0];
my $wd = 3 * $w + 1; # vertical gap
my $wr = 2 * $w + 8; # down right gap
my $wl = 2 * $w - 8; # down lef... |
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
... | #Common_Lisp | Common Lisp | CL-USER> (defparameter *test-scores* '(("texas" 68.9) ("ohio" 87.8) ("california" 76.2) ("new york" 88.2)) )
*TEST-SCORES* |
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
... | #D | D | import std.stdio, std.algorithm;
struct Pair { string name, value; }
void main() {
Pair[] pairs = [{"Joe", "5531"},
{"Adam", "2341"},
{"Bernie", "122"},
{"Walter", "1234"},
{"David", "19"}];
pairs.schwartzSort!q{ a.na... |
http://rosettacode.org/wiki/Sorting_algorithms/Counting_sort | Sorting algorithms/Counting 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 [
countingSortWithMin: min andMax: max [
|oc z|
oc := OrderedCollection new.
1 to: (max - min + 1) do: [ :n| oc add: 0 ].
self do: [ :v |
oc at: (v - min + 1) put: ( (oc at: (v - min + 1)) + 1)
].
z := 1.
min to: max do: [ :i |
1 to: (oc at: (i - min + 1)) do: [ :k |
self... |
http://rosettacode.org/wiki/Solve_the_no_connection_puzzle | Solve the no connection puzzle | You are given a box with eight holes labelled A-to-H, connected by fifteen straight lines in the pattern as shown below:
A B
/│\ /│\
/ │ X │ \
/ │/ \│ \
C───D───E───F
\ │\ /│ /
\ │ X │ /
\│/ \│/
G H
You ar... | #Go | Go | package main
import (
"fmt"
"strings"
)
func main() {
p, tests, swaps := Solution()
fmt.Println(p)
fmt.Println("Tested", tests, "positions and did", swaps, "swaps.")
}
// Holes A=0, B=1, …, H=7
// With connections:
const conn = `
A B
/|\ /|\
/ | X | \
/ |/ \| \
C - D - E - F
... |
http://rosettacode.org/wiki/Solve_a_Numbrix_puzzle | Solve a Numbrix puzzle | Numbrix puzzles are similar to Hidato.
The most important difference is that it is only possible to move 1 node left, right, up, or down (sometimes referred to as the Von Neumann neighborhood).
Published puzzles also tend not to have holes in the grid and may not always indicate the end node.
Two examples follow:
Exam... | #Python | Python |
from sys import stdout
neighbours = [[-1, 0], [0, -1], [1, 0], [0, 1]]
exists = []
lastNumber = 0
wid = 0
hei = 0
def find_next(pa, x, y, z):
for i in range(4):
a = x + neighbours[i][0]
b = y + neighbours[i][1]
if wid > a > -1 and hei > b > -1:
if pa[a][b] == z:
... |
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
... | #Delphi | Delphi | uses Types, Generics.Collections;
var
a: TIntegerDynArray;
begin
a := TIntegerDynArray.Create(5, 4, 3, 2, 1);
TArray.Sort<Integer>(a);
end; |
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
... | #DWScript | DWScript | var a : array of Integer := [5, 4, 3, 2, 1];
a.Sort; // ascending natural sort
PrintLn(a.Map(IntToStr).Join(',')); // 1,2,3,4,5 |
http://rosettacode.org/wiki/Sort_a_list_of_object_identifiers | Sort a list of object identifiers |
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 | local OIDs = {
"1.3.6.1.4.1.11.2.17.19.3.4.0.10",
"1.3.6.1.4.1.11.2.17.5.2.0.79",
"1.3.6.1.4.1.11.2.17.19.3.4.0.4",
"1.3.6.1.4.1.11150.3.4.0.1",
"1.3.6.1.4.1.11.2.17.19.3.4.0.1",
"1.3.6.1.4.1.11150.3.4.0"
}
function compare (a, b)
local aList, bList, Na, Nb = {}, {}
for num in a:gmatch... |
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
... | #Haskell | Haskell | import Control.Monad
import qualified Data.Array as A
import Data.Array.IArray
import Data.Array.ST
import Data.List
import Data.List.Utils
-- Partition 'xs' according to whether their element indices are in 'is'. Sort
-- the sublist corresponding to 'is', merging the result with the remainder of
-- the list.
disSor... |
http://rosettacode.org/wiki/Sort_stability | Sort stability |
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 | var table = [
<UK London>,
<US New\ York>,
<US Birmingham>,
<UK Birmingham>,
];
table.sort {|a,b| a[0] <=> b[0]}.each { |col|
say "#{col[0]} #{col[1]}"
} |
http://rosettacode.org/wiki/Sort_stability | Sort stability |
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
... | #Stata | Stata | import "/sort" for Cmp, Sort
var data = [ ["UK", "London"], ["US", "New York"], ["US", "Birmingham"], ["UK", "Birmingham"] ]
// for sorting by country
var cmp = Fn.new { |p1, p2| Cmp.string.call(p1[0], p2[0]) }
// for sorting by city
var cmp2 = Fn.new { |p1, p2| Cmp.string.call(p1[1], p2[1]) }
System.print("Ini... |
http://rosettacode.org/wiki/Sort_three_variables | Sort three variables |
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 | ;sort three variables: x, y, z
;Macro handles any of the native types, including integers, floating point, and strings
;because the variable types are not declared but substituted during each instance of the macro.
;The sorting is in ascending order, i.e. x < y < z.
Macro sort3vars(x, y, z)
If x > y: Swap x, y: End... |
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
... | #Mathematica.2FWolfram_Language | Mathematica/Wolfram Language | StringOrderQ[x_String, y_String] :=
If[StringLength[x] == StringLength[y],
OrderedQ[{x, y}],
StringLength[x] >StringLength[y]
]
words={"on","sunday","sander","sifted","and","sorted","sambaa","for","a","second"};
Sort[words,StringOrderQ] |
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
... | #Maxima | Maxima | strangeorderp(a, b) := slength(a) > slength(b) or (slength(a) = slength(b) and orderlessp(a, b))$
s: tokens("Lorem ipsum dolor sit amet consectetur adipiscing elit Sed non risus Suspendisse\
lectus tortor dignissim sit amet adipiscing nec ultricies sed dolor")$
sort(s, strangeorderp);
["Suspendisse", "consectetur", ... |
http://rosettacode.org/wiki/Sorting_algorithms/Comb_sort | Sorting algorithms/Comb sort | Sorting algorithms/Comb sort
You are encouraged to solve this task according to the task description, using any language you may know.
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 algor... | #VBA | VBA | Function comb_sort(ByVal s As Variant) As Variant
Dim gap As Integer: gap = UBound(s)
Dim swapped As Integer
Do While True
gap = WorksheetFunction.Max(WorksheetFunction.Floor_Precise(gap / 1.3), 1)
swapped = False
For i = 0 To UBound(s) - gap
si = Val(s(i))
If... |
http://rosettacode.org/wiki/Sorting_algorithms/Bogosort | Sorting algorithms/Bogosort |
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 | extern crate rand;
use rand::Rng;
fn bogosort_by<T,F>(order: F, coll: &mut [T])
where F: Fn(&T, &T) -> bool
{
let mut rng = rand::thread_rng();
while !is_sorted_by(&order, coll) {
rng.shuffle(coll);
}
}
#[inline]
fn is_sorted_by<T,F>(order: F, coll: &[T]) -> bool
where F: Fn(&T,&T) -> bo... |
http://rosettacode.org/wiki/Sorting_algorithms/Bogosort | Sorting algorithms/Bogosort |
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 | def isSorted(l: List[Int]) = l.iterator sliding 2 forall (s => s.head <= s.last)
def bogosort(l: List[Int]): List[Int] = if (isSorted(l)) l else bogosort(scala.util.Random.shuffle(l)) |
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
... | #Erlang | Erlang |
-module( bubble_sort ).
-export( [list/1, task/0] ).
list( To_be_sorted ) -> sort( To_be_sorted, [], true ).
task() ->
List = "asdqwe123",
Sorted = list( List ),
io:fwrite( "List ~p is sorted ~p~n", [List, Sorted] ).
sort( [], Acc, true ) -> lists:reverse( Acc );
sort( [], Acc, false ) -> sort( lists:rev... |
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
... | #OCaml | OCaml | # let gnome_sort a =
let i = ref 1
and j = ref 2 in
while !i < Array.length a do
if a.(!i-1) <= a.(!i) then
begin
i := !j;
j := !j + 1;
end else begin
swap a (!i-1) (!i);
i := !i - 1;
if !i = 0 then begin
i := !j;
j := !j + 1;
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.