task_url
stringlengths
30
116
task_name
stringlengths
2
86
task_description
stringlengths
0
14.4k
language_url
stringlengths
2
53
language_name
stringlengths
1
52
code
stringlengths
0
61.9k
http://rosettacode.org/wiki/Sorting_algorithms/Cocktail_sort
Sorting algorithms/Cocktail sort
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#MATLAB_.2F_Octave
MATLAB / Octave
function list = cocktailSort(list)   %We have to do this because the do...while loop doesn't exist in MATLAB swapped = true;   while swapped   %Bubble sort down the list swapped = false; for i = (1:numel(list)-1) if( list(i) > list(i+1) ) list([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.
#Aime
Aime
file i, o; tcpip_connect(i, o, "127.0.0.1", 256, 0); i.text("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.
#AutoHotkey
AutoHotkey
Network_Port = 256 Network_Address = 127.0.0.1 NewData := false DataReceived = GoSub, Connection_Init SendData(socket,"hello socket world") return   Connection_Init: OnExit, ExitSub   socket := ConnectToAddress(Network_Address, Network_Port) if socket = -1 ExitApp   Process, Exist DetectHiddenWindows On ScriptMainW...
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 ...
#Action.21
Action!
INCLUDE "D2:REAL.ACT" ;from the Action! Tool Kit   BYTE FUNC IsZero(REAL POINTER a) CHAR ARRAY s(10)   StrR(a,s) IF s(0)=1 AND s(1)='0 THEN RETURN (1) FI RETURN (0)   CARD FUNC MyMod(CARD a,b) REAL ar,br,dr CARD d,m   IF a>32767 THEN  ;Built-in DIV and MOD  ;do not work properly  ;for numbers...
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 ...
#ALGOL_68
ALGOL 68
# find elements of the Smarandache prime-digital sequence - primes whose # # digits are all primes # # Uses the observations that the final digit of 2 or more digit Smarandache # # primes must be 3 or 7 and the only prime digits are 2, 3, 5 and 7 # # Needs ...
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.23
C#
using System.Collections.Generic; using System.Linq; using System.Text;   namespace SokobanSolver { public class SokobanSolver { private class Board { public string Cur { get; internal set; } public string Sol { get; internal set; } public int X { get; interna...
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 ...
#Icon_and_Unicon
Icon and Unicon
global nCells, cMap, best record Pos(r,c)   procedure main(A) puzzle := showPuzzle("Input",readPuzzle()) QMouse(puzzle,findStart(puzzle),&null,0) showPuzzle("Output", solvePuzzle(puzzle)) | write("No solution!") end   procedure readPuzzle() # Start with a reduced puzzle space p := [[-1],[-1]] nC...
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...
#Perl
Perl
use SOAP::Lite;   print SOAP::Lite -> service('http://example.com/soap/wsdl') -> soapFunc("hello"); print SOAP::Lite -> service('http://example.com/soap/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...
#Phix
Phix
-- -- demo\rosetta\SOAP.exw -- ===================== -- -- translated from https://gist.github.com/p120ph37/8281362ae9da042f3043 -- without js -- (libcurl) include builtins\libcurl.e include builtins\xml.e -- xml_encode() function write_callback(atom pData, integer size, nmemb, atom /*pUserdata*/) integer by...
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...
#Phix
Phix
with javascript_semantics sequence board integer limit, tries constant ROW = 1, COL = 2 constant moves = {{-2,-2},{-2,2},{2,-2},{2,2},{-3,0},{3,0},{0,-3},{0,3}} function solve(integer row, integer col, integer n) integer nrow, ncol tries+= 1 if n>limit then return 1 end if for move=1 to length(moves) ...
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 ...
#Delphi
Delphi
program SortCompositeStructures;   {$APPTYPE CONSOLE}   uses SysUtils, Generics.Collections, Generics.Defaults;   type TStructurePair = record name: string; value: string; constructor Create(const aName, aValue: string); end;   constructor TStructurePair.Create(const aName, aValue: string); begin name...
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 ...
#Tcl
Tcl
proc countingsort {a {min ""} {max ""}} { # If either of min or max weren't given, compute them now if {$min eq ""} { set min [::tcl::mathfunc::min $a] } if {$max eq ""} { set max [::tcl::mathfunc::max $a] }   # Make the "array" of counters set count [lrepeat [expr {$max - $m...
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...
#Groovy
Groovy
import java.util.stream.Collectors import java.util.stream.IntStream   class NoConnection { // adopted from Go static int[][] links = [ [2, 3, 4], // A to C,D,E [3, 4, 5], // B to D,E,F [2, 4], // D to C, E [5], // E to F [2, 3, 4], // G to C,...
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...
#Racket
Racket
#lang racket ;;; Used in my solutions of: ;;; "Solve a Hidato Puzzle" ;;; "Solve a Holy Knights Tour" ;;; "Solve a Numbrix Puzzle" ;;; "Solve a Hopido Puzzle"   ;;; As well as the solver being common, the solution renderer and input formats are common (provide  ;; Input: list of neighbour offsets  ;; Output: a solver ...
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...
#Raku
Raku
my @adjacent = [-1, 0], [ 0, -1], [ 0, 1], [ 1, 0]; put "\n" xx 60;   solveboard q:to/END/; __ __ __ __ __ __ __ __ __ __ __ 46 45 __ 55 74 __ __ __ 38 __ __ 43 __ __ 78 __ __ 35 __ __ __ __ __ 71 __ __ __ 33 __ __ __ 59 __ __ __ 17 __ _...
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.C3.A9j.C3.A0_Vu
Déjà Vu
!. sort [ 5 4 3 2 1 ]
http://rosettacode.org/wiki/Sort_an_integer_array
Sort an integer array
Sorting Algorithm This is a sorting algorithm.   It may be applied to a set of data in order to sort it.     For comparing various sorts, see compare sorts.   For other sorting algorithms,   see sorting algorithms,   or: O(n logn) sorts Heap sort | Merge sort | Patience sort | Quick sort O(n log2n) sorts Shell Sort ...
#E
E
[2,4,3,1,2].sort()
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 ...
#M2000_Interpreter
M2000 Interpreter
  Module CheckIt { Flush ' empty stack of values Data "1.3.6.1.4.1.11.2.17.19.3.4.0.4" , "1.3.6.1.4.1.11.2.17.19.3.4.0.1", "1.3.6.1.4.1.11150.3.4.0.1" 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.11150.3.4.0" \\ Inventories of type queue can get same ke...
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 ...
#Mathematica_.2F_Wolfram_Language
Mathematica / Wolfram Language
in = {"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"}; in = StringSplit[#, "."] & /@ in; in = Map[ToExpression, in, {2}]; Column[StringRiffle[ToString /@ #, "."] & /...
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 ...
#Icon_and_Unicon
Icon and Unicon
  link sort # get the 'isort' procedure for sorting a list   procedure sortDisjoint (items, indices) indices := isort (indices) # sort indices into a list result := copy (items) values := [] every put (values, result[!indices]) values := isort (values) every result[!indices] := pop (values) return result ...
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 ...
#Tcl
Tcl
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_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 ...
#TXR
TXR
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 ...
#Python
Python
  #python2 Code for Sorting 3 values a= raw_input("Enter values one by one ..\n1.").strip() b=raw_input("2.").strip() c=raw_input("3.").strip() if a>b : a,b = b,a if a>c: a,c = c,a if b>c: b,c = c,b print(str(a)+" "+str(b)+" "+str(c))  
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 ...
#Quackery
Quackery
[ stack ] is x [ stack ] is y [ stack ] is z   $ 'lions, tigers, and' x put $ 'bears, oh my!' y put $ '(from the "Wizard of OZ")' z put   x take y take z take 3 pack sortwith $> unpack z put y put x put   say " x = " x take echo$ cr say " y = " y take echo$ cr say " z = " z ta...
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 ...
#MAXScript
MAXScript
fn myCmp str1 str2 = ( case of ( (str1.count < str2.count): 1 (str1.count > str2.count): -1 default:( -- String compare is case sensitive, name compare isn't. Hence... str1 = str1 as name str2 = str2 as name case of ...
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 ...
#min
min
("Here" "are" "some" "sample" "strings" "to" "be" "sorted") (((length) (length)) spread <) sort print
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...
#Vlang
Vlang
fn main() { mut a := [170, 45, 75, -90, -802, 24, 2, 66] println("before: $a") comb_sort(mut a) println("after: $a") }   fn comb_sort(mut a []int) { if a.len < 2 { return } for gap := a.len; ; { if gap > 1 { gap = gap * 4 / 5 } mut swapped := false...
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 ...
#Sidef
Sidef
func in_order(a) { return true if (a.len <= 1); var first = a[0]; a.ft(1).all { |elem| first <= elem  ? do { first = elem; true } : false } }   func bogosort(a) { a.shuffle! while !in_order(a); return a; }   var arr = 5.of{ 100.rand.int }; say "Before: #{arr}"; say "After: #{bogosort(arr)}";
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 ...
#ERRE
ERRE
  PROGRAM BUBBLE_SORT   DIM FLIPS%,N,J   DIM A%[100]   BEGIN   ! init random number generator RANDOMIZE(TIMER) ! fills array A% with random data FOR N=1 TO UBOUND(A%,1) DO A%[N]=RND(1)*256 END FOR ! sort array FLIPS%=TRUE WHILE FLIPS% DO FLIPS%=FALSE FOR N=1 TO UBOUND(A%,1)-1 DO IF...
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 ...
#Octave
Octave
function s = gnomesort(v) i = 2; j = 3; while ( i <= length(v) ) if ( v(i-1) <= v(i) ) i = j; j++; else t = v(i-1); v(i-1) = v(i); v(i) = t; i--; if ( i == 1 ) i = j; j++; endif endif endwhile s = v; endfunction
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 ...
#MAXScript
MAXScript
fn cocktailSort arr = ( local swapped = true while swapped do ( swapped = false for i in 1 to (arr.count-1) do ( if arr[i] > arr[i+1] then ( swap arr[i] arr[i+1] swapped = true ) ) if not swapped then...
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.
#AutoIt
AutoIt
Func _HelloWorldSocket() TCPStartup() $Socket = TCPConnect("127.0.0.1", 256) TCPSend($Socket, "Hello World") TCPCloseSocket($Socket) TCPShutdown() EndFunc
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.
#AWK
AWK
BEGIN { s="/inet/tcp/256/0/0" print strftime() |& s close(s) }  
http://rosettacode.org/wiki/Sleeping_Beauty_problem
Sleeping Beauty problem
Background on the task In decision theory, The Sleeping Beauty Problem is a problem invented by Arnold Zoboff and first publicized on Usenet. The experimental subject, named Sleeping Beauty, agrees to an experiment as follows: Sleeping Beauty volunteers to be put into a deep sleep on a Sunday. There is then a fair coin...
#11l
11l
F sleeping_beauty_experiment(repetitions) ‘ Run the Sleeping Beauty Problem experiment `repetitions` times, checking to see how often we had heads on waking Sleeping Beauty. ’ V gotheadsonwaking = 0 V wakenings = 0 L 0 .< repetitions V coin_result = random:choice([‘heads’, ‘tails’])   ...
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 ...
#AWK
AWK
  # syntax: GAWK -f SMARANDACHE_PRIME-DIGITAL_SEQUENCE.AWK BEGIN { limit = 25 printf("1-%d:",limit) while (1) { if (is_prime(++n)) { if (all_digits_prime(n) == 1) { if (++count <= limit) { printf(" %d",n) } if (count == 100) { printf("\n%d:...
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 ...
#BASIC256
BASIC256
arraybase 1 dim smar(100) smar[1] = 2   cont = 1 i = 1   print 1, 2 while cont < 100 i += 2 if not isPrime(i) then continue while for j = 1 to length(string(i)) digit = int(mid(string(i),j,1)) if not isPrime(digit) then continue while next j cont += 1 smar[cont] = i if cont = 100 or cont <= 25 then print con...
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.2B.2B
C++
#include <iostream> #include <string> #include <vector> #include <queue> #include <regex> #include <tuple> #include <set> #include <array> using namespace std;   class Board { public: vector<vector<char>> sData, dData; int px, py;   Board(string b) { regex pattern("([^\\n]+)\\n?"); sregex_iterator end, ...
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 ...
#J
J
9!:21]2^34   unpack=:verb define mask=. +./' '~:y board=. (255 0 1{a.) {~ {.@:>:@:"."0 mask#"1 y )   ex1=:unpack ];._2]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 1 0 0 0 0 0 0 0 0 0 0 0 0 )   solve=:verb define board=.,:y for_move.1+i.+/({.a.)=,y do. board=. ;move <...
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...
#PHP
PHP
<?php //load the wsdl file $client = new SoapClient("http://example.com/soap/definition.wsdl"); //functions are now available to be called $result = $client->soapFunc("hello"); $result = $client->anotherSoapFunc(34234);   //SOAP Information $client = new SoapClient("http://example.com/soap/definition.wsdl"); //list of ...
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...
#PureBasic
PureBasic
  XIncludeFile "COMatePLUS.pbi" Define.COMateObject soapObject = COMate_CreateObject("MSSOAP.SoapClient") soapObject\Invoke("MSSoapInit('http://example.com/soap/wsdl')") result = soapObject\Invoke("soapFunc('hello')") result2 = soapObject\Invoke("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...
#Python
Python
from SOAPpy import WSDL proxy = WSDL.Proxy("http://example.com/soap/wsdl") result = proxy.soapFunc("hello") result = proxy.anotherSoapFunc(34234)
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...
#Picat
Picat
  import sat. main => Grid = {{0,1,1,0,1,1,0}, {1,1,1,1,1,1,1}, {1,1,1,1,1,1,1}, {0,1,1,1,1,1,0}, {0,0,1,1,1,0,0}, {0,0,0,1,0,0,0}}, NR = len(Grid), NC = len(Grid[1]), Es = [{(R,C), (R1,C1), _} : R in 1..NR, C in 1..NC, R1 in 1..NR, C1 in 1..NC, % Edges ((R1 = R, abs(C1...
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...
#Prolog
Prolog
hopido(Grid,[C|Solved],Xs,Ys) :- select(C,Grid,RGrid), solve(RGrid,C,Solved,Xs,Ys).   solve([],_,[],_,_). solve(Grid,p(X,Y),[p(X1,Y1)|R],Xs,Ys) :- valid_move(X,Y,Xs,Ys,X1,Y1), select(p(X1,Y1),Grid,NextGrid), solve(NextGrid,p(X1,Y1),R,Xs,Ys).   valid_move(X,Y,Xs,_,X1,Y) :- j3(X,X1,Xs). % right (3,0) valid_m...
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 ...
#E
E
def compareBy(keyfn) { # This ought to be in the standard library return def comparer(a, b) { return keyfn(a).op__cmp(keyfn(b)) } }   def x := [ ["Joe",3], ["Bill",4], ["Alice",20], ["Harry",3], ]   println(x.sort(compareBy(fn [name,_] { name })))
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 ...
#VBA
VBA
Option Base 1 Private Function countingSort(array_ As Variant, mina As Long, maxa As Long) As Variant Dim count() As Integer ReDim count(maxa - mina + 1) For i = 1 To UBound(array_) count(array_(i) - mina + 1) = count(array_(i) - mina + 1) + 1 Next i Dim z As Integer: z = 1 For i = mina ...
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...
#Haskell
Haskell
import Data.List (permutations)   solution :: [Int] solution@(a : b : c : d : e : f : g : h : _) = head $ filter isSolution (permutations [1 .. 8]) where isSolution :: [Int] -> Bool isSolution (a : b : c : d : e : f : g : h : _) = all ((> 1) . abs) $ zipWith (-) [a, c, ...
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...
#REXX
REXX
/*REXX program solves a Numbrix (R) puzzle, it also displays the puzzle and solution. */ maxR= 0; maxC= 0; maxX= 0; /*define maxR, maxC, and maxX. */ minR= 9e9; minC= 9e9; minX= 9e9; /* " minR, minC, " minX. */ cells= 0 ...
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 ...
#EGL
EGL
program SortExample   function main() test1 int[] = [1,-1,8,-8,2,-2,7,-7,3,-3,6,-6,9,-9,4,-4,5,-5,0]; test1.sort(sortFunction);   for(i int from 1 to test1.getSize()) SysLib.writeStdout(test1[i]); end end   function sortFunction(a any in, b any in) returns (int) return (a as i...
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 ...
#Elena
Elena
import system'routines; import extensions;   public program() { var unsorted := new int[]{6, 2, 7, 8, 3, 1, 10, 5, 4, 9};   console.printLine(unsorted.clone().sort(ifOrdered).asEnumerable()) }
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 ...
#Nim
Nim
import algorithm, sequtils, strutils   type OID = distinct string   # Borrow the `$` procedure from the base string type. proc `$`(oid: OID): string {.borrow.}     template toSeqInt(oid: OID): seq[int] = ## Convert an OID into a sequence of integers. oid.string.split('.').map(parseInt)     proc oidCmp(a, b: OID): i...
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 ...
#Perl
Perl
my @OIDs = qw( 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 );   my @sorted = map { $_->[0] } sort { $a->[1] cmp $b->[1] } map { [$_, join '', map { sprintf...
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 ...
#Io
Io
List disjointSort := method(indices, sortedIndices := indices unique sortInPlace sortedValues := sortedIndices map(idx,at(idx)) sortInPlace sortedValues foreach(i,v,atPut(sortedIndices at(i),v)) self )   list(7,6,5,4,3,2,1,0) disjointSort(list(6,1,7)) println
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 ...
#Wren
Wren
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 ...
#R
R
  #lang R   assignVec <- Vectorize("assign", c("x", "value")) `%<<-%` <- function(x, value) invisible(assignVec(x, value, envir = .GlobalEnv)) # define multiple global assignments operator  
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 ...
#Racket
Racket
#lang racket   (define-syntax-rule (sort-3! x y z <?) (begin (define-syntax-rule (swap! x y) (let ((tmp x)) (set! x y) (set! y tmp))) (define-syntax-rule (sort-2! x y) (when (<? y x) (swap! x y))) (sort-2! x y) (sort-2! x z) (sort-2! y z)))   (module+ test (require rackunit data/order...
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 ...
#Nemerle
Nemerle
using System.Console;   module CustomSort { Main() : void { def strings1 = ["these", "are", "strings", "of", "different", "length"]; def strings2 = ["apple", "House", "chewy", "Salty", "rises", "Later"];   WriteLine(strings1.Sort((x, y) => y.Length.CompareTo(x.Length))); WriteLin...
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 ...
#NetRexx
NetRexx
/* NetRexx */ options replace format comments java crossref symbols nobinary   -- ============================================================================= class RSortCustomComparator public   -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ method main(args = String[]) public static...
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...
#Wren
Wren
var combSort = Fn.new { |a| var gap = a.count while (true) { gap = (gap/1.25).floor if (gap < 1) gap = 1 var i = 0 var swaps = false while (true) { if (a[i] > a[i+gap]) { var t = a[i] a[i] = a[i+gap] a[i+gap] = t...
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 ...
#Scheme
Scheme
(import (rnrs base (6)) (srfi :27 random-bits))   (define (shuffle lst) (define (swap! vec i j) (let ((tmp (vector-ref vec i))) (vector-set! vec i (vector-ref vec j)) (vector-set! vec j tmp))) (define vec (list->vector lst)) (let loop ((i (sub1 (vector-length vec)))) (unless (zero? 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 ...
#Euphoria
Euphoria
function bubble_sort(sequence s) object tmp integer changed for j = length(s) to 1 by -1 do changed = 0 for i = 1 to j-1 do if compare(s[i], s[i+1]) > 0 then tmp = s[i] s[i] = s[i+1] s[i+1] = tmp changed = 1 ...
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 ...
#ooRexx
ooRexx
/* Rexx */   call demo return exit   -- ----------------------------------------------------------------------------- -- Gnome sort implementation -- ----------------------------------------------------------------------------- ::routine gnomeSort use arg ra, sAsc = '' if sAsc = '' then sAsc = isTrue()   sDsc = ...
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 ...
#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 = cocktailSort(String[] Arrays.copy...
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.
#BBC_BASIC
BBC BASIC
INSTALL @lib$+"SOCKLIB" PROC_initsockets   socket% = FN_tcpconnect("localhost", "256") IF socket% <=0 ERROR 100, "Failed to open socket"   REM Don't use FN_writesocket since an error is expected msg$ = "hello socket world" SYS `send`, socket%, !^msg$, LEN(msg$), 0 TO result%   ...
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.
#C
C
#include <stdio.h> #include <string.h> #include <sys/types.h> #include <sys/socket.h> #include <netdb.h>   const char *msg = "hello socket world";   int main() { int i, sock, len, slen;   struct addrinfo hints, *addrs; memset(&hints, 0, sizeof(struct addrinfo)); hints.ai_family = AF_UNSPEC; hints.ai_so...
http://rosettacode.org/wiki/Sleeping_Beauty_problem
Sleeping Beauty problem
Background on the task In decision theory, The Sleeping Beauty Problem is a problem invented by Arnold Zoboff and first publicized on Usenet. The experimental subject, named Sleeping Beauty, agrees to an experiment as follows: Sleeping Beauty volunteers to be put into a deep sleep on a Sunday. There is then a fair coin...
#Arturo
Arturo
sleepingBeauty: function [reps][ wakings: 0 heads: 0 do.times: reps [ coin: random 0 1 wakings: wakings + 1 if? coin = 0 -> heads: heads + 1 else -> wakings: wakings + 1 ] print ["Wakings over" reps "repetitions =" wakings] return 100.0 * heads//wakings ]   pc: sl...
http://rosettacode.org/wiki/Sleeping_Beauty_problem
Sleeping Beauty problem
Background on the task In decision theory, The Sleeping Beauty Problem is a problem invented by Arnold Zoboff and first publicized on Usenet. The experimental subject, named Sleeping Beauty, agrees to an experiment as follows: Sleeping Beauty volunteers to be put into a deep sleep on a Sunday. There is then a fair coin...
#BASIC
BASIC
  iteraciones = 1000000 cara = 0 dormir = 0   for i = 1 to iteraciones lanza_moneda = int(rand * 2) dormir = dormir + 1 if lanza_moneda = 1 then cara = cara + 1 else dormir = dormir + 1 end if next i   print "Wakings over "; iteraciones; " repetitions = "; dormir print "Percentage probability of heads on wakin...
http://rosettacode.org/wiki/Sleeping_Beauty_problem
Sleeping Beauty problem
Background on the task In decision theory, The Sleeping Beauty Problem is a problem invented by Arnold Zoboff and first publicized on Usenet. The experimental subject, named Sleeping Beauty, agrees to an experiment as follows: Sleeping Beauty volunteers to be put into a deep sleep on a Sunday. There is then a fair coin...
#C.2B.2B
C++
#include <iostream> #include <random>   int main() { std::cout.imbue(std::locale("")); const int experiments = 1000000; std::random_device dev; std::default_random_engine engine(dev()); std::uniform_int_distribution<int> distribution(0, 1); int heads = 0, wakenings = 0; for (int i = 0; i < e...
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 ...
#C
C
#include <locale.h> #include <stdbool.h> #include <stdint.h> #include <stdio.h>   typedef uint32_t integer;   integer next_prime_digit_number(integer n) { if (n == 0) return 2; switch (n % 10) { case 2: return n + 1; case 3: case 5: return n + 2; default: return 2...
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 ...
#11l
11l
[[Int]] board [Int] given V start = (-1, -1)   F setup(s) V lines = s.split("\n") V ncols = lines[0].split(‘ ’, group_delimiters' 1B).len V nrows = lines.len  :board = (0 .< nrows + 2).map(_ -> [-1] * (@ncols + 2))   L(row) lines V r = L.index L(cell) row.split(‘ ’, group_delimiters' 1B) ...
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...
#D
D
import std.string, std.typecons, std.exception, std.algorithm; import queue_usage2; // No queue in Phobos 2.064.   const struct Board { private enum El { floor = ' ', wall = '#', goal = '.', box = '$', player = '@', boxOnGoal='*' } private alias CTable = string; private immutable size_...
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 ...
#Java
Java
import java.util.*;   public class HolyKnightsTour {   final static String[] board = { " xxx ", " x xx ", " xxxxxxx", "xxx x x", "x x xxx", "1xxxxxx ", " xx x ", " xxx "};   private final static int base = 12; private final static i...
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...
#Raku
Raku
# Reference: # https://github.com/retupmoca/P6-SOAP # http://wiki.dreamfactory.com/DreamFactory/Tutorials/Temp_Conversion_SOAP_API   use v6; use SOAP::Client;   my $request = SOAP::Client.new('http://www.w3schools.com/xml/tempconvert.asmx?WSDL') or die;   say $request.call('CelsiusToFahrenheit', Celsius => 100 ) or die...
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...
#Ruby
Ruby
require 'soap/wsdlDriver'   wsdl = SOAP::WSDLDriverFactory.new("http://example.com/soap/wsdl") soap = wsdl.create_rpc_driver   response1 = soap.soapFunc(:elementName => "value") puts response1.soapFuncReturn   response2 = soap.anotherSoapFunc(:aNumber => 42) puts response2.anotherSoapFuncReturn
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...
#Smalltalk
Smalltalk
| service client response1 response2 |   service := SprayWSDLService onUrl: 'http://example.com/soap/wsdl'.   client := service createClient. response1 := client send: 'soapFunc' withArguments:{ 'hello' }. response2 := client send: 'anotherSoapFunc' withArguments:{ 34234 }.
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...
#Python
Python
  from sys import stdout   neighbours = [[2, 2], [-2, 2], [2, -2], [-2, -2], [3, 0], [0, 3], [-3, 0], [0, -3]] cnt = 0 pWid = 0 pHei = 0     def is_valid(a, b): return -1 < a < pWid and -1 < b < pHei     def iterate(pa, x, y, v): if v > cnt: return 1   for i in range(len(neighbours)): a = x ...
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 ...
#EchoLisp
EchoLisp
  ;; sorting (name value) by name - Ignoring case (define (name a) (first a)) (define( sort-proc a b) (string-ci<? (name a) (name b)))   (define people '(("😎" -42) ("albert" 33) ("Simone" 44) ("Antoinette" 42) ("elvis" 666) ("😃" 1000)))   (list-sort sort-proc people) → (("albert" 33) ("Antoinette" 42) ("el...
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 ...
#VBScript
VBScript
function findMax( a ) dim num dim max max = 0 for each num in a if num > max then max = num next findMax = max end function   function findMin( a ) dim num dim min min = 0 for each num in a if num < min then min = num next findMin = min end function   'the function returns the sorted array, but the fact...
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...
#J
J
holes=:;:'A B C D E F G H'   connections=:".;._2]0 :0 holes e.;:'C D E' NB. A holes e.;:'D E F' NB. B holes e.;:'A D G' NB. C holes e.;:'A B C E G H' NB. D holes e.;:'A B D F G H' NB. E holes e.;:'B E H' NB. F holes e.;:'C D E' NB. G holes e.;:'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...
#Ruby
Ruby
require 'HLPsolver'   ADJACENT = [[-1, 0], [0, -1], [0, 1], [1, 0]]   board1 = <<EOS 0 0 0 0 0 0 0 0 0 0 0 46 45 0 55 74 0 0 0 38 0 0 43 0 0 78 0 0 35 0 0 0 0 0 71 0 0 0 33 0 0 0 59 0 0 0 17 0 0 0 0 0 67 0 0 18 0 0 11 0 0 64 0 0 0 24 21 0 1 2 0 0 0 0 0 0 0 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...
#SystemVerilog
SystemVerilog
    ////////////////////////////////////////////////////////////////////////////// /// NumbrixSolver /// /// Solve the puzzle, by using system verilog randomization engine /// ////////////////////////////////////////////////////////////////////////////// ...
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 ...
#Elixir
Elixir
list = [2, 4, 3, 1, 2] IO.inspect Enum.sort(list) IO.inspect Enum.sort(list, &(&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 ...
#Erlang
Erlang
List = [2, 4, 3, 1, 2]. SortedList = lists:sort(List).
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 ...
#Phix
Phix
sequence strings = {"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"} constan...
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 ...
#Phixmonti
Phixmonti
include ..\Utilitys.pmt   ( "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" )   len for var i i get "." " " subst split len for var j j get tonum j se...
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 ...
#J
J
7 6 5 4 3 2 1 0 (/:~@:{`[`]}~ /:~@~.) 6 1 7 7 0 5 4 3 2 1 6
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 ...
#Java
Java
import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List;   public class Disjoint { public static <T extends Comparable<? super T>> void sortDisjoint( List<T> array, int[] idxs) { Arrays.sort(idxs); List<T> disjoint = new ArrayList<T>(); ...
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 ...
#zkl
zkl
fcn sortByColumn(list,col) { list.sort('wrap(city1,city2){ city1[col]<city2[col] }) }
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 ...
#Raku
Raku
# Sorting strings. Added a vertical bar between strings to make them discernable my ($a, $b, $c) = 'lions, tigers, and', 'bears, oh my!', '(from "The Wizard of Oz")'; say "sorting: {($a, $b, $c).join('|')}"; say ($a, $b, $c).sort.join('|'), ' - standard lexical string sort';   # Sorting numeric things my ($x, $y, $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 ...
#Nial
Nial
sort fork [=[tally first,tally last],up, >= [tally first,tally last]] ['Here', 'are', 'some', 'sample', 'strings', 'to', 'be', 'sorted'] =+-------+------+------+----+----+---+--+--+ =|strings|sample|sorted|Here|some|are|be|to| =+-------+------+------+----+----+---+--+--+
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 ...
#Nim
Nim
import strutils, algorithm   var strings = "here are Some sample strings to be sorted".split(' ')   strings.sort(proc (x, y: string): int = result = cmp(y.len, x.len) if result == 0: result = cmpIgnoreCase(x, y) )   echo strings
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...
#zkl
zkl
fcn combSort(list){ len,gap,swaps:=list.len(),len,True; while(gap>1 or swaps){ gap,swaps=(1).max(gap.toFloat()/1.2473), False; foreach i in (len - gap){ if(list[i]>list[i + gap]){ list.swap(i,i + gap); swaps=True; } } } list }
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 ...
#Smalltalk
Smalltalk
Smalltalk at: #isItSorted put: [ :c | |isit| isit := false. (2 to: (c size)) detect: [ :i | ( (c at: ( i - 1 )) > (c at: i) ) ] ifNone: [ isit := true ]. isit ]. Smalltalk at: #bogosort put: [ :c | [ isItSorted value: c ] whileFalse: [ 1 to: (c size) do: [ :i | |r t| r := (Random be...
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 ...
#Ezhil
Ezhil
    ## இந்த நிரல் ஒரு பட்டியலில் உள்ள எண்களை Bubble Sort என்ற முறைப்படி ஏறுவரிசையிலும் பின்னர் அதையே இறங்குவரிசையிலும் அடுக்கித் தரும்   ## மாதிரிக்கு நாம் ஏழு எண்களை எடுத்துக்கொள்வோம்   எண்கள் = [5, 1, 10, 8, 1, 21, 4, 2] எண்கள்பிரதி = எண்கள்   பதிப்பி "ஆரம்பப் பட்டியல்:" பதிப்பி எண்கள்   நீளம் = len(எண்கள்) குறைநீளம்...
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 ...
#Oz
Oz
declare fun {GnomeSort Xs} case Xs of nil then nil [] X|Xr then {Loop [X] Xr} end end   fun {Loop Vs Ws} case [Vs Ws] of [V|_ W|Wr] andthen V =< W then {Loop W|Vs Wr} [] [V|Vr W|Wr] then {Loop Vr W|V|Wr} [] [nil W|Wr] then {Loop [W] Wr} [] [Vs nil ] then {Reverse Vs} ...
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 ...
#Nim
Nim
template trySwap(): untyped = if a[i] < a[i-1]: swap a[i], a[i-1] t = false   proc cocktailSort[T](a: var openarray[T]) = var t = false var l = a.len while not t: t = true for i in 1 ..< l: trySwap if t: break for i in countdown(l-1, 1): trySwap   var a = @[4, 65, 2, -31, 0, 99, 2, 83, 7...
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.
#C.23
C#
using System; using System.IO; using System.Net.Sockets;   class Program { static void Main(string[] args) { TcpClient tcp = new TcpClient("localhost", 256); StreamWriter writer = new StreamWriter(tcp.GetStream());   writer.Write("hello socket world"); writer.Flush();   tcp.C...
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.
#C.2B.2B
C++
//compile with g++ main.cpp -lboost_system -pthread   #include <boost/asio.hpp>   int main() { boost::asio::io_context io_context; boost::asio::ip::tcp::socket sock(io_context); boost::asio::ip::tcp::resolver resolver(io_context); boost::asio::ip::tcp::resolver::query query("localhost", "4321");   boost::asi...
http://rosettacode.org/wiki/Sleeping_Beauty_problem
Sleeping Beauty problem
Background on the task In decision theory, The Sleeping Beauty Problem is a problem invented by Arnold Zoboff and first publicized on Usenet. The experimental subject, named Sleeping Beauty, agrees to an experiment as follows: Sleeping Beauty volunteers to be put into a deep sleep on a Sunday. There is then a fair coin...
#CLU
CLU
% This program needs to be merged with PCLU's "misc" library % to use the random number generator.   experiment = cluster is run rep = null   own awake: int := 0 own awake_heads: int := 0    % Returns true if heads, false if tails coin_toss = proc () returns (bool) return(random$next(2)=1) ...
http://rosettacode.org/wiki/Sleeping_Beauty_problem
Sleeping Beauty problem
Background on the task In decision theory, The Sleeping Beauty Problem is a problem invented by Arnold Zoboff and first publicized on Usenet. The experimental subject, named Sleeping Beauty, agrees to an experiment as follows: Sleeping Beauty volunteers to be put into a deep sleep on a Sunday. There is then a fair coin...
#Dyalect
Dyalect
let experiments = 10000 var heads = 0 var wakenings = 0 for _ in 1..experiments { wakenings += 1 match rnd(min: 0, max: 10) { <5 => heads += 1, _ => wakenings += 1 } } print("Wakenings over \(experiments) experiments: \(wakenings)") print("Sleeping Beauty should estimate a credence of: \(Flo...
http://rosettacode.org/wiki/Sleeping_Beauty_problem
Sleeping Beauty problem
Background on the task In decision theory, The Sleeping Beauty Problem is a problem invented by Arnold Zoboff and first publicized on Usenet. The experimental subject, named Sleeping Beauty, agrees to an experiment as follows: Sleeping Beauty volunteers to be put into a deep sleep on a Sunday. There is then a fair coin...
#Excel
Excel
SLEEPINGB =LAMBDA(n, LET( headsWakes, LAMBDA(x, IF(1 = x, {1,1}, {0,2} ) )( RANDARRAY(n, 1, 0, 1, TRUE) ), CHOOSE( {1,2}, SUM(INDEX(headsWakes, 0, 1)), SUM(INDEX(headsWakes, 0, 2)) ...