code
stringlengths
1
46.1k
label
class label
1.18k classes
domain_label
class label
21 classes
index
stringlengths
4
5
x <- sample(c(0, 1), 26, replace=T) x names(x) <- letters x sort(x, method=) sort(x, method=)
245Sort stability
12php
30fzq
import java.util.Comparator; import java.util.Arrays; public class Test { public static void main(String[] args) { String[] strings = {"Here", "are", "some", "sample", "strings", "to", "be", "sorted"}; Arrays.sort(strings, new Comparator<String>() { public int compare(String s1, String s2) { i...
243Sort using a custom comparator
9java
j2j7c
object CombSort extends App { val ia = Array(28, 44, 46, 24, 19, 2, 17, 11, 25, 4) val ca = Array('X', 'B', 'E', 'A', 'Z', 'M', 'S', 'L', 'Y', 'C') def sorted[E](input: Array[E])(implicit ord: Ordering[E]): Array[E] = { import ord._ var gap = input.length var swapped = true while (gap > 1 || swap...
235Sorting algorithms/Comb sort
16scala
sbtqo
class Array def beadsort map {|e| [1] * e}.columns.columns.map(&:length) end def columns y = length x = map(&:length).max Array.new(x) do |row| Array.new(y) { |column| self[column][row] }.compact end end end p [5,3,1,7,4,1,1].beadsort
239Sorting algorithms/Bead sort
14ruby
4mj5p
null
240Sorting algorithms/Cocktail sort
11kotlin
xh0ws
import Data.List ( sort , intercalate ) splitString :: Eq a => (a) -> [a] -> [[a]] splitString c [] = [] splitString c s = let ( item , rest ) = break ( == c ) s ( _ , next ) = break ( /= c ) rest in item: splitString c next convertIntListToString :: [Int] -> String convertIntListToString =...
248Sort a list of object identifiers
8haskell
qhpx9
x <- sample(c(0, 1), 26, replace=T) x names(x) <- letters x sort(x, method=) sort(x, method=)
245Sort stability
3python
bujkr
function lengthSorter(a, b) { var result = b.length - a.length; if (result == 0) result = a.localeCompare(b); return result; } var test = ["Here", "are", "some", "sample", "strings", "to", "be", "sorted"]; test.sort(lengthSorter); alert( test.join(' ') );
243Sort using a custom comparator
10javascript
1g1p7
bogosort <- function(x) { while(is.unsorted(x)) x <- sample(x) x } n <- c(1, 10, 9, 7, 3, 0) bogosort(n)
236Sorting algorithms/Bogosort
13r
e7oad
function cocktailSort( A ) local swapped repeat swapped = false for i = 1, #A - 1 do if A[ i ] > A[ i+1 ] then A[ i ], A[ i+1 ] = A[ i+1 ] ,A[i] swapped=true end end if swapped == false then break
240Sorting algorithms/Cocktail sort
1lua
qk8x0
size_t write_data(void *ptr, size_t size, size_t nmeb, void *stream){ return fwrite(ptr,size,nmeb,stream); } size_t read_data(void *ptr, size_t size, size_t nmeb, void *stream){ return fread(ptr,size,nmeb,stream); } void callSOAP(char* URL, char * inFile, char * outFile) { FILE * rfp = fopen(inFile, ); ...
253SOAP
5c
w7gec
import java.util.*; public class Hopido { final static String[] board = { ".00.00.", "0000000", "0000000", ".00000.", "..000..", "...0..."}; final static int[][] moves = {{-3, 0}, {0, 3}, {3, 0}, {0, -3}, {2, 2}, {2, -2}, {-2, 2}, {-2, -2}}; static int[...
250Solve a Hopido puzzle
9java
xjhwy
package main import ( "fmt" big "github.com/ncw/gmp" )
254Smallest number k such that k+2^m is composite for all m less than k
0go
w74eg
typedef struct twoStringsStruct { char * key, *value; } sTwoStrings; int ord( char v ) { static char *dgts = ; char *cp; for (cp=dgts; v != *cp; cp++); return (cp-dgts); } int cmprStrgs(const sTwoStrings *s1,const sTwoStrings *s2) { char *p1 = s1->key; char *p2 = s2->key; char *mrk1, ...
255Sort an array of composite structures
5c
lfocy
class Array def counting_sort! replace counting_sort end def counting_sort min, max = minmax count = Array.new(max - min + 1, 0) each {|number| count[number - min] += 1} (min..max).each_with_object([]) {|i, ary| ary.concat([i] * count[i - min])} end end ary = [9,7,10,2,9,7,4,3,10,2,7,10,2,...
237Sorting algorithms/Counting sort
14ruby
6o23t
use strict; use warnings; $_ = <<END; 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 0 0 0 END my $gap = /.\n/ * $-[0]; print; s...
249Solve a Numbrix puzzle
2perl
xjkw8
(sort [5 4 3 2 1]) (1 2 3 4 5)
252Sort an integer array
6clojure
xj7wk
package com.rosettacode; import java.util.Comparator; import java.util.stream.Stream; public class OIDListSorting { public static void main(String[] args) { final String dot = "\\."; final Comparator<String> oids_comparator = (o1, o2) -> { final String[] o1Numbers = o1.split(dot), o...
248Sort a list of object identifiers
9java
p5rb3
x <- sample(c(0, 1), 26, replace=T) x names(x) <- letters x sort(x, method="quick") sort(x, method="shell")
245Sort stability
13r
7c4ry
use 5.010_000; my $x = 'lions, tigers, and'; my $y = 'bears, oh my!'; my $z = '(from the "Wizard of OZ")'; ( $x, $y, $z ) = sort ( $x, $y, $z ); say 'Case 1:'; say " x = $x"; say " y = $y"; say " z = $z"; $x = 77444; $y = -12; $z = 0; ( $x, $y, $z ) = sort { $a <=> $b } ( $x, $y, $z ); say 'Case 2:'; sa...
242Sort three variables
2perl
7ljrh
func combSort(inout list:[Int]) { var swapped = true var gap = list.count while gap > 1 || swapped { gap = gap * 10 / 13 if gap == 9 || gap == 10 { gap = 11 } else if gap < 1 { gap = 1 } swapped = false for var i = 0, j = gap; j < l...
235Sorting algorithms/Comb sort
17swift
aro1i
(require '[clj-soap.core:as soap]) (let [client (soap/client-fn "http://example.com/soap/wsdl")] (client:soapFunc) (client:anotherSoapFunc))
253SOAP
6clojure
8pk05
null
250Solve a Hopido puzzle
11kotlin
p54b6
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; }
254Smallest number k such that k+2^m is composite for all m less than k
2perl
u3fvr
fn counting_sort( mut data: Vec<usize>, min: usize, max: usize, ) -> Vec<usize> {
237Sorting algorithms/Counting sort
15rust
yiv68
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
237Sorting algorithms/Counting sort
16scala
cf493
package main import ( "fmt" "sort" ) func main() {
247Sort disjoint sublist
0go
vzm2m
<?php $x = 'lions, tigers, and'; $y = 'bears, oh my!'; $z = '(from the )'; $items = [$x, $y, $z]; sort($items); list($x, $y, $z) = $items; echo <<<EOT Case 1: x = $x y = $y z = $z EOT; $x = 77444; $y = -12; $z = 0; $items = [$x, $y, $z]; sort($items); list($x, $y, $z) = $items; echo <<<EOT Case 2: x = $...
242Sort three variables
12php
fqtdh
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 (inde...
243Sort using a custom comparator
11kotlin
5y5ua
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)
243Sort using a custom comparator
1lua
4m45c
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.x......
256Solve a Holy Knight's tour
0go
kvmhz
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"` Addre...
253SOAP
0go
cdi9g
(def *langs* [["Clojure" 2007] ["Common Lisp" 1984] ["Java" 1995] ["Haskell" 1990] ["Lisp" 1958] ["Scheme" 1975]]) user> (sort-by second *langs*) (["Lisp" 1958] ["Scheme" 1975] ["Common Lisp" 1984] ["Haskell" 1990] ["Java" 1995] ["Clojure" 2007])
255Sort an array of composite structures
6clojure
4yt5o
null
248Sort a list of object identifiers
11kotlin
7cvr4
def sparseSort = { a, indices = ([] + (0..<(a.size()))) -> indices.sort().unique() a[indices] = a[indices].sort() a }
247Sort disjoint sublist
7groovy
mity5
ary = [[, ], [, ], [, ], [, ]] p ary.sort {|a,b| a[1] <=> b[1]}
245Sort stability
14ruby
14kpw
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.sort...
245Sort stability
15rust
agb14
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)
245Sort stability
16scala
xjawg
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
236Sorting algorithms/Bogosort
14ruby
81z01
int w, h, n_boxes; uint8_t *board, *goals, *live; typedef uint16_t cidx_t; typedef uint32_t hash_t; typedef struct state_t state_t; struct state_t { hash_t h; state_t *prev, *next, *qnext; cidx_t c[]; }; size_t state_size, block_size = 32; state_t *block_root, *block_head; inline state_t* newstate(state_t *pa...
257Sokoban
5c
68e32
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 _ ...
256Solve a Holy Knight's tour
8haskell
nekie
null
253SOAP
11kotlin
vzf21
use strict; use warnings; $_ = do { local $/; <DATA> }; s/./$&$&/g; my $w = /\n/ && $-[0]; my $wd = 3 * $w + 1; my $wr = 2 * $w + 8; my $wl = 2 * $w - 8; place($_, '00'); die "No solution\n"; sub place { (local $_, my $last) = @_; (my $new = $last)++; /$last.{10}(?=00)/g ...
250Solve a Hopido puzzle
2perl
yoi6u
package main import ( "fmt" "strings" ) func main() { p, tests, swaps := Solution() fmt.Println(p) fmt.Println("Tested", tests, "positions and did", swaps, "swaps.") }
251Solve the no connection puzzle
0go
qhhxz
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: ...
249Solve a Numbrix puzzle
3python
qhbxi
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(...
248Sort a list of object identifiers
1lua
jlu71
import Control.Monad import qualified Data.Array as A import Data.Array.IArray import Data.Array.ST import Data.List import Data.List.Utils disSort1 :: (Ord a, Num a, Enum a, Ord b) => [b] -> [a] -> [b] disSort1 xs is = let is_ = sort is (sub, rest) = partition ((`elem` is_) . fst) $ zip [0 ..] xs in ...
247Sort disjoint sublist
8haskell
erkai
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) -> bool,...
236Sorting algorithms/Bogosort
15rust
oa383
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))
236Sorting algorithms/Bogosort
16scala
dxmng
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);
253SOAP
2perl
0bhs4
import java.util.stream.Collectors import java.util.stream.IntStream class NoConnection {
251Solve the no connection puzzle
7groovy
144p6
a= raw_input().strip() b=raw_input().strip() c=raw_input().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))
242Sort three variables
3python
j2h7p
<?php $client = new SoapClient(); $result = $client->soapFunc(); $result = $client->anotherSoapFunc(34234); $client = new SoapClient(); print_r($client->__getTypes()); print_r($client->__getFunctions()); ?>
253SOAP
12php
56zus
from SOAPpy import WSDL proxy = WSDL.Proxy() result = proxy.soapFunc() result = proxy.anotherSoapFunc(34234)
253SOAP
3python
8pk0o
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, g, e, a, c, g, e,...
251Solve the no connection puzzle
8haskell
miiyf
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 ...
248Sort a list of object identifiers
2perl
fx0d7
assignVec <- Vectorize("assign", c("x", "value")) `%<<-%` <- function(x, value) invisible(assignVec(x, value, envir = .GlobalEnv))
242Sort three variables
13r
4mg5y
const char *msg = ; int main() { int i, sock, len, slen; struct addrinfo hints, *addrs; memset(&hints, 0, sizeof(struct addrinfo)); hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; if (0 == getaddrinfo(, , &hints, &addrs)) { sock = socket(addrs->ai_family, addrs->ai_socktyp...
258Sockets
5c
lfscy
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 + next_prime_digit_number(n/10) * 10; } } bool is_prime(integer n) { if (...
259Smarandache prime-digital sequence
5c
7cfrg
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 int[...
256Solve a Holy Knight's tour
9java
qh4xa
require 'soap/wsdlDriver' wsdl = SOAP::WSDLDriverFactory.new() soap = wsdl.create_rpc_driver response1 = soap.soapFunc(:elementName => ) puts response1.soapFuncReturn response2 = soap.anotherSoapFunc(:aNumber => 42) puts response2.anotherSoapFuncReturn
253SOAP
14ruby
iapoh
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 + neighb...
250Solve a Hopido puzzle
3python
minyh
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 0 ...
249Solve a Numbrix puzzle
14ruby
0b1su
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>(); ...
247Sort disjoint sublist
9java
h24jm
package main import ( "fmt" "strings" ) func main() { level := ` ####### # # # # #. # # #. $$ # #.$$ # #.# @# #######` fmt.Printf("level:%s\n", level) fmt.Printf("solution:\n%s\n", solve(level)) } func solve(board string) string { buffer = make([]byte, len(board)) width := s...
257Sokoban
0go
p59bg
(() => { 'use strict';
256Solve a Holy Knight's tour
10javascript
iahol
import static java.lang.Math.abs; import java.util.*; import static java.util.stream.Collectors.toList; import static java.util.stream.IntStream.range; public class NoConnection {
251Solve the no connection puzzle
9java
fxxdv
function sort_disjoint(values, indices) { var sublist = []; indices.sort(function(a, b) { return a > b; }); for (var i = 0; i < indices.length; i += 1) { sublist.push(values[indices[i]]); } sublist.sort(function(a, b) { return a < b; }); for (var i = 0; i < indices.length; i += 1) { values[indice...
247Sort disjoint sublist
10javascript
agh10
(ns socket-example (:import (java.net Socket) (java.io PrintWriter))) (defn send-data [host msg] (with-open [sock (Socket. host 256) printer (PrintWriter. (.getOutputStream sock))] (.println printer msg))) (send-data "localhost" "hello socket world")
258Sockets
6clojure
4yn5o
package main import ( "fmt" "math/rand" "rcu" "time" ) func sleepingBeauty(reps int) float64 { wakings := 0 heads := 0 for i := 0; i < reps; i++ { coin := rand.Intn(2)
260Sleeping Beauty problem
0go
jlf7d
import Control.Monad (liftM) import Data.Array import Data.List (transpose) import Data.Maybe (mapMaybe) import qualified Data.Sequence as Seq import qualified Data.Set as Set import Prelude hiding (Left, Right) data Field = Space | Wall | Goal deriving (Eq) data Action = Up | Down | Left | Right | PushUp ...
257Sokoban
8haskell
fxbd1
(() => { 'use strict';
251Solve the no connection puzzle
10javascript
yoo6r
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' ] for s in sorted(data, key=lambda x: list(map(int, x.split('.')))): print(s)
248Sort a list of object identifiers
3python
tq8fw
x = 'lions, tigers, and' y = 'bears, oh my!' z = '(from the )' x, y, z = [x, y, z].sort puts x, y, z x, y, z = 7.7444e4, -12, 18/2r x, y, z = [x, y, z].sort puts x, y, z
242Sort three variables
14ruby
kubhg
import Darwin func shuffle<T>(inout array: [T]) { for i in 1..<array.count { let j = Int(arc4random_uniform(UInt32(i))) (array[i], array[j]) = (array[j], array[i]) } } func issorted<T:Comparable>(ary: [T]) -> Bool { for i in 0..<(ary.count-1) { if ary[i] > ary[i+1] { return false } } r...
236Sorting algorithms/Bogosort
17swift
0pts6
import Data.Monoid (Sum(..)) import System.Random (randomIO) import Control.Monad (replicateM) import Data.Bool (bool) data Toss = Heads | Tails deriving Show anExperiment toss = moreWakenings <> case toss of Heads -> headsOnWaking Tails -> moreWakenings where moreWakenings = (1,0) headsO...
260Sleeping Beauty problem
8haskell
o148p
int *board, *flood, *known, top = 0, w, h; static inline int idx(int y, int x) { return y * w + x; } int neighbors(int c, int *p) { int i, j, n = 0; int y = c / w, x = c % w; for (i = y - 1; i <= y + 1; i++) { if (i < 0 || i >= h) continue; for (j = x - 1; j <= x + 1; j++) if (!(j < 0 || j >= w || (j ...
261Solve a Hidato puzzle
5c
0bvst
import java.util.*; public class Sokoban { String destBoard, currBoard; int playerX, playerY, nCols; Sokoban(String[] board) { nCols = board[0].length(); StringBuilder destBuf = new StringBuilder(); StringBuilder currBuf = new StringBuilder(); for (int r = 0; r < board.len...
257Sokoban
9java
0bgse
null
256Solve a Holy Knight's tour
11kotlin
14lpd
require 'HLPsolver' ADJACENT = [[-3, 0], [0, -3], [0, 3], [3, 0], [-2, -2], [-2, 2], [2, -2], [2, 2]] board1 = <<EOS . 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 . . . . . 1 . . . EOS t0 = Time.now HLPsolver.new(board1).solve puts
250Solve a Hopido puzzle
14ruby
cdf9k
null
247Sort disjoint sublist
11kotlin
4yl57
fn main() { let mut array = [5, 1, 3]; array.sort(); println!("Sorted: {:?}", array); array.sort_by(|a, b| b.cmp(a)); println!("Reverse sorted: {:?}", array); }
242Sort three variables
15rust
b5pkx
$ include "seed7_05.s7i"; const proc: genSort3 (in type: elemType) is func begin global const proc: doSort3 (in var elemType: x, in var elemType: y, in var elemType: z) is func local var array elemType: sorted is 0 times elemType.value; begin writeln("BEFORE: x=[" <& x <& "]; y=[...
242Sort three variables
16scala
are1n
use strict; sub gnome_sort { my @a = @_; my $size = scalar(@a); my $i = 1; my $j = 2; while($i < $size) { if ( $a[$i-1] <= $a[$i] ) { $i = $j; $j++; } else { @a[$i, $i-1] = @a[$i-1, $i]; $i--; if ($i == 0) { $i = $j; $j++; } } } return @a; }
238Sorting algorithms/Gnome sort
2perl
g9k4e
use strict; use warnings; sub sleeping_beauty { my($trials) = @_; my($gotheadsonwaking,$wakenings); $wakenings++ and rand > .5 ? $gotheadsonwaking++ : $wakenings++ for 1..$trials; $wakenings, $gotheadsonwaking/$wakenings } my $trials = 1_000_000; printf "Wakenings over $trials experiments:%d\nSleeping...
260Sleeping Beauty problem
2perl
68p36
null
257Sokoban
11kotlin
er2a4
local p1, p1W = ".xxx.....x.xx....xxxxxxxxxx..x.xx.x..xxxsxxxxxx...xx.x.....xxx..", 8 local p2, p2W = ".....s.x..........x.x.........xxxxx.........xxx.......x..x.x..x..xxxxx...xxxxx..xx.....xx..xxxxx...xxxxx..x..x.x..x.......xxx.........xxxxx.........x.x..........x.x.....", 13 local puzzle, movesCnt, wid = {}, 0, 0 loc...
256Solve a Holy Knight's tour
1lua
ag21v
null
251Solve the no connection puzzle
11kotlin
8pp0q
values = { 7, 6, 5, 4, 3, 2, 1, 0 } indices = { 6, 1, 7 } i = 1
247Sort disjoint sublist
1lua
gm24j
from random import choice def sleeping_beauty_experiment(repetitions): gotheadsonwaking = 0 wakenings = 0 for _ in range(repetitions): coin_result = choice([, ]) wakenings += 1 if coin_result == : gotheadsonwaking += 1 if coin_result == :...
260Sleeping Beauty problem
3python
yo16q
package main import ( "fmt" "math/big" ) var b = new(big.Int) func isSPDSPrime(n uint64) bool { nn := n for nn > 0 { r := nn % 10 if r != 2 && r != 3 && r != 5 && r != 7 { return false } nn /= 10 } b.SetUint64(n) if b.ProbablyPrime(0) {
259Smarandache prime-digital sequence
0go
dwjne
%w[ 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_by{|oid| oid.split().map(&:to_i)} .each{|oid| puts oid}
248Sort a list of object identifiers
14ruby
30iz7
func varSort<T: Comparable>(_ x: inout T, _ y: inout T, _ z: inout T) { let res = [x, y, z].sorted() x = res[0] y = res[1] z = res[2] } var x = "lions, tigers, and" var y = "bears, oh my!" var z = "(from the \"Wizard of OZ\")" print("Before:") print("x = \(x)") print("y = \(y)") print("z = \(z)") print() va...
242Sort three variables
17swift
hvkj0
function gnomeSort($arr){ $i = 1; $j = 2; while($i < count($arr)){ if ($arr[$i-1] <= $arr[$i]){ $i = $j; $j++; }else{ list($arr[$i],$arr[$i-1]) = array($arr[$i-1],$arr[$i]); $i--; if($i == 0){ $i = $j; $j++; } } } return $arr; } $arr = array(3,1,6,2,9,4,7,8,5); echo implode(',',gnom...
238Sorting algorithms/Gnome sort
12php
nw3ig
beautyProblem <- function(n) { wakeCount <- headCount <- 0 for(i in seq_len(n)) { wakeCount <- wakeCount + 1 if(sample(c("H", "T"), 1) == "H") headCount <- headCount + 1 else wakeCount <- wakeCount + 1 } headCount/wakeCount } print(beautyProblem(10000000))
260Sleeping Beauty problem
13r
tqhfz
import Control.Monad (guard) import Math.NumberTheory.Primes.Testing (isPrime) import Data.List.Split (chunksOf) import Data.List (intercalate) import Text.Printf (printf) smarandache :: [Integer] smarandache = [2,3,5,7] <> s [2,3,5,7] >>= \x -> guard (isPrime x) >> [x] where s xs = r <> s r where r = xs >>= \x -> [x...
259Smarandache prime-digital sequence
8haskell
56oug
use strict; use warnings qw(FATAL all); my @initial = split /\n/, <<''; =for space is an empty square @ is the player $ is a box . is a goal + is the player on a goal * is a box on a goal =cut my $cols = length($initial[0]); my $initial = join '', @initial; my $size = length($initial); die unless $siz...
257Sokoban
2perl
cds9a
fn split(s: &str) -> impl Iterator<Item = u64> + '_ { s.split('.').map(|x| x.parse().unwrap()) } fn main() { let mut oids = vec![ "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....
248Sort a list of object identifiers
15rust
68n3l
def sleeping_beauty_experiment(n) coin = [:heads, :tails] gotheadsonwaking = 0 wakenings = 0 n.times do wakenings += 1 coin.sample == :heads? gotheadsonwaking += 1: wakenings += 1 end puts gotheadsonwaking / wakenings.to_f end puts
260Sleeping Beauty problem
14ruby
9nemz
public class SmarandachePrimeDigitalSequence { public static void main(String[] args) { long s = getNextSmarandache(7); System.out.printf("First 25 Smarandache prime-digital sequence numbers:%n2 3 5 7 "); for ( int count = 1 ; count <= 21 ; s = getNextSmarandache(s) ) { if ( isP...
259Smarandache prime-digital sequence
9java
9nwmu