-
Notifications
You must be signed in to change notification settings - Fork 1
/
sort.4th.txt
72 lines (50 loc) · 946 Bytes
/
sort.4th.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
74755 CONSTANT RAND1
1309 CONSTANT RAND2
13849 CONSTANT RAND3
65535 CONSTANT RAND4
VARIABLE SEED
RAND1 SEED !
: RAND
SEED @
RAND2 *
RAND3 +
RAND4 AND
SEED !
SEED @
;
6000 CONSTANT SIZE
SIZE 1- cell * VARIABLE INTS ALLOT
: INIT
RAND1 SEED !
INTS
SIZE 0 DO
RAND OVER !
cell +
LOOP
DROP
;
: SORTINTS
INIT
ms@
SIZE 1- 0 DO
\ just walk two ptrs by 1+ in the inner loop
INTS
DUP cell + ( -- INTS INTS+1 )
SIZE 1- I - 0 DO
OVER @ ( -- INTS INTS+1 INTS.value )
OVER @ ( -- INTS INTS+1 INTS.value INTS+1.value )
2DUP ( -- INTS INTS+1 INTS.value INTS+1.value INTS.value INTS+1.value )
> IF ( -- INTS INTS+1 INTS.value INTS+1.value )
3 PICK ! ( -- INTS INTS+1 INTS.value )
1 PICK ! ( -- INTS INTS+1 )
ELSE
2DROP ( -- INTS INTS+1 )
THEN
cell +
SWAP cell +
SWAP
LOOP
2DROP
LOOP
ms@ - .
;