Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
3
Task/JortSort/00-META.yaml
Normal file
3
Task/JortSort/00-META.yaml
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
---
|
||||
from: http://rosettacode.org/wiki/JortSort
|
||||
note: Sorting Algorithms
|
||||
20
Task/JortSort/00-TASK.txt
Normal file
20
Task/JortSort/00-TASK.txt
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
{{Sorting Algorithm}}
|
||||
[[Category:Sorting]]
|
||||
|
||||
{{noticebox||Note: jortSort is considered a work of satire. It achieves its result in an intentionally roundabout way. You are encouraged to write your solutions in the spirit of the original jortsort rather than trying to give the most concise or idiomatic solution.}}
|
||||
|
||||
|
||||
JortSort is a sorting tool set that makes the user do the work and guarantees efficiency because you don't have to sort ever again.
|
||||
<br>It was originally presented by Jenn "Moneydollars" Schiffer at the
|
||||
prestigious [https://www.youtube.com/watch?v=pj4U_W0OFoE JSConf].
|
||||
|
||||
|
||||
JortSort is a function that takes a single array of comparable objects as its argument.
|
||||
|
||||
It then sorts the array in ascending order and compares the sorted array to the originally provided array.
|
||||
|
||||
If the arrays match (i.e. the original array was already sorted), the function returns '''true'''.
|
||||
|
||||
If the arrays do not match (i.e. the original array was not sorted), the function returns '''false'''.
|
||||
<br><br>
|
||||
|
||||
11
Task/JortSort/11l/jortsort.11l
Normal file
11
Task/JortSort/11l/jortsort.11l
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
F jortsort(sequence)
|
||||
R Array(sequence) == sorted(sequence)
|
||||
|
||||
F print_for_seq(seq)
|
||||
print(‘jortsort(#.) is #.’.format(seq, jortsort(seq)))
|
||||
|
||||
print_for_seq([1, 2, 4, 3])
|
||||
print_for_seq([14, 6, 8])
|
||||
print_for_seq([‘a’, ‘c’])
|
||||
print_for_seq(‘CVGH’)
|
||||
print_for_seq(‘PQRST’)
|
||||
132
Task/JortSort/AArch64-Assembly/jortsort.aarch64
Normal file
132
Task/JortSort/AArch64-Assembly/jortsort.aarch64
Normal file
|
|
@ -0,0 +1,132 @@
|
|||
/* ARM assembly AARCH64 Raspberry PI 3B */
|
||||
/* program jortSort64.s */
|
||||
|
||||
/*******************************************/
|
||||
/* Constantes file */
|
||||
/*******************************************/
|
||||
/* for this file see task include a file in language AArch64 assembly*/
|
||||
.include "../includeConstantesARM64.inc"
|
||||
|
||||
/*******************************************/
|
||||
/* Initialized data */
|
||||
/*******************************************/
|
||||
.data
|
||||
szMessOk: .asciz "Ok, the list is sorted. \n"
|
||||
szMessNotOk: .asciz "Ouah!! this list is unsorted.\n"
|
||||
szCarriageReturn: .asciz "\n"
|
||||
tbNumber: .quad 3
|
||||
.quad 4
|
||||
.quad 20
|
||||
.quad 5
|
||||
.equ LGTBNUMBER, (. - tbNumber)/8 // number element of area
|
||||
/*******************************************/
|
||||
/* UnInitialized data */
|
||||
/*******************************************/
|
||||
.bss
|
||||
sZoneConversion: .skip 100
|
||||
.align 4
|
||||
tbNumberSorted: .skip 8 * LGTBNUMBER
|
||||
/*******************************************/
|
||||
/* code section */
|
||||
/*******************************************/
|
||||
.text
|
||||
.global main
|
||||
main: // entry of program
|
||||
ldr x0,qAdrtbNumber
|
||||
ldr x1,qAdrtbNumberSorted
|
||||
mov x2,LGTBNUMBER
|
||||
bl insertionSort // sort area
|
||||
ldr x0,qAdrtbNumber
|
||||
ldr x1,qAdrtbNumberSorted
|
||||
mov x2,LGTBNUMBER
|
||||
bl comparArea // control area
|
||||
cbz x0,1f
|
||||
ldr x0,qAdrszMessNotOk // not sorted
|
||||
bl affichageMess
|
||||
b 100f
|
||||
1: // ok it is good
|
||||
ldr x0,qAdrszMessOk
|
||||
bl affichageMess
|
||||
100: // standard end of the program
|
||||
mov x0, #0 // return code
|
||||
mov x8, #EXIT // request to exit program
|
||||
svc 0 // perform the system call
|
||||
|
||||
qAdrtbNumber: .quad tbNumber
|
||||
qAdrtbNumberSorted: .quad tbNumberSorted
|
||||
qAdrszMessNotOk: .quad szMessNotOk
|
||||
qAdrszMessOk: .quad szMessOk
|
||||
qAdrszCarriageReturn: .quad szCarriageReturn
|
||||
/******************************************************************/
|
||||
/* insertion sort */
|
||||
/******************************************************************/
|
||||
/* x0 contains the address of area to sort */
|
||||
/* x1 contains the address of area sorted */
|
||||
/* x2 contains the number of element */
|
||||
insertionSort:
|
||||
stp x1,lr,[sp,-16]! // save registers
|
||||
stp x2,x3,[sp,-16]! // save registers
|
||||
mov x3,0
|
||||
1: // copy area unsorted to other area
|
||||
ldr x4,[x0,x3,lsl 3]
|
||||
str x4,[x1,x3,lsl 3]
|
||||
add x3,x3,1
|
||||
cmp x3,x2
|
||||
blt 1b
|
||||
|
||||
mov x3,1 // and sort area
|
||||
2:
|
||||
ldr x4,[x1,x3,lsl 3]
|
||||
subs x5,x3,1
|
||||
3:
|
||||
cbz x5,4f
|
||||
ldr x6,[x1,x5,lsl 3]
|
||||
cmp x6,x4
|
||||
ble 4f
|
||||
add x7,x5,1
|
||||
str x6,[x1,x7,lsl 3]
|
||||
subs x5,x5,1
|
||||
b 3b
|
||||
4:
|
||||
add x5,x5,1
|
||||
str x4,[x1,x5,lsl 3]
|
||||
add x3,x3,1
|
||||
cmp x3,x2
|
||||
blt 2b
|
||||
100:
|
||||
ldp x2,x3,[sp],16 // restaur 2 registers
|
||||
ldp x1,lr,[sp],16 // restaur 2 registers
|
||||
ret
|
||||
/******************************************************************/
|
||||
/* Comparaison elements of two areas */
|
||||
/******************************************************************/
|
||||
/* x0 contains the address of area to sort */
|
||||
/* x1 contains the address of area sorted */
|
||||
/* x2 contains the number of element */
|
||||
comparArea:
|
||||
stp x1,lr,[sp,-16]! // save registers
|
||||
stp x2,x3,[sp,-16]! // save registers
|
||||
mov x3,0
|
||||
1:
|
||||
ldr x4,[x0,x3,lsl 3] // load element area 1
|
||||
ldr x5,[x1,x3,lsl 3] // load element area 2
|
||||
cmp x4,x5 // equal ?
|
||||
bne 99f // no -> error
|
||||
add x3,x3,1 // yes increment indice
|
||||
cmp x3,x2 // maxi ?
|
||||
blt 1b // no -> loop
|
||||
mov x0,0 // yes -> it is ok
|
||||
b 100f
|
||||
99:
|
||||
mov x0,1
|
||||
100:
|
||||
ldp x2,x3,[sp],16 // restaur 2 registers
|
||||
ldp x1,lr,[sp],16 // restaur 2 registers
|
||||
ret
|
||||
|
||||
|
||||
/********************************************************/
|
||||
/* File Include fonctions */
|
||||
/********************************************************/
|
||||
/* for this file see task include a file in language AArch64 assembly */
|
||||
.include "../includeARM64.inc"
|
||||
71
Task/JortSort/Action-/jortsort.action
Normal file
71
Task/JortSort/Action-/jortsort.action
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
PROC PrintArray(INT ARRAY a INT size)
|
||||
INT i
|
||||
|
||||
Put('[)
|
||||
FOR i=0 TO size-1
|
||||
DO
|
||||
IF i>0 THEN Put(' ) FI
|
||||
PrintI(a(i))
|
||||
OD
|
||||
Put('])
|
||||
RETURN
|
||||
|
||||
PROC InsertionSort(INT ARRAY a INT size)
|
||||
INT i,j,value
|
||||
|
||||
FOR i=1 TO size-1
|
||||
DO
|
||||
value=a(i)
|
||||
j=i-1
|
||||
WHILE j>=0 AND a(j)>value
|
||||
DO
|
||||
a(j+1)=a(j)
|
||||
j==-1
|
||||
OD
|
||||
a(j+1)=value
|
||||
OD
|
||||
RETURN
|
||||
|
||||
BYTE FUNC IsSorted(INT ARRAY a INT n)
|
||||
INT ARRAY b(20)
|
||||
INT i
|
||||
|
||||
IF n=0 THEN
|
||||
RETURN (1)
|
||||
FI
|
||||
|
||||
MoveBlock(b,a,n*2)
|
||||
InsertionSort(b,n)
|
||||
FOR i=0 TO n-1
|
||||
DO
|
||||
IF b(i)#a(i) THEN
|
||||
RETURN (0)
|
||||
FI
|
||||
OD
|
||||
RETURN (1)
|
||||
|
||||
PROC Test(INT ARRAY a INT n)
|
||||
BYTE sorted
|
||||
|
||||
sorted=IsSorted(a,n)
|
||||
PrintArray(a,n)
|
||||
IF sorted THEN
|
||||
PrintE(" is sorted")
|
||||
ELSE
|
||||
PrintE(" is not sorted")
|
||||
FI
|
||||
RETURN
|
||||
|
||||
PROC Main()
|
||||
INT ARRAY
|
||||
a=[65530 0 1 2 10 13 16],
|
||||
b=[2 3 6 4],
|
||||
c=[3 3 3 3 3 3],
|
||||
d=[7]
|
||||
|
||||
Test(a,7)
|
||||
Test(b,4)
|
||||
Test(c,6)
|
||||
Test(d,1)
|
||||
Test(d,0)
|
||||
RETURN
|
||||
18
Task/JortSort/Ada/jortsort.ada
Normal file
18
Task/JortSort/Ada/jortsort.ada
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
with Ada.Text_IO, Ada.Containers.Generic_Array_Sort;
|
||||
|
||||
procedure Jortsort is
|
||||
|
||||
function Jort_Sort(List: String) return Boolean is
|
||||
procedure Sort is new Ada.Containers.Generic_Array_Sort
|
||||
(Positive, Character, Array_Type => String);
|
||||
Second_List: String := List;
|
||||
begin
|
||||
Sort(Second_List);
|
||||
return Second_List = List;
|
||||
end Jort_Sort;
|
||||
|
||||
use Ada.Text_IO;
|
||||
begin
|
||||
Put_Line("""abbigail"" sorted: " & Boolean'Image(Jort_Sort("abbigail")));
|
||||
Put_Line("""abbey"" sorted: " & Boolean'Image(Jort_Sort("abbey")));
|
||||
end Jortsort;
|
||||
57
Task/JortSort/AppleScript/jortsort.applescript
Normal file
57
Task/JortSort/AppleScript/jortsort.applescript
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
use AppleScript version "2.4"
|
||||
use framework "Foundation"
|
||||
use scripting additions
|
||||
|
||||
|
||||
------------------------- JORTSORT -------------------------
|
||||
|
||||
|
||||
-- jortSort :: Ord a => [a] -> Bool
|
||||
on jortSort(xs)
|
||||
xs = sort(xs)
|
||||
end jortSort
|
||||
|
||||
|
||||
--------------------------- TEST ---------------------------
|
||||
on run
|
||||
map(jortSort, {{4, 5, 1, 3, 2}, {1, 2, 3, 4, 5}})
|
||||
|
||||
--> {false, true}
|
||||
end run
|
||||
|
||||
|
||||
------------------------- GENERIC --------------------------
|
||||
|
||||
-- map :: (a -> b) -> [a] -> [b]
|
||||
on map(f, xs)
|
||||
-- The list obtained by applying f
|
||||
-- to each element of xs.
|
||||
tell mReturn(f)
|
||||
set lng to length of xs
|
||||
set lst to {}
|
||||
repeat with i from 1 to lng
|
||||
set end of lst to |λ|(item i of xs, i, xs)
|
||||
end repeat
|
||||
return lst
|
||||
end tell
|
||||
end map
|
||||
|
||||
|
||||
-- mReturn :: First-class m => (a -> b) -> m (a -> b)
|
||||
on mReturn(f)
|
||||
-- 2nd class handler function lifted into 1st class script wrapper.
|
||||
if script is class of f then
|
||||
f
|
||||
else
|
||||
script
|
||||
property |λ| : f
|
||||
end script
|
||||
end if
|
||||
end mReturn
|
||||
|
||||
|
||||
-- sort :: Ord a => [a] -> [a]
|
||||
on sort(xs)
|
||||
((current application's NSArray's arrayWithArray:xs)'s ¬
|
||||
sortedArrayUsingSelector:"compare:") as list
|
||||
end sort
|
||||
13
Task/JortSort/Arturo/jortsort.arturo
Normal file
13
Task/JortSort/Arturo/jortsort.arturo
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
jortSort?: function [a]->
|
||||
a = sort a
|
||||
|
||||
test: function [a]->
|
||||
print [a "is" (jortSort? a)? -> "sorted" -> "not sorted"]
|
||||
|
||||
test [1 2 3]
|
||||
test [2 3 1]
|
||||
|
||||
print ""
|
||||
|
||||
test ["a" "b" "c"]
|
||||
test ["c" "a" "b"]
|
||||
9
Task/JortSort/AutoHotkey/jortsort-1.ahk
Normal file
9
Task/JortSort/AutoHotkey/jortsort-1.ahk
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
JortSort(Array){
|
||||
sorted:=[]
|
||||
for index, val in Array
|
||||
sorted[val]:=1
|
||||
for key, val in sorted
|
||||
if (key<>Array[A_Index])
|
||||
return 0
|
||||
return 1
|
||||
}
|
||||
4
Task/JortSort/AutoHotkey/jortsort-2.ahk
Normal file
4
Task/JortSort/AutoHotkey/jortsort-2.ahk
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
Array1 := ["a", "d", "b" , "c"]
|
||||
Array2 := ["a", "b", "c" , "d"]
|
||||
MsgBox % JortSort(Array1) "`n" JortSort(Array2)
|
||||
return
|
||||
3
Task/JortSort/BQN/jortsort.bqn
Normal file
3
Task/JortSort/BQN/jortsort.bqn
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
JSort ← ≡⟜∧
|
||||
JSort 3‿2‿1
|
||||
0
|
||||
62
Task/JortSort/C++/jortsort.cpp
Normal file
62
Task/JortSort/C++/jortsort.cpp
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <iterator>
|
||||
|
||||
class jortSort {
|
||||
public:
|
||||
template<class T>
|
||||
bool jort_sort( T* o, size_t s ) {
|
||||
T* n = copy_array( o, s );
|
||||
sort_array( n, s );
|
||||
bool r = false;
|
||||
|
||||
if( n ) {
|
||||
r = check( o, n, s );
|
||||
delete [] n;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
private:
|
||||
template<class T>
|
||||
T* copy_array( T* o, size_t s ) {
|
||||
T* z = new T[s];
|
||||
memcpy( z, o, s * sizeof( T ) );
|
||||
//std::copy( o, o + s, z );
|
||||
return z;
|
||||
}
|
||||
template<class T>
|
||||
void sort_array( T* n, size_t s ) {
|
||||
std::sort( n, n + s );
|
||||
}
|
||||
template<class T>
|
||||
bool check( T* n, T* o, size_t s ) {
|
||||
for( size_t x = 0; x < s; x++ )
|
||||
if( n[x] != o[x] ) return false;
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
jortSort js;
|
||||
|
||||
template<class T>
|
||||
void displayTest( T* o, size_t s ) {
|
||||
std::copy( o, o + s, std::ostream_iterator<T>( std::cout, " " ) );
|
||||
std::cout << ": -> The array is " << ( js.jort_sort( o, s ) ? "sorted!" : "not sorted!" ) << "\n\n";
|
||||
}
|
||||
|
||||
int main( int argc, char* argv[] ) {
|
||||
const size_t s = 5;
|
||||
std::string oStr[] = { "5", "A", "D", "R", "S" };
|
||||
displayTest( oStr, s );
|
||||
std::swap( oStr[0], oStr[1] );
|
||||
displayTest( oStr, s );
|
||||
|
||||
int oInt[] = { 1, 2, 3, 4, 5 };
|
||||
displayTest( oInt, s );
|
||||
std::swap( oInt[0], oInt[1] );
|
||||
displayTest( oInt, s );
|
||||
|
||||
return 0;
|
||||
}
|
||||
22
Task/JortSort/C-sharp/jortsort.cs
Normal file
22
Task/JortSort/C-sharp/jortsort.cs
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
using System;
|
||||
|
||||
class Program
|
||||
{
|
||||
public static bool JortSort<T>(T[] array) where T : IComparable, IEquatable<T>
|
||||
{
|
||||
// sort the array
|
||||
T[] originalArray = (T[]) array.Clone();
|
||||
Array.Sort(array);
|
||||
|
||||
// compare to see if it was originally sorted
|
||||
for (var i = 0; i < originalArray.Length; i++)
|
||||
{
|
||||
if (!Equals(originalArray[i], array[i]))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
55
Task/JortSort/C/jortsort.c
Normal file
55
Task/JortSort/C/jortsort.c
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
|
||||
int number_of_digits(int x){
|
||||
int NumberOfDigits;
|
||||
for(NumberOfDigits=0;x!=0;NumberOfDigits++){
|
||||
x=x/10;
|
||||
}
|
||||
return NumberOfDigits;
|
||||
}
|
||||
|
||||
int* convert_array(char array[], int NumberOfElements) //converts integer arguments from char to int
|
||||
{
|
||||
int *convertedArray=malloc(NumberOfElements*sizeof(int));
|
||||
int originalElement, convertedElement;
|
||||
|
||||
for(convertedElement=0, originalElement=0; convertedElement<NumberOfElements; convertedElement++)
|
||||
{
|
||||
convertedArray[convertedElement]=atoi(&array[originalElement]);
|
||||
originalElement+=number_of_digits(convertedArray[convertedElement])+1; //computes where is the beginning of the next element
|
||||
|
||||
}
|
||||
return convertedArray;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int isSorted(int array[], int numberOfElements){
|
||||
int sorted=1;
|
||||
for(int counter=0;counter<numberOfElements;counter++){
|
||||
if(counter!=0 && array[counter-1]>array[counter]) sorted--;
|
||||
|
||||
}
|
||||
return sorted;
|
||||
}
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
int* convertedArray;
|
||||
|
||||
|
||||
convertedArray=convert_array(*(argv+1), argc-1);
|
||||
|
||||
|
||||
|
||||
if(isSorted(convertedArray, argc-1)==1) printf("Did you forgot to turn on your brain?! This array is already sorted!\n");
|
||||
else if(argc-1<=10) printf("Am I really supposed to sort this? Sort it by yourself!\n");
|
||||
else printf("Am I really supposed to sort this? Bhahahaha!\n");
|
||||
free(convertedArray);
|
||||
return 0;
|
||||
|
||||
|
||||
|
||||
}
|
||||
1
Task/JortSort/Clojure/jortsort.clj
Normal file
1
Task/JortSort/Clojure/jortsort.clj
Normal file
|
|
@ -0,0 +1 @@
|
|||
(defn jort-sort [x] (= x (sort x)))
|
||||
2
Task/JortSort/Common-Lisp/jortsort.lisp
Normal file
2
Task/JortSort/Common-Lisp/jortsort.lisp
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
(defun jort-sort (x)
|
||||
(equalp x (sort (copy-seq x) #'<)))
|
||||
3
Task/JortSort/Crystal/jortsort.crystal
Normal file
3
Task/JortSort/Crystal/jortsort.crystal
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
def jort_sort(array)
|
||||
array == array.sort
|
||||
end
|
||||
16
Task/JortSort/D/jortsort.d
Normal file
16
Task/JortSort/D/jortsort.d
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
module jortsort;
|
||||
|
||||
import std.algorithm : sort, SwapStrategy;
|
||||
|
||||
bool jortSort(T)(T[] array) {
|
||||
auto originalArray = array.dup;
|
||||
sort!("a < b", SwapStrategy.stable)(array);
|
||||
return originalArray == array;
|
||||
}
|
||||
|
||||
unittest {
|
||||
assert(jortSort([1, 2, 3]));
|
||||
assert(!jortSort([1, 6, 3]));
|
||||
assert(jortSort(["apple", "banana", "orange"]));
|
||||
assert(!jortSort(["two", "one", "three"]));
|
||||
}
|
||||
46
Task/JortSort/Delphi/jortsort.delphi
Normal file
46
Task/JortSort/Delphi/jortsort.delphi
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
program JortSort;
|
||||
|
||||
{$APPTYPE CONSOLE}
|
||||
{$R *.res}
|
||||
|
||||
uses
|
||||
System.SysUtils,
|
||||
System.Generics.Collections,
|
||||
System.Generics.Defaults;
|
||||
|
||||
type
|
||||
TArrayHelper = class helper for TArray
|
||||
public
|
||||
class function JortSort<T>(const original: TArray<T>): Boolean; static;
|
||||
end;
|
||||
|
||||
{ TArrayHelper }
|
||||
|
||||
class function TArrayHelper.JortSort<T>(const original: TArray<T>): Boolean;
|
||||
var
|
||||
sorted: TArray<T>;
|
||||
i: Integer;
|
||||
begin
|
||||
SetLength(sorted, Length(original));
|
||||
copy<T>(original, sorted, Length(original));
|
||||
Sort<T>(sorted);
|
||||
|
||||
for i := 0 to High(original) do
|
||||
if TComparer<T>.Default.Compare(sorted[i], original[i]) <> 0 then
|
||||
exit(False);
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
var
|
||||
test: TArray<Integer>;
|
||||
begin
|
||||
// true
|
||||
test := [1, 2, 3, 4, 5];
|
||||
Writeln(TArray.JortSort<Integer>(test));
|
||||
|
||||
// false
|
||||
test := [5, 4, 3, 2, 1];
|
||||
Writeln(TArray.JortSort<Integer>(test));
|
||||
|
||||
Readln;
|
||||
end.
|
||||
6
Task/JortSort/Elixir/jortsort.elixir
Normal file
6
Task/JortSort/Elixir/jortsort.elixir
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
iex(1)> jortsort = fn list -> list == Enum.sort(list) end
|
||||
#Function<6.90072148/1 in :erl_eval.expr/5>
|
||||
iex(2)> jortsort.([1,2,3,4])
|
||||
true
|
||||
iex(3)> jortsort.([1,2,5,4])
|
||||
false
|
||||
2
Task/JortSort/F-Sharp/jortsort.fs
Normal file
2
Task/JortSort/F-Sharp/jortsort.fs
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
let jortSort n=n=Array.sort n
|
||||
printfn "%A %A" (jortSort [|1;23;42|]) (jortSort [|23;42;1|])
|
||||
2
Task/JortSort/Factor/jortsort.factor
Normal file
2
Task/JortSort/Factor/jortsort.factor
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
USING: kernel sorting ;
|
||||
: jortsort ( seq -- ? ) dup natural-sort = ;
|
||||
62
Task/JortSort/FreeBASIC/jortsort.basic
Normal file
62
Task/JortSort/FreeBASIC/jortsort.basic
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
' FB 1.05.0 Win64
|
||||
|
||||
' Although it's possible to create generic sorting routines using macros in FreeBASIC
|
||||
' here we will just use Integer arrays.
|
||||
|
||||
Sub quicksort(a() As Integer, first As Integer, last As Integer)
|
||||
Dim As Integer length = last - first + 1
|
||||
If length < 2 Then Return
|
||||
Dim pivot As Integer = a(first + length\ 2)
|
||||
Dim lft As Integer = first
|
||||
Dim rgt As Integer = last
|
||||
While lft <= rgt
|
||||
While a(lft) < pivot
|
||||
lft +=1
|
||||
Wend
|
||||
While a(rgt) > pivot
|
||||
rgt -= 1
|
||||
Wend
|
||||
If lft <= rgt Then
|
||||
Swap a(lft), a(rgt)
|
||||
lft += 1
|
||||
rgt -= 1
|
||||
End If
|
||||
Wend
|
||||
quicksort(a(), first, rgt)
|
||||
quicksort(a(), lft, last)
|
||||
End Sub
|
||||
|
||||
Function jortSort(a() As Integer) As Boolean
|
||||
' copy the array
|
||||
Dim lb As Integer = LBound(a)
|
||||
Dim ub As Integer = UBound(a)
|
||||
Dim b(lb To ub) As Integer
|
||||
' this could be done more quickly using memcpy
|
||||
' but we just copy element by element here
|
||||
For i As Integer = lb To ub
|
||||
b(i) = a(i)
|
||||
Next
|
||||
' sort "b"
|
||||
quickSort(b(), lb, ub)
|
||||
' now compare with "a" to see if it's already sorted
|
||||
For i As Integer = lb To ub
|
||||
If a(i) <> b(i) Then Return False
|
||||
Next
|
||||
Return True
|
||||
End Function
|
||||
|
||||
Sub printResults(a() As Integer)
|
||||
For i As Integer = LBound(a) To UBound(a)
|
||||
Print a(i); " ";
|
||||
Next
|
||||
Print " => "; IIf(jortSort(a()), "sorted", "not sorted")
|
||||
End Sub
|
||||
|
||||
Dim a(4) As Integer = {1, 2, 3, 4, 5}
|
||||
printResults(a())
|
||||
Print
|
||||
Dim b(4) As Integer = {2, 1, 3, 4, 5}
|
||||
PrintResults(b())
|
||||
Print
|
||||
Print "Press any key to quit"
|
||||
Sleep
|
||||
27
Task/JortSort/Go/jortsort.go
Normal file
27
Task/JortSort/Go/jortsort.go
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"sort"
|
||||
)
|
||||
|
||||
func main() {
|
||||
log.Println(jortSort([]int{1, 2, 1, 11, 213, 2, 4})) //false
|
||||
log.Println(jortSort([]int{0, 1, 0, 0, 0, 0})) //false
|
||||
log.Println(jortSort([]int{1, 2, 4, 11, 22, 22})) //true
|
||||
log.Println(jortSort([]int{0, 0, 0, 1, 2, 2})) //true
|
||||
}
|
||||
|
||||
func jortSort(a []int) bool {
|
||||
c := make([]int, len(a))
|
||||
copy(c, a)
|
||||
sort.Ints(a)
|
||||
for k, v := range c {
|
||||
if v == a[k] {
|
||||
continue
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
4
Task/JortSort/Haskell/jortsort-1.hs
Normal file
4
Task/JortSort/Haskell/jortsort-1.hs
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
import Data.List (sort)
|
||||
|
||||
jortSort :: (Ord a) => [a] -> Bool
|
||||
jortSort list = list == sort list
|
||||
10
Task/JortSort/Haskell/jortsort-2.hs
Normal file
10
Task/JortSort/Haskell/jortsort-2.hs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
import Data.List (sort)
|
||||
|
||||
jortSort
|
||||
:: (Ord a)
|
||||
=> [a] -> Bool
|
||||
jortSort = (==) <*> sort
|
||||
|
||||
--------------------------- TEST ---------------------------
|
||||
main :: IO ()
|
||||
main = print $ jortSort <$> [[4, 5, 1, 3, 2], [1, 2, 3, 4, 5]]
|
||||
1
Task/JortSort/J/jortsort-1.j
Normal file
1
Task/JortSort/J/jortsort-1.j
Normal file
|
|
@ -0,0 +1 @@
|
|||
jortsort=: -: /:~
|
||||
1
Task/JortSort/J/jortsort-2.j
Normal file
1
Task/JortSort/J/jortsort-2.j
Normal file
|
|
@ -0,0 +1 @@
|
|||
jortSort=: assert@(-: /:~)
|
||||
6
Task/JortSort/J/jortsort-3.j
Normal file
6
Task/JortSort/J/jortsort-3.j
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
jortsort 1 2 4 3
|
||||
0
|
||||
jortsort 'sux'
|
||||
1
|
||||
jortsort&> 1 2 4 3;14 6 8;1 3 8 19;'ac';'sux';'CVGH';'PQRST'
|
||||
0 0 1 1 1 0 1
|
||||
5
Task/JortSort/Janet/jortsort.janet
Normal file
5
Task/JortSort/Janet/jortsort.janet
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
(defn jortsort [xs]
|
||||
(deep= xs (sorted xs)))
|
||||
|
||||
(print (jortsort @[1 2 3 4 5])) # true
|
||||
(print (jortsort @[2 1 3 4 5])) # false
|
||||
9
Task/JortSort/Java/jortsort.java
Normal file
9
Task/JortSort/Java/jortsort.java
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
public class JortSort {
|
||||
public static void main(String[] args) {
|
||||
System.out.println(jortSort(new int[]{1, 2, 3}));
|
||||
}
|
||||
|
||||
static boolean jortSort(int[] arr) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
13
Task/JortSort/JavaScript/jortsort.js
Normal file
13
Task/JortSort/JavaScript/jortsort.js
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
var jortSort = function( array ) {
|
||||
|
||||
// sort the array
|
||||
var originalArray = array.slice(0);
|
||||
array.sort( function(a,b){return a - b} );
|
||||
|
||||
// compare to see if it was originally sorted
|
||||
for (var i = 0; i < originalArray.length; ++i) {
|
||||
if (originalArray[i] !== array[i]) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
1
Task/JortSort/Jq/jortsort-1.jq
Normal file
1
Task/JortSort/Jq/jortsort-1.jq
Normal file
|
|
@ -0,0 +1 @@
|
|||
def jortsort: . == sort;
|
||||
1
Task/JortSort/Jq/jortsort-2.jq
Normal file
1
Task/JortSort/Jq/jortsort-2.jq
Normal file
|
|
@ -0,0 +1 @@
|
|||
[1, "snort", "sort", [1,2], {"1":2}] | jortsort
|
||||
1
Task/JortSort/Jq/jortsort-3.jq
Normal file
1
Task/JortSort/Jq/jortsort-3.jq
Normal file
|
|
@ -0,0 +1 @@
|
|||
true
|
||||
29
Task/JortSort/Jsish/jortsort.jsish
Normal file
29
Task/JortSort/Jsish/jortsort.jsish
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
/* jortSort in Jsish, based on the original satire, modified for jsish */
|
||||
var jortSort = function(arr:array):boolean {
|
||||
// make a copy
|
||||
var originalArray = arr.slice(0);
|
||||
// sort
|
||||
arr.sort( function(a,b) { return a - b; } );
|
||||
// compare to see if it was originally sorted
|
||||
for (var i = 0; i < originalArray.length; ++i) {
|
||||
if (originalArray[i] !== arr[i]) return false;
|
||||
}
|
||||
// yes, the data came in sorted
|
||||
return true;
|
||||
};
|
||||
|
||||
if (Interp.conf('unitTest')) {
|
||||
; jortSort([1,2,3]);
|
||||
; jortSort([3,2,1]);
|
||||
; jortSort([1, 'snort', 'sort', [1,2], {1:2}]);
|
||||
; jortSort(['snort', 'sort', 1, [1,2], {1:2}]);
|
||||
}
|
||||
|
||||
/*
|
||||
=!EXPECTSTART!=
|
||||
jortSort([1,2,3]) ==> true
|
||||
jortSort([3,2,1]) ==> false
|
||||
jortSort([1, 'snort', 'sort', [1,2], {1:2}]) ==> true
|
||||
jortSort(['snort', 'sort', 1, [1,2], {1:2}]) ==> false
|
||||
=!EXPECTEND!=
|
||||
*/
|
||||
1
Task/JortSort/Julia/jortsort.julia
Normal file
1
Task/JortSort/Julia/jortsort.julia
Normal file
|
|
@ -0,0 +1 @@
|
|||
jortsort(A) = sort(A) == A
|
||||
1
Task/JortSort/K/jortsort-1.k
Normal file
1
Task/JortSort/K/jortsort-1.k
Normal file
|
|
@ -0,0 +1 @@
|
|||
jortsort:{x~x@<x}
|
||||
1
Task/JortSort/K/jortsort-2.k
Normal file
1
Task/JortSort/K/jortsort-2.k
Normal file
|
|
@ -0,0 +1 @@
|
|||
jortsort 1 2 3
|
||||
25
Task/JortSort/Kotlin/jortsort.kotlin
Normal file
25
Task/JortSort/Kotlin/jortsort.kotlin
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
// version 1.0.6
|
||||
|
||||
fun <T> jortSort(a: Array<T>): Boolean {
|
||||
val b = a.copyOf()
|
||||
b.sort()
|
||||
for (i in 0 until a.size)
|
||||
if (a[i] != b[i]) return false
|
||||
return true
|
||||
}
|
||||
|
||||
fun <T> printResults(a: Array<T>) {
|
||||
println(a.joinToString(" ") + " => " + if (jortSort(a)) "sorted" else "not sorted")
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val a = arrayOf(1, 2, 3, 4, 5)
|
||||
printResults(a)
|
||||
val b = arrayOf(2, 1, 3, 4, 5)
|
||||
printResults(b)
|
||||
println()
|
||||
val c = arrayOf('A', 'B', 'C', 'D', 'E')
|
||||
printResults(c)
|
||||
val d = arrayOf('C', 'D', 'A', 'E', 'B')
|
||||
printResults(d)
|
||||
}
|
||||
14
Task/JortSort/Lua/jortsort.lua
Normal file
14
Task/JortSort/Lua/jortsort.lua
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
function copy (t)
|
||||
local new = {}
|
||||
for k, v in pairs(t) do new[k] = v end
|
||||
return new
|
||||
end
|
||||
|
||||
function jortSort (array)
|
||||
local originalArray = copy(array)
|
||||
table.sort(array)
|
||||
for i = 1, #originalArray do
|
||||
if originalArray[i] ~= array[i] then return false end
|
||||
end
|
||||
return true
|
||||
end
|
||||
9
Task/JortSort/Maple/jortsort.maple
Normal file
9
Task/JortSort/Maple/jortsort.maple
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
jortSort := proc(arr)
|
||||
local copy:
|
||||
copy := sort(Array([seq(arr[i], i=1..numelems(arr))])):
|
||||
return ArrayTools:-IsEqual(copy,arr):
|
||||
end proc:
|
||||
#Examples
|
||||
jortSort(Array([5,6,7,2,1]));
|
||||
jortSort(Array([-5,0,7,12,21]));
|
||||
jortSort(Array(StringTools:-Explode("abcdefg")));
|
||||
3
Task/JortSort/Mathematica/jortsort.math
Normal file
3
Task/JortSort/Mathematica/jortsort.math
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
jortSort[list_] := list == Sort[list];
|
||||
Print[jortSort[Range[100]]];
|
||||
Print[jortSort[RandomSample[Range[100]]]];
|
||||
13
Task/JortSort/Nim/jortsort.nim
Normal file
13
Task/JortSort/Nim/jortsort.nim
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
import algorithm
|
||||
|
||||
func jortSort[T](a: openArray[T]): bool =
|
||||
a == a.sorted()
|
||||
|
||||
proc test[T](a: openArray[T]) =
|
||||
echo a, " is ", if a.jortSort(): "" else: "not ", "sorted"
|
||||
|
||||
test([1, 2, 3])
|
||||
test([2, 3, 1])
|
||||
echo ""
|
||||
test(['a', 'b', 'c'])
|
||||
test(['c', 'a', 'b'])
|
||||
2
Task/JortSort/OCaml/jortsort-1.ocaml
Normal file
2
Task/JortSort/OCaml/jortsort-1.ocaml
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
let jortSortList lst =
|
||||
lst = List.sort compare lst
|
||||
4
Task/JortSort/OCaml/jortsort-2.ocaml
Normal file
4
Task/JortSort/OCaml/jortsort-2.ocaml
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
let jortSortArray ary =
|
||||
let originalArray = Array.copy ary in
|
||||
Array.sort compare ary;
|
||||
originalArray = ary
|
||||
12
Task/JortSort/Objeck/jortsort.objeck
Normal file
12
Task/JortSort/Objeck/jortsort.objeck
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
function : JortSort(elems : CompareVector) ~ Bool {
|
||||
sorted := CompareVector->New(elems);
|
||||
sorted->Sort();
|
||||
|
||||
each(i : sorted) {
|
||||
if(sorted->Get(i)->Compare(elems->Get(i)) <> 0) {
|
||||
return false;
|
||||
};
|
||||
};
|
||||
|
||||
return true;
|
||||
}
|
||||
1
Task/JortSort/Oforth/jortsort.fth
Normal file
1
Task/JortSort/Oforth/jortsort.fth
Normal file
|
|
@ -0,0 +1 @@
|
|||
: jortSort dup sort == ;
|
||||
11
Task/JortSort/OoRexx/jortsort.rexx
Normal file
11
Task/JortSort/OoRexx/jortsort.rexx
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
jortSort: Parse Arg list
|
||||
/*---------------------------------------------------------------------
|
||||
* Determine if list is sorted
|
||||
* << is used to avoid numeric comparison
|
||||
* 3 4e-1 is sorted
|
||||
*--------------------------------------------------------------------*/
|
||||
Do i=2 To words(list)
|
||||
If word(list,i)<<word(list,i-1) Then
|
||||
Leave
|
||||
End
|
||||
Return (i=words(list)+1)|(list='')
|
||||
1
Task/JortSort/PARI-GP/jortsort.parigp
Normal file
1
Task/JortSort/PARI-GP/jortsort.parigp
Normal file
|
|
@ -0,0 +1 @@
|
|||
jortSort(v)=vecsort(v)==v
|
||||
7
Task/JortSort/Perl/jortsort.pl
Normal file
7
Task/JortSort/Perl/jortsort.pl
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
sub jortsort {
|
||||
my @s=sort @_; # Default standard string comparison
|
||||
for (0..$#s) {
|
||||
return 0 unless $_[$_] eq $s[$_];
|
||||
}
|
||||
1;
|
||||
}
|
||||
5
Task/JortSort/Phix/jortsort-1.phix
Normal file
5
Task/JortSort/Phix/jortsort-1.phix
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
(phixonline)-->
|
||||
<span style="color: #008080;">type</span> <span style="color: #000000;">JortSort</span><span style="color: #0000FF;">(</span><span style="color: #004080;">sequence</span> <span style="color: #000000;">s</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #008080;">return</span> <span style="color: #000000;">s</span><span style="color: #0000FF;">=</span><span style="color: #7060A8;">sort</span><span style="color: #0000FF;">(</span><span style="color: #000000;">s</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">type</span>
|
||||
<!--
|
||||
4
Task/JortSort/Phix/jortsort-2.phix
Normal file
4
Task/JortSort/Phix/jortsort-2.phix
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
(phixonline)-->
|
||||
<span style="color: #000000;">JortSort</span> <span style="color: #000000;">ok</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">2</span><span style="color: #0000FF;">,</span><span style="color: #000000;">3</span><span style="color: #0000FF;">}</span>
|
||||
<span style="color: #000000;">JortSort</span> <span style="color: #000000;">bad</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">5</span><span style="color: #0000FF;">,</span><span style="color: #000000;">4</span><span style="color: #0000FF;">,</span><span style="color: #000000;">6</span><span style="color: #0000FF;">}</span>
|
||||
<!--
|
||||
3
Task/JortSort/Phix/jortsort-3.phix
Normal file
3
Task/JortSort/Phix/jortsort-3.phix
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
(phixonline)-->
|
||||
<span style="color: #008080;">global</span> <span style="color: #008080;">constant</span> <span style="color: #000000;">T_while</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">336</span> <span style="color: #000000;">tt_stringF</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"while"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">T_while</span><span style="color: #0000FF;">)</span>
|
||||
<!--
|
||||
18
Task/JortSort/Picat/jortsort.picat
Normal file
18
Task/JortSort/Picat/jortsort.picat
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
go =>
|
||||
List = [
|
||||
[1,2,3,4,5],
|
||||
[2,3,4,5,1],
|
||||
[2],
|
||||
"jortsort",
|
||||
"jortsort".sort()
|
||||
],
|
||||
foreach(L in List)
|
||||
printf("%w: ", L),
|
||||
if not jortsort(L) then
|
||||
print("not ")
|
||||
end,
|
||||
println("sorted")
|
||||
end,
|
||||
nl.
|
||||
|
||||
jortsort(X) => X == X.sort().
|
||||
2
Task/JortSort/PicoLisp/jortsort.l
Normal file
2
Task/JortSort/PicoLisp/jortsort.l
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
(de jortSort (L) (= L (sort L)))
|
||||
(jortSort (1 2 3))
|
||||
3
Task/JortSort/PowerShell/jortsort.psh
Normal file
3
Task/JortSort/PowerShell/jortsort.psh
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
function jortsort($a) { -not (Compare-Object $a ($a | sort) -SyncWindow 0)}
|
||||
jortsort @(1,2,3)
|
||||
jortsort @(2,3,1)
|
||||
20
Task/JortSort/PureBasic/jortsort.basic
Normal file
20
Task/JortSort/PureBasic/jortsort.basic
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
Macro isSort(liste)
|
||||
If OpenConsole()
|
||||
Print("[ ") : ForEach liste : Print(liste+Space(1)) : Next : Print("] = ")
|
||||
If jortSort(liste) : PrintN("True") : Else : PrintN("False") : EndIf
|
||||
EndIf
|
||||
EndMacro
|
||||
|
||||
Procedure.b jortSort(List jortS.s())
|
||||
NewList cpy.s() : CopyList(jortS(),cpy()) : SortList(cpy(),#PB_Sort_Ascending)
|
||||
ForEach jortS()
|
||||
SelectElement(cpy(),ListIndex(jortS()))
|
||||
If Not jortS()=cpy() : ProcedureReturn #False : EndIf
|
||||
Next
|
||||
ProcedureReturn #True
|
||||
EndProcedure
|
||||
|
||||
NewList l1.s()
|
||||
For i=1 To 10 : AddElement(l1()) : l1()=Chr(Random(90,65)) : Next
|
||||
isSort(l1()) : SortList(l1(),#PB_Sort_Ascending) : isSort(l1())
|
||||
Input()
|
||||
11
Task/JortSort/Python/jortsort.py
Normal file
11
Task/JortSort/Python/jortsort.py
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
>>> def jortsort(sequence):
|
||||
return list(sequence) == sorted(sequence)
|
||||
>>> for data in [(1,2,4,3), (14,6,8), ['a', 'c'], ['s', 'u', 'x'], 'CVGH', 'PQRST']:
|
||||
print(f'jortsort({repr(data)}) is {jortsort(data)}')
|
||||
jortsort((1, 2, 4, 3)) is False
|
||||
jortsort((14, 6, 8)) is False
|
||||
jortsort(['a', 'c']) is True
|
||||
jortsort(['s', 'u', 'x']) is True
|
||||
jortsort('CVGH') is False
|
||||
jortsort('PQRST') is True
|
||||
>>>
|
||||
4
Task/JortSort/Quackery/jortsort-1.quackery
Normal file
4
Task/JortSort/Quackery/jortsort-1.quackery
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
[ dup
|
||||
' [ sortwith ]
|
||||
]'[ nested join
|
||||
do = ] is jortsortwith ( [ --> b )
|
||||
8
Task/JortSort/Quackery/jortsort-2.quackery
Normal file
8
Task/JortSort/Quackery/jortsort-2.quackery
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
[ true swap
|
||||
]'[ temp put
|
||||
dup [] != if
|
||||
[ behead swap witheach
|
||||
[ tuck temp share do if
|
||||
[ dip not conclude ] ] ]
|
||||
drop
|
||||
temp release ] is sortedwith ( [ --> b )
|
||||
26
Task/JortSort/REXX/jortsort-1.rexx
Normal file
26
Task/JortSort/REXX/jortsort-1.rexx
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
/*REXX program verifies that an array is sorted using a jortSort algorithm. */
|
||||
parse arg $ /*obtain the list of numbers from C.L. */
|
||||
if $='' then $=1 2 4 3 /*Not specified? Then use the default.*/
|
||||
say 'array items=' space($) /*display the list to the terminal. */
|
||||
if jortSort($) then say 'The array is sorted.'
|
||||
else say "The array isn't sorted."
|
||||
exit /*stick a fork in it, we're all done. */
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
eSort: procedure expose @.; h=@.0 /*exchange sort.*/
|
||||
do while h>1; h=h%2
|
||||
do i=1 for @.0-h; j=i; k=h+i
|
||||
do while @.k<@.j; t=@.j; @.j=@.k; @.k=t
|
||||
if h>=j then leave; j=j-h; k=k-h
|
||||
end /*while @.k<@.j*/
|
||||
end /*i*/
|
||||
end /*while h>1*/
|
||||
return
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
jortSort: parse arg x; @.0=words(x) /*assign # items in list. */
|
||||
do j=1 for @.0; !.j=word(x,j); @.j=!.j /*save a copy of original.*/
|
||||
end /*j*/
|
||||
call eSort /*sort with exchange sort.*/
|
||||
do k=1 for @.0
|
||||
if !.k\==@.k then return 0 /*the array isn't sorted. */
|
||||
end /*k*/
|
||||
return 1 /*the array is sorted. */
|
||||
15
Task/JortSort/REXX/jortsort-2.rexx
Normal file
15
Task/JortSort/REXX/jortsort-2.rexx
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
/*REXX program verifies that an array is sorted using a jortSort algorithm. */
|
||||
parse arg $ /*obtain the list of numbers from C.L. */
|
||||
if $='' then $=1 2 4 3 /*Not specified? Then use the default.*/
|
||||
say 'array items=' space($) /*display the list to the terminal. */
|
||||
if jortSort($) then say 'The array is sorted.'
|
||||
else say "The array isn't sorted."
|
||||
exit /*stick a fork in it, we're all done. */
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
jortSort: parse arg x
|
||||
p=word(x,1)
|
||||
do j=2 to words(x); _=word(x,j)
|
||||
if _<p then return 0 /*array isn't sorted.*/
|
||||
p=_
|
||||
end /*j*/
|
||||
return 1 /*array is sorted.*/
|
||||
3
Task/JortSort/Racket/jortsort-1.rkt
Normal file
3
Task/JortSort/Racket/jortsort-1.rkt
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
#lang racket/base
|
||||
(define (jort-sort l [<? <])
|
||||
(equal? l (sort l <?)))
|
||||
3
Task/JortSort/Racket/jortsort-2.rkt
Normal file
3
Task/JortSort/Racket/jortsort-2.rkt
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
#lang racket/base
|
||||
(define (jort-sort l [<? <])
|
||||
(eq? l (sort l <?)))
|
||||
5
Task/JortSort/Racket/jortsort-3.rkt
Normal file
5
Task/JortSort/Racket/jortsort-3.rkt
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
#lang racket/base
|
||||
(define (jort-sort l [<? <])
|
||||
(or (null? l)
|
||||
(for/and ([x (in-list l)] [y (in-list (cdr l))])
|
||||
(not (<? y x))))) ; same as (<= x y) but using only <?
|
||||
1
Task/JortSort/Raku/jortsort-1.raku
Normal file
1
Task/JortSort/Raku/jortsort-1.raku
Normal file
|
|
@ -0,0 +1 @@
|
|||
sub jort-sort { @_ eqv @_.sort }
|
||||
1
Task/JortSort/Raku/jortsort-2.raku
Normal file
1
Task/JortSort/Raku/jortsort-2.raku
Normal file
|
|
@ -0,0 +1 @@
|
|||
sub jort-sort-more-better-sorta { [!after] @_ }
|
||||
10
Task/JortSort/Ring/jortsort.ring
Normal file
10
Task/JortSort/Ring/jortsort.ring
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
aList = [4,2,3,1]
|
||||
see jortSort(aList) + nl
|
||||
|
||||
func jortSort array
|
||||
originalArray = array
|
||||
array = sort(array)
|
||||
for i= 1 to len(originalArray)
|
||||
if originalArray[i] != array[i] return false ok
|
||||
next
|
||||
return true
|
||||
3
Task/JortSort/Ruby/jortsort-1.rb
Normal file
3
Task/JortSort/Ruby/jortsort-1.rb
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
def jort_sort(array)
|
||||
array == array.sort
|
||||
end
|
||||
12
Task/JortSort/Ruby/jortsort-2.rb
Normal file
12
Task/JortSort/Ruby/jortsort-2.rb
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
def jort_sort(array)
|
||||
# sort the array
|
||||
original_array = array.dup
|
||||
array.sort!
|
||||
|
||||
# compare to see if it was originally sorted
|
||||
original_array.length.times do |i|
|
||||
return false if original_array[i] != array[i]
|
||||
end
|
||||
|
||||
true
|
||||
end
|
||||
16
Task/JortSort/Rust/jortsort-1.rust
Normal file
16
Task/JortSort/Rust/jortsort-1.rust
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
use std::cmp::{Ord, Eq};
|
||||
|
||||
fn jort_sort<T: Ord + Eq + Clone>(array: Vec<T>) -> bool {
|
||||
// sort the array
|
||||
let mut sorted_array = array.to_vec();
|
||||
sorted_array.sort();
|
||||
|
||||
// compare to see if it was originally sorted
|
||||
for i in 0..array.len() {
|
||||
if array[i] != sorted_array[i] {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
12
Task/JortSort/Rust/jortsort-2.rust
Normal file
12
Task/JortSort/Rust/jortsort-2.rust
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
fn jort_sort<T>(slice: &[T]) -> bool
|
||||
where
|
||||
T: Ord + PartialEq + Clone,
|
||||
{
|
||||
let mut sorted = slice.to_vec();
|
||||
sorted.sort_unstable();
|
||||
|
||||
slice
|
||||
.iter()
|
||||
.zip(sorted.iter())
|
||||
.all(|(orig, sorted)| orig == sorted)
|
||||
}
|
||||
9
Task/JortSort/Rust/jortsort-3.rust
Normal file
9
Task/JortSort/Rust/jortsort-3.rust
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
fn jort_sort<T>(slice: &[T]) -> bool
|
||||
where
|
||||
T: Ord + PartialEq + Clone,
|
||||
{
|
||||
let mut sorted = slice.to_vec();
|
||||
sorted.sort_unstable();
|
||||
|
||||
slice == sorted
|
||||
}
|
||||
25
Task/JortSort/SSEM/jortsort.ssem
Normal file
25
Task/JortSort/SSEM/jortsort.ssem
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
11011000000000100000000000000000 0. -27 to c
|
||||
00000000000000110000000000000000 1. Test
|
||||
11101000000000000000000000000000 2. 23 to CI
|
||||
10011000000001100000000000000000 3. c to 25
|
||||
10011000000000100000000000000000 4. -25 to c
|
||||
01011000000000010000000000000000 5. Sub. 26
|
||||
00000000000000110000000000000000 6. Test
|
||||
10101000000001000000000000000000 7. Add 21 to CI
|
||||
00011000000000000000000000000000 8. 24 to CI
|
||||
10011000000000100000000000000000 9. -25 to c
|
||||
01011000000001100000000000000000 10. c to 26
|
||||
00000000000000100000000000000000 11. -0 to c
|
||||
10101000000000010000000000000000 12. Sub. 21
|
||||
00000000000001100000000000000000 13. c to 0
|
||||
00000000000000100000000000000000 14. -0 to c
|
||||
00000000000001100000000000000000 15. c to 0
|
||||
01101000000000000000000000000000 16. 22 to CI
|
||||
11111000000000100000000000000000 17. -31 to c
|
||||
00000000000001110000000000000000 18. Stop
|
||||
10101000000000100000000000000000 19. -21 to c
|
||||
00000000000001110000000000000000 20. Stop
|
||||
10000000000000000000000000000000 21. 1
|
||||
11111111111111111111111111111111 22. -1
|
||||
00001000000000000000000000000000 23. 16
|
||||
01001000000000000000000000000000 24. 18
|
||||
3
Task/JortSort/Scala/jortsort.scala
Normal file
3
Task/JortSort/Scala/jortsort.scala
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
import java.util.Objects.deepEquals
|
||||
|
||||
def jortSort[K:Ordering]( a:Array[K] ) = deepEquals(a.sorted, a)
|
||||
1
Task/JortSort/Sidef/jortsort.sidef
Normal file
1
Task/JortSort/Sidef/jortsort.sidef
Normal file
|
|
@ -0,0 +1 @@
|
|||
func jort_sort(array) { array == array.sort };
|
||||
3
Task/JortSort/Swift/jortsort-1.swift
Normal file
3
Task/JortSort/Swift/jortsort-1.swift
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
func jortSort<T:Comparable>(array: [T]) -> Bool {
|
||||
return array == sorted(array)
|
||||
}
|
||||
13
Task/JortSort/Swift/jortsort-2.swift
Normal file
13
Task/JortSort/Swift/jortsort-2.swift
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
func jortSort<T:Comparable>(inout array: [T]) -> Bool {
|
||||
|
||||
// sort the array
|
||||
let originalArray = array
|
||||
array.sort({$0 < $1})
|
||||
|
||||
// compare to see if it was originally sorted
|
||||
for var i = 0; i < originalArray.count; ++i {
|
||||
if originalArray[i] != array[i] { return false }
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
6
Task/JortSort/Tcl/jortsort.tcl
Normal file
6
Task/JortSort/Tcl/jortsort.tcl
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
proc jortsort {args} {
|
||||
set list [lindex $args end]
|
||||
set list [list {*}$list] ;# ensure canonical list form
|
||||
set options [lrange $args 0 end-1]
|
||||
expr {[lsort {*}$options $list] eq $list}
|
||||
}
|
||||
16
Task/JortSort/UNIX-Shell/jortsort.sh
Normal file
16
Task/JortSort/UNIX-Shell/jortsort.sh
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
JortSort() {
|
||||
cmp -s <(printf “%s\n” “$@“) <(printf “%s\n” “$@“ | sort)
|
||||
}
|
||||
|
||||
JortSortVerbose() {
|
||||
if JortSort “$@“; then
|
||||
echo True
|
||||
else
|
||||
echo False
|
||||
If
|
||||
}
|
||||
|
||||
JortSortVerbose 1 2 3 4 5
|
||||
JortSortVerbose 1 3 4 5 2
|
||||
JortSortVerbose a b c
|
||||
JortSortVerbose c a b
|
||||
19
Task/JortSort/V-(Vlang)/jortsort.v
Normal file
19
Task/JortSort/V-(Vlang)/jortsort.v
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
fn main() {
|
||||
println(jort_sort([1, 2, 1, 11, 213, 2, 4])) //false
|
||||
println(jort_sort([0, 1, 0, 0, 0, 0])) //false
|
||||
println(jort_sort([1, 2, 4, 11, 22, 22])) //true
|
||||
println(jort_sort([0, 0, 0, 1, 2, 2])) //true
|
||||
}
|
||||
|
||||
fn jort_sort(a []int) bool {
|
||||
mut c := a.clone()
|
||||
c.sort()
|
||||
for k, v in c {
|
||||
if v == a[k] {
|
||||
continue
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
25
Task/JortSort/VBScript/jortsort.vb
Normal file
25
Task/JortSort/VBScript/jortsort.vb
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
Function JortSort(s)
|
||||
JortSort = True
|
||||
arrPreSort = Split(s,",")
|
||||
Set arrSorted = CreateObject("System.Collections.ArrayList")
|
||||
'Populate the resorted arraylist.
|
||||
For i = 0 To UBound(arrPreSort)
|
||||
arrSorted.Add(arrPreSort(i))
|
||||
Next
|
||||
arrSorted.Sort()
|
||||
'Compare the elements of both arrays.
|
||||
For j = 0 To UBound(arrPreSort)
|
||||
If arrPreSort(j) <> arrSorted(j) Then
|
||||
JortSort = False
|
||||
Exit For
|
||||
End If
|
||||
Next
|
||||
End Function
|
||||
|
||||
WScript.StdOut.Write JortSort("1,2,3,4,5")
|
||||
WScript.StdOut.WriteLine
|
||||
WScript.StdOut.Write JortSort("1,2,3,5,4")
|
||||
WScript.StdOut.WriteLine
|
||||
WScript.StdOut.Write JortSort("a,b,c")
|
||||
WScript.StdOut.WriteLine
|
||||
WScript.StdOut.Write JortSort("a,c,b")
|
||||
12
Task/JortSort/Wren/jortsort.wren
Normal file
12
Task/JortSort/Wren/jortsort.wren
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
import "/sort" for Sort
|
||||
|
||||
var jortSort = Fn.new { |a|
|
||||
var b = Sort.merge(a)
|
||||
for (i in 0...a.count) {
|
||||
if (a[i] != b[i]) return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
var tests = [ [1, 2, 3, 4, 5], [2, 1, 3, 4, 5] ]
|
||||
for (test in tests) System.print("%(test) -> %(jortSort.call(test) ? "sorted" : "not sorted")")
|
||||
26
Task/JortSort/XPL0/jortsort.xpl0
Normal file
26
Task/JortSort/XPL0/jortsort.xpl0
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
include xpllib; \for Sort
|
||||
|
||||
func JortSort(A, N);
|
||||
int A, N, B, I;
|
||||
def SizeOfInt = 4;
|
||||
[B:= Reserve(N*SizeOfInt);
|
||||
for I:= 0 to N-1 do B(I):= A(I);
|
||||
Sort(B, N);
|
||||
for I:= 0 to N-1 do
|
||||
if B(I) # A(I) then return false;
|
||||
return true;
|
||||
];
|
||||
|
||||
int Tests, Test, I;
|
||||
def Size = 5;
|
||||
[Tests:= [ [1, 2, 3, 4, 5], [2, 1, 3, 4, 5] ];
|
||||
for Test:= 0 to 2-1 do
|
||||
[ChOut(0, ^[);
|
||||
for I:= 0 to Size-2 do
|
||||
[IntOut(0, Tests(Test,I)); Text(0, ", ")];
|
||||
IntOut(0, Tests(Test,I));
|
||||
Text(0, "] -> ");
|
||||
Text(0, if JortSort(Tests(Test), Size) then "sorted" else "not sorted");
|
||||
CrLf(0);
|
||||
];
|
||||
]
|
||||
1
Task/JortSort/Zkl/jortsort-1.zkl
Normal file
1
Task/JortSort/Zkl/jortsort-1.zkl
Normal file
|
|
@ -0,0 +1 @@
|
|||
fcn jort(list){ False!=list.reduce(fcn(a,b){ (a>b) and return(Void.Stop,False); b }) }
|
||||
1
Task/JortSort/Zkl/jortsort-2.zkl
Normal file
1
Task/JortSort/Zkl/jortsort-2.zkl
Normal file
|
|
@ -0,0 +1 @@
|
|||
fcn jort(list){ list==list.copy().sort() }
|
||||
Loading…
Add table
Add a link
Reference in a new issue