Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -0,0 +1,63 @@
*** GNOME SORT *****************************************************************
* GNOME(V) -- gnome sort of the numerical vector V.
*** HELPER FUNCTIONS ***********************************************************
* IDXMAX(V) -- highest index of vector V.
* IDXMIN(V) -- lowest index of vector V.
* NUMBER(V) -- succeeds if V is some form of numerical data, fails otherwise.
* NUMBERS(V) -- succeeds iff all elements of vector V are numerical
* SWAP(A,B) -- swaps the values of two variables (named with .var).
* VECTOR(V) -- succeeds iff V is a vector.
********************************************************************************
define('GNOME(V)I,J,K,L,H,T')
*
define('IDXMAX(V)')
define('IDXMIN(V)')
define('NUMBER(V)')
define('NUMBERS(V)I,M')
define('SWAP(SWAP_PARAMETER_VAR_A,SWAP_PARAMETER_VAR_B)')
define('VECTOR(V)')
:(GNOME.END)
****************************************
* GNOME FUNCTION *
****************************************
GNOME numbers(v) :F(FRETURN)
gnome = copy(v)
l = idxmin(v) ; h = idxmax(v) ; i = l + 1
GNOME.LOOP j = i - 1
le(i, l) :S(GNOME.FORWARD)
gt(i,h) :S(RETURN)
le(gnome<j>, gnome<i>) :S(GNOME.FORWARD)
swap(.gnome<j>, .gnome<i>)
i = i - 1 :(GNOME.LOOP)
GNOME.FORWARD i = i + 1 :(GNOME.LOOP)
****************************************
* HELPER FUNCTIONS *
****************************************
IDXMAX vector(v) :F(FRETURN)
prototype(v) ':' span('-' &digits) . idxmax :S(RETURN)F(IDXMAX.NORM)
IDXMAX.NORM idxmax = prototype(v) :(RETURN)
****************************************
IDXMIN vector(v) :F(FRETURN)
prototype(v) span('-' &digits) . idxmin ':' :S(RETURN)F(IDXMIN.NORM)
IDXMIN.NORM idxmin = 1 :(RETURN)
****************************************
NUMBER ident(datatype(v), 'INTEGER') :S(RETURN)
ident(datatype(v), 'REAL') :S(RETURN)F(FRETURN)
****************************************
NUMBERS vector(v) :F(FRETURN)
i = idxmin(v) ; m = idxmax(v)
NUMBERS.LOOP le(i,m) :F(RETURN)
number(v<i>) :F(FRETURN)
i = i + 1 :(NUMBERS.LOOP)
****************************************
SWAP SWAP = $SWAP_PARAMETER_VAR_A
$SWAP_PARAMETER_VAR_A = $SWAP_PARAMETER_VAR_B
$SWAP_PARAMETER_VAR_B = SWAP
SWAP = :(RETURN)
****************************************
VECTOR ident(v) :S(FRETURN)
prototype(v) ',' :S(FRETURN)F(RETURN)
****************************************
GNOME.END

View file

@ -0,0 +1,29 @@
-INCLUDE 'gnome_sort.sno'
GNOME.TEST output = 'valid values...'
a = array(5)
a<1> = 50 ; a<2> = 40 ; a<3> = 10
a<4> = 30 ; a<5> = 20
b = gnome(a) :F(ERROR)
eq(b<1>,10) ; eq(b<2>,20) ; eq(b<3>,30) :F(ERROR)
eq(b<4>,40) ; eq(b<5>,50) :F(ERROR)
a = array('-2:2')
a<-2> = 50 ; a<-1> = 40 ; a<0> = 10
a<1> = 30 ; a<2> = 20
b = gnome(a) :F(ERROR)
eq(b<-2>,10) ; eq(b<-1>,20) ; eq(b<0>,30) :F(ERROR)
eq(b<1>,40) ; eq(b<2>,50) :F(ERROR)
a = array(5)
a<1> = 5.5 ; a<2> = 4.4 ; a<3> = 1.1
a<4> = 3.3 ; a<5> = 2.2
b = gnome(a) :F(ERROR)
eq(b<1>,1.1) ; eq(b<2>,2.2) ; eq(b<3>,3.3) :F(ERROR)
eq(b<4>,4.4) ; eq(b<5>,5.5) :F(ERROR)
output = 'invalid values...'
a = array(5, "five")
b = gnome(a) :S(ERROR)
a = array(5)
b = gnome(a) :S(ERROR)
output = 'PASSED!'
END