Home » CEEFAX disks » telesoftware17.adl » 25-08-89/SorTest
25-08-89/SorTest
This website contains an archive of files for the Acorn Electron, BBC Micro, Acorn Archimedes, Commodore 16 and Commodore 64 computers, which Dominic Ford has rescued from his private collection of floppy disks and cassettes.
Some of these files were originally commercial releases in the 1980s and 1990s, but they are now widely available online. I assume that copyright over them is no longer being asserted. If you own the copyright and would like files to be removed, please contact me.
Tape/disk: | Home » CEEFAX disks » telesoftware17.adl |
Filename: | 25-08-89/SorTest |
Read OK: | ✔ |
File size: | 1DEB bytes |
Load address: | FFFF0E00 |
Exec address: | FFFF802B |
File contents
10REM:SorTest by L.L.J.Vick (22/2/89) 20ONERROR:REPORT:PRINT" at line ";ERL:PROCquit:END 30MODE7:C=(HIMEM-TOP-2000)DIV12 40DIMa%(C),q%(C),s%(C),c%(7),time%(9),M$(9),O$(6) 50S$=" Sort":FORI=1TO6:READO$(I):NEXT 60*KEY0RUN|M 70REPEAT:MODE7:PROCinit 80FORmthd=first TOlast 90FORI%=0TON%:q%(I%)=I%:NEXT:delay=2E3 100VDU26,12:PRINT'M$(mthd)S$ 110VDU28,0,24,39,2 120PRINT'"Sorting in progress." 130TIME=0 140IFspd=1:PROCslow:ELSE:PROCfast 150time%(mthd)=TIME 160IFlast=first:PROClist 170PRINT'"Time taken = "FNtime 180PROCcont:NEXT 190IFlast>first:PROCresults 200UNTILFALSE 210: 220DEFPROCslow 230IFmthd=1:PROCbubble 240IFmthd=2:PROCbubble_flag 250IFmthd=3:PROCbubble_monitor 260IFmthd=4:PROCshaker 270IFmthd=5:PROCstr_insertion 280IFmthd=6:PROCbin_insertion 290IFmthd=7:PROCselection 300ENDPROC 310: 320DEFPROCfast 330IFmthd=1:PROCshell(2) 340IFmthd=2:PROCshell(3) 350IFmthd=3:PROCquick 360IFmthd=4:PROCquick_nr 370IFmthd=5:PROCquickinsert 380IFmthd=6:PROCheap 390IFmthd=7:PROCradix 400IFmthd=8:PROCstr_rad(3) 410IFmthd=9:PROCmerge(1,N%) 420ENDPROC 430: 440DATAPerfect,Near-Perfect,Reverse,Random,Well distributed,With many equal 450DATA7,Bubble,Bubble (with Flag),Bubble (with Monitor),Shaker,Straight Insertion,Binary Insertion,Selection 460DATA9,Shell(2),Shell(3),Quick (recursive),Quick (non-recursive),Quick/Insertion,Heap,Radix Exchange,Straight Radix,Merge 470: 480DEFPROCinit 490FORI=0TO1:PRINTTAB(3,I)CHR$141"SORTING ALGORITHMS ON TEST":NEXT 500@%=&606:VDU28,1,24,39,2 510REPEAT:CLS:PRINTTAB(1,9)"Choose a number, less than "STR$(C+1)"." 520PRINTTAB(0,20)"Press H (RETURN) for Help & Information"; 530INPUTTAB(13,11)"N = "n$:IFLENn$<5:N%=VALn$:ELSE:N%=0:VDU7 540IFn$="H"ORn$="h":S%=2:VDU7:CHAIN"T/Sorts" 550UNTILN%>1ANDN%<=C 560N$="The original Number Sequence ":n$=STR$(N%):CLS 570P$="a Permutation of 1 to ":R$="a Random set " 580PRINT'N$"consists"''"of a set of integers which can be:-"' 590PRINT"EITHER "P$n$' 600FORI=1TO4:PRINTI"...In "O$(I)" order"':NEXT 610PRINT"OR "R$"in this range"' 620FORI=5TO6:PRINTI"..."O$(I)':NEXT 630REPEAT:PRINTTAB(5,21)"Choose (1 to 6) :"; 640O%=GET-48:UNTILO%>0ANDO%<7 650PRINTTAB(24,21)STR$(O%)" wait!"; 660FORI%=0TON%:a%(I%)=I%:NEXT 670I%=RND(-N%) 680IFO%=2:PROCnear 690IFO%=3:PROCrev 700IFO%=4:PROCperm 710IFO%=5:PROCrandom 720IFO%=6:PROCequal_keys 730CLS:PRINTTAB(0,9)"Do you want the 'slow' or the 'fast'"''TAB(8)"methods? (S/F) :"; 740spd=FNin("SF") 750CLS:IFspd=1:RESTORE450:ELSERESTORE460 760READmethods 770FORI=1TOmethods:READM$(I):PRINT'I"..."M$(I)S$:NEXT 780REPEAT:PRINTTAB(0,21)"Choose an Algorithm (A for All): "; 790I=INSTR(LEFT$("123456789",methods)+"Aa",GET$):UNTILI 800first=I:last=I:IFI>methods:first=1:last=methods 810ENDPROC 820: 830DEFPROCperm 840FORI%=1TON%:J%=RND(N%) 850T%=a%(J%):a%(J%)=a%(I%):a%(I%)=T% 860NEXT 870ENDPROC 880: 890DEFPROCnear 900L%=3:IFN%<8:L%=N%DIV4+1 910FORI%=L%TON%-L%:J%=RND(L%*2)+I%-L% 920T%=a%(J%):a%(J%)=a%(I%):a%(I%)=T% 930NEXT 940ENDPROC 950: 960DEFPROCrev 970FORI%=1TON% 980a%(I%)=N%+1-I% 990NEXT 1000ENDPROC 1010: 1020DEFPROCrandom 1030FORI%=1TON% 1040a%(I%)=RND(N%) 1050NEXT 1060ENDPROC 1070: 1080DEFPROCequal_keys 1090K%=LN(N%+1):T%=N%DIVK% 1100FORI%=1TOT%:q%(I%)=RND(T%):NEXT 1110FORI%=1TON% 1120a%(I%)=q%(RND(T%))*K% 1130NEXT 1140ENDPROC 1150: 1160DEFPROCbubble 1170FORI%=N%TO2STEP-1 1180FORJ%=1TOI%-1:T%=q%(J%+1) 1190IFa%(q%(J%))>a%(T%):q%(J%+1)=q%(J%):q%(J%)=T% 1200NEXT, 1210ENDPROC 1220: 1230DEFPROCbubble_flag 1240I%=N%:REPEAT:F%=TRUE 1250FORJ%=1TOI%-1:T%=q%(J%+1) 1260IFa%(q%(J%))>a%(T%):q%(J%+1)=q%(J%):q%(J%)=T%:F%=FALSE 1270NEXT:I%=I%-1 1280UNTILF% 1290ENDPROC 1300: 1310DEFPROCbubble_monitor 1320I%=N%-1:REPEAT:F%=1 1330FORJ%=1TOI%:T%=q%(J%+1) 1340IFa%(q%(J%))>a%(T%):q%(J%+1)=q%(J%):q%(J%)=T%:F%=J% 1350NEXT:I%=F%-1 1360UNTILF%=1 1370ENDPROC 1380: 1390DEFPROCshaker 1400L%=2:R%=N%:K%=N% 1410REPEAT 1420FORJ%=R%TOL%STEP-1:T%=q%(J%-1) 1430IFa%(T%)>a%(q%(J%)):q%(J%-1)=q%(J%):q%(J%)=T%:K%=J% 1440NEXT:L%=K%+1 1450FORJ%=L%TOR%:T%=q%(J%-1) 1460IFa%(T%)>a%(q%(J%)):q%(J%-1)=q%(J%):q%(J%)=T%:K%=J% 1470NEXT:R%=K%-1 1480UNTILL%>R% 1490ENDPROC 1500: 1510DEFPROCstr_insertion:PROCinsert(1,N%):ENDPROC 1520: 1530DEFPROCinsert(L%,R%) 1540FORI%=L%+1TOR%:W%=q%(I%):J%=I%:F%=FALSE 1550REPEAT 1560T%=q%(J%-1):IFa%(T%)>a%(W%):q%(J%)=T%:J%=J%-1:ELSEF%=TRUE 1570UNTILF% 1580q%(J%)=W% 1590NEXT 1600ENDPROC 1610: 1620DEFPROCbin_insertion 1630FORI%=2TON%:W%=q%(I%):L%=1:R%=I%-1 1640REPEAT 1650M%=(L%+R%)DIV2:IFa%(q%(M%))>a%(W%):R%=M%-1:ELSE:L%=M%+1 1660UNTILL%>R% 1670IFL%<I%:FORJ%=I%-1TOL%STEP-1:q%(J%+1)=q%(J%):NEXT:q%(L%)=W% 1680NEXT 1690ENDPROC 1700: 1710DEFPROCselection 1720FORI%=1TON%-1:M%=I% 1730FORJ%=(I%+1)TON%:IFa%(q%(J%))<a%(q%(M%)):M%=J% 1740NEXT:T%=q%(M%):q%(M%)=q%(I%):q%(I%)=T% 1750NEXT 1760ENDPROC 1770: 1780DEFPROCshell(G%) 1790H%=1:REPEAT:H%=G%*H%+1:UNTILH%>N% 1800REPEAT:H%=H%DIVG% 1810FORI%=(H%+1)TON%:W%=q%(I%):J%=I%:F%=FALSE 1820REPEAT 1830IFa%(q%(J%-H%))>a%(W%):q%(J%)=q%(J%-H%):J%=J%-H%:F%=(J%<=H%):ELSEF%=TRUE 1840UNTILF% 1850q%(J%)=W% 1860NEXT 1870UNTILH%=1 1880ENDPROC 1890: 1900DEFPROCquick:G%=LN(N%)+3:PROCsort(1,N%):ENDPROC 1910: 1920REM:Quicksort : recursive 1930DEFPROCsort(L%,R%) 1940LOCALI%,J% 1950IFR%-L%<G%:PROCinsert(L%,R%):ENDPROC 1960PROCmedian 1970W%=a%(q%(M%)):I%=L%:J%=R% 1980REPEAT 1990REPEAT:I%=I%+1:UNTILa%(q%(I%))>=W% 2000REPEAT:J%=J%-1:UNTILa%(q%(J%))<=W% 2010IFI%<J%:T%=q%(J%):q%(J%)=q%(I%):q%(I%)=T% 2020UNTILJ%<I% 2030IF(R%-I%)>(J%-L%):PROCsort(L%,J%):PROCsort(I%,R%):ELSE:PROCsort(I%,R%):PROCsort(L%,J%) 2040ENDPROC 2050: 2060DEFPROCmedian 2070T%=q%(R%):IFa%(q%(L%))>a%(T%):q%(R%)=q%(L%):q%(L%)=T% 2080M%=(L%+R%)DIV2 2090T%=q%(R%):IFa%(q%(M%))>a%(T%):q%(R%)=q%(M%):q%(M%)=T% 2100T%=q%(M%):IFa%(q%(L%))>a%(T%):q%(M%)=q%(L%):q%(L%)=T% 2110ENDPROC 2120: 2130DEFPROCquick_nr 2140G%=LN(N%)+3:L%=1:R%=N%:S%=2 2150REPEAT 2160IFR%>L%:PROCnr_sort:ELSE:S%=S%-2:L%=s%(S%):R%=s%(S%+1) 2170UNTILS%<2 2180ENDPROC 2190: 2200REM:Quicksort : non-recursive 2210DEFPROCnr_sort 2220IFR%-L%<G%:PROCinsert(L%,R%):R%=L%:ENDPROC 2230PROCmedian 2240W%=a%(q%(M%)):I%=L%:J%=R% 2250REPEAT 2260REPEAT:I%=I%+1:UNTILa%(q%(I%))>=W% 2270REPEAT:J%=J%-1:UNTILa%(q%(J%))<=W% 2280IFI%<J%:T%=q%(J%):q%(J%)=q%(I%):q%(I%)=T% 2290UNTILJ%<I% 2300IF(R%-I%)>(J%-L%):s%(S%)=I%:s%(S%+1)=R%:R%=J%:ELSE:s%(S%)=L%:s%(S%+1)=J%:L%=I% 2310S%=S%+2 2320ENDPROC 2330: 2340DEFPROCquickinsert 2350G%=LN(N%)+3:L%=1:R%=N%:S%=2 2360REPEAT 2370IFR%>L%+G%:PROCsed_srt:ELSE:S%=S%-2:L%=s%(S%):R%=s%(S%+1) 2380UNTILS%<2 2390PROCstr_insertion 2400ENDPROC 2410: 2420REM:Quicksort a la Sedgewick : non-recursive 2430DEFPROCsed_srt 2440PROCmedian 2450I%=L%:J%=R%-1:T%=q%(M%):q%(M%)=q%(J%):q%(J%)=T% 2460W%=a%(q%(J%)) 2470REPEAT 2480REPEAT:I%=I%+1:UNTILa%(q%(I%))>=W% 2490REPEAT:J%=J%-1:UNTILa%(q%(J%))<=W% 2500IFI%<J%:T%=q%(J%):q%(J%)=q%(I%):q%(I%)=T% 2510UNTILJ%<I%:T%=q%(I%):q%(I%)=q%(R%-1):q%(R%-1)=T% 2520IF(R%-I%)>(J%-L%):s%(S%)=I%+1:s%(S%+1)=R%:R%=I%-1:ELSE:s%(S%)=L%:s%(S%+1)=I%-1:L%=I%+1 2530S%=S%+2 2540ENDPROC 2550: 2560DEFPROCheap 2570M%=N% 2580FORL%=N%DIV2TO1STEP-1:PROCdheap(L%):NEXT 2590REPEAT 2600T%=q%(M%):q%(M%)=q%(1):q%(1)=T%:M%=M%-1:IFM%>1:PROCdheap(1) 2610UNTILM%=0 2620ENDPROC 2630: 2640DEFPROCdheap(K%) 2650W%=q%(K%):F%=FALSE:G%=M%DIV2 2660REPEAT 2670J%=K%+K%:IFJ%<M%:IFa%(q%(J%))<a%(q%(J%+1)):J%=J%+1 2680IFa%(W%)>=a%(q%(J%)):F%=TRUE:ELSE:q%(K%)=q%(J%):K%=J% 2690UNTILF%ORK%>G%:q%(K%)=W% 2700ENDPROC 2710: 2720DEFPROCradix 2730M%=2:REPEAT:M%=M%*2:UNTILM%>N% 2740PROCrad(1,N%,M%) 2750ENDPROC 2760: 2770DEFPROCrad(L%,R%,B%) 2780IFR%<=L%:ENDPROC 2790LOCALI%,J%:I%=L%:J%=R% 2800REPEAT 2810F%=FALSE:REPEAT:IF(((a%(q%(I%)))DIVB%)AND1)=0:IFI%<J%:I%=I%+1:ELSE:F%=TRUE 2820UNTILF% 2830F%=FALSE:REPEAT:IF(((a%(q%(J%)))DIVB%)AND1):IFI%<J%:J%=J%-1:ELSE:F%=TRUE 2840UNTILF%:T%=q%(J%):q%(J%)=q%(I%):q%(I%)=T% 2850UNTILJ%=I%:IF((a%(q%(R%))DIVB%)AND1)=0:J%=J%+1 2860IFB%>1:B%=B%DIV2:PROCrad(L%,J%-1,B%):PROCrad(J%,R%,B%) 2870ENDPROC 2880: 2890DEFPROCstr_rad(G%) 2900M%=2^G%-1:G%=1 2910REPEAT:FORJ%=0TOM%:c%(J%)=0:NEXT 2920FORI%=1TON%:J%=((a%(q%(I%)))DIVG%)ANDM%:c%(J%)=c%(J%)+1:NEXT 2930FORJ%=1TOM%:c%(J%)=c%(J%-1)+c%(J%):NEXT 2940FORI%=N%TO1STEP-1:J%=((a%(q%(I%)))DIVG%)ANDM% 2950T%=c%(J%):s%(T%)=q%(I%):c%(J%)=T%-1:NEXT 2960FORI%=1TON%:q%(I%)=s%(I%):NEXT:G%=(M%+1)*G%:UNTILG%>N%:ENDPROC 2970: 2980DEFPROCmerge(L%,R%):LOCALM% 2990M%=(L%+R%)DIV2 3000IFM%>L%:PROCmerge(L%,M%) 3010IFM%+1<R%:PROCmerge(M%+1,R%) 3020FORI%=L%TOM%:s%(I%)=q%(I%):NEXT:I%=L% 3030T%=R%+M%+1:FORJ%=M%+1TOR%:s%(T%-J%)=q%(J%):NEXT:J%=R% 3040FORK%=L%TOR% 3050IFa%(s%(I%))<a%(s%(J%)):q%(K%)=s%(I%):I%=I%+1:ELSE:q%(K%)=s%(J%):J%=J%-1 3060NEXT 3070ENDPROC 3080: 3090DEFPROCcont 3100PRINT'"Press Spacebar to continue."; 3110REPEAT:I=INKEY(delay):UNTILI=32ORI 3120ENDPROC 3130: 3140DEFPROCresults 3150delay=2E5:print=FALSE:VDU26,12 3160REPEAT 3170IFprint:PRINT':VDU2,21,16:*FX21,0 3180PRINT" METHOD"SPC22;"TIME" 3190FORmthd=first TOlast:T$=FNtime:PRINT'M$(mthd)S$TAB(36-LENT$)T$:NEXT 3200PRINT'N$"was" 3210IFO%<5:PRINTP$n$" in"'O$(O%)" order.":ELSEPRINTR$"between 1 and "n$'"- "O$(O%)"." 3220PRINT:IFprint:VDU6,3:print=FALSE:ELSE:PRINT"Do you want a Printout (Y/N)? ";:print=1-FNin("NY") 3230IFprint:INPUT'"Left margin (0-43) : "I:VDU2,1,27,1,64,1,27,1,108,1,I,3 3240UNTILNOTprint 3250PROCcont 3260ENDPROC 3270: 3280DEFFNin(d$):REPEAT:I=INSTR(d$,CHR$(GETAND&DF)):UNTILI:=I 3290: 3300DEFFNtime:=STR$(10*time%(mthd))+" ms" 3310: 3320DEFPROClist 3330CLS:F%=FALSE 3340FORI%=1TON% 3350PRINTI%,q%(I%),a%(I%),a%(q%(I%)) 3360IFa%(q%(I%))<a%(q%(I%-1)):F%=TRUE 3370NEXT 3380IFF%:VDU7:PRINT"Discrepancy !" 3390ENDPROC 3400: 3410DEFPROCquit:@%=10:VDU3:*FX12,0 3420PRINT'"Press f0 to run again."; 3430ENDPROC 3440ENDIF"SorTest"
%�:SorTest by L.L.J.Vick (22/2/89) �:�:�" at line ";�:�quit:� �7:C=(�-�P-2000)�12 (1�a%(C),q%(C),s%(C),c%(7),time%(9),M$(9),O$(6) 2S$=" Sort":�I=1�6:�O$(I):� <*KEY0RUN|M F�:�7:�init P�mthd=first �last Z"�I%=0�N%:q%(I%)=I%:�:delay=2E3 d�26,12:�'M$(mthd)S$ n�28,0,24,39,2 x�'"Sorting in progress." ��=0 ��spd=1:�slow:�:�fast �time%(mthd)=� ��last=first:�list ��'"Time taken = "�time ��cont:� ��last>first:�results ��� �: � ��slow ��mthd=1:�bubble ��mthd=2:�bubble_flag ��mthd=3:�bubble_monitor �mthd=4:�shaker �mthd=5:�str_insertion �mthd=6:�bin_insertion "�mthd=7:�selection ,� 6: @ ��fast J�mthd=1:�shell(2) T�mthd=2:�shell(3) ^�mthd=3:�quick h�mthd=4:�quick_nr r�mthd=5:�quickinsert |�mthd=6:�heap ��mthd=7:�radix ��mthd=8:�str_rad(3) ��mthd=9:�merge(1,N%) �� �: �I�Perfect,Near-Perfect,Reverse,Random,Well distributed,With many equal �k�7,Bubble,Bubble (with Flag),Bubble (with Monitor),Shaker,Straight Insertion,Binary Insertion,Selection �y�9,Shell(2),Shell(3),Quick (recursive),Quick (non-recursive),Quick/Insertion,Heap,Radix Exchange,Straight Radix,Merge �: � ��init �3�I=0�1:�3,I)�141"SORTING ALGORITHMS ON TEST":� �@%=&606:�28,1,24,39,2 �4�:�:�1,9)"Choose a number, less than "�(C+1)"." 5�0,20)"Press H (RETURN) for Help & Information"; ,�13,11)"N = "n$:�n$<5:N%=�n$:�:N%=0:�7 %�n$="H"�n$="h":S%=2:�7:�"T/Sorts" &�N%>1�N%<=C 01N$="The original Number Sequence ":n$=�(N%):� :2P$="a Permutation of 1 to ":R$="a Random set " D:�'N$"consists"''"of a set of integers which can be:-"' N�"EITHER "P$n$' X%�I=1�4:�I"...In "O$(I)" order"':� b�"OR "R$"in this range"' l�I=5�6:�I"..."O$(I)':� v!�:�5,21)"Choose (1 to 6) :"; �O%=�-48:�O%>0�O%<7 ��24,21)�(O%)" wait!"; ��I%=0�N%:a%(I%)=I%:� � I%=�(-N%) ��O%=2:�near ��O%=3:�rev ��O%=4:�perm ��O%=5:�random ��O%=6:�equal_keys �J�:�0,9)"Do you want the 'slow' or the 'fast'"''�8)"methods? (S/F) :"; �spd=�in("SF") ��:�spd=1:��dBA:���dLA ��methods )�I=1�methods:�M$(I):�'I"..."M$(I)S$:� 1�:�0,21)"Choose an Algorithm (A for All): "; 'I=��"123456789",methods)+"Aa",�):�I 2first=I:last=I:�I>methods:first=1:last=methods *� 4: > ��perm H�I%=1�N%:J%=�(N%) R%T%=a%(J%):a%(J%)=a%(I%):a%(I%)=T% \� f� p: z ��near �L%=3:�N%<8:L%=N%�4+1 �!�I%=L%�N%-L%:J%=�(L%*2)+I%-L% �%T%=a%(J%):a%(J%)=a%(I%):a%(I%)=T% �� �� �: � ��rev ��I%=1�N% �a%(I%)=N%+1-I% �� �� �: ���random �I%=1�N% a%(I%)=�(N%) � $� .: 8��equal_keys BK%=�(N%+1):T%=N%�K% L�I%=1�T%:q%(I%)=�(T%):� V�I%=1�N% `a%(I%)=q%(�(T%))*K% j� t� ~: ���bubble ��I%=N%�2�-1 ��J%=1�I%-1:T%=q%(J%+1) �0�a%(q%(J%))>a%(T%):q%(J%+1)=q%(J%):q%(J%)=T% ��, �� �: ���bubble_flag �I%=N%:�:F%=� ��J%=1�I%-1:T%=q%(J%+1) �5�a%(q%(J%))>a%(T%):q%(J%+1)=q%(J%):q%(J%)=T%:F%=� � �:I%=I%-1 �F% � : ��bubble_monitor (I%=N%-1:�:F%=1 2�J%=1�I%:T%=q%(J%+1) <6�a%(q%(J%))>a%(T%):q%(J%+1)=q%(J%):q%(J%)=T%:F%=J% F �:I%=F%-1 P �F%=1 Z� d: n��shaker xL%=2:R%=N%:K%=N% �� ��J%=R%�L%�-1:T%=q%(J%-1) �6�a%(T%)>a%(q%(J%)):q%(J%-1)=q%(J%):q%(J%)=T%:K%=J% � �:L%=K%+1 ��J%=L%�R%:T%=q%(J%-1) �6�a%(T%)>a%(q%(J%)):q%(J%-1)=q%(J%):q%(J%)=T%:K%=J% � �:R%=K%-1 � �L%>R% �� �: �#��str_insertion:�insert(1,N%):� �: ���insert(L%,R%) $�I%=L%+1�R%:W%=q%(I%):J%=I%:F%=� � 6T%=q%(J%-1):�a%(T%)>a%(W%):q%(J%)=T%:J%=J%-1:�F%=� "�F% , q%(J%)=W% 6� @� J: T��bin_insertion ^#�I%=2�N%:W%=q%(I%):L%=1:R%=I%-1 h� r5M%=(L%+R%)�2:�a%(q%(M%))>a%(W%):R%=M%-1:�:L%=M%+1 | �L%>R% �5�L%<I%:�J%=I%-1�L%�-1:q%(J%+1)=q%(J%):�:q%(L%)=W% �� �� �: ���selection ��I%=1�N%-1:M%=I% �.�J%=(I%+1)�N%:�a%(q%(J%))<a%(q%(M%)):M%=J% �'�:T%=q%(M%):q%(M%)=q%(I%):q%(I%)=T% �� �� �: ���shell(G%) �H%=1:�:H%=G%*H%+1:�H%>N% �:H%=H%�G% &�I%=(H%+1)�N%:W%=q%(I%):J%=I%:F%=� � &E�a%(q%(J%-H%))>a%(W%):q%(J%)=q%(J%-H%):J%=J%-H%:F%=(J%<=H%):�F%=� 0�F% : q%(J%)=W% D� N �H%=1 X� b: l$��quick:G%=�(N%)+3:�sort(1,N%):� v: ��:Quicksort : recursive ���sort(L%,R%) � �I%,J% ��R%-L%<G%:�insert(L%,R%):� ��median �W%=a%(q%(M%)):I%=L%:J%=R% �� ��:I%=I%+1:�a%(q%(I%))>=W% ��:J%=J%-1:�a%(q%(J%))<=W% �,�I%<J%:T%=q%(J%):q%(J%)=q%(I%):q%(I%)=T% � �J%<I% �J�(R%-I%)>(J%-L%):�sort(L%,J%):�sort(I%,R%):�:�sort(I%,R%):�sort(L%,J%) �� : ��median 8T%=q%(R%):�a%(q%(L%))>a%(T%):q%(R%)=q%(L%):q%(L%)=T% M%=(L%+R%)�2 *8T%=q%(R%):�a%(q%(M%))>a%(T%):q%(R%)=q%(M%):q%(M%)=T% 48T%=q%(M%):�a%(q%(L%))>a%(T%):q%(M%)=q%(L%):q%(L%)=T% >� H: R��quick_nr \G%=�(N%)+3:L%=1:R%=N%:S%=2 f� p3�R%>L%:�nr_sort:�:S%=S%-2:L%=s%(S%):R%=s%(S%+1) z �S%<2 �� �: ��:Quicksort : non-recursive � ��nr_sort �$�R%-L%<G%:�insert(L%,R%):R%=L%:� ��median �W%=a%(q%(M%)):I%=L%:J%=R% �� ��:I%=I%+1:�a%(q%(I%))>=W% ��:J%=J%-1:�a%(q%(J%))<=W% �,�I%<J%:T%=q%(J%):q%(J%)=q%(I%):q%(I%)=T% � �J%<I% �N�(R%-I%)>(J%-L%):s%(S%)=I%:s%(S%+1)=R%:R%=J%:�:s%(S%)=L%:s%(S%+1)=J%:L%=I% S%=S%+2 � : $��quickinsert .G%=�(N%)+3:L%=1:R%=N%:S%=2 8� B6�R%>L%+G%:�sed_srt:�:S%=S%-2:L%=s%(S%):R%=s%(S%+1) L �S%<2 V�str_insertion `� j: t.�:Quicksort a la Sedgewick : non-recursive ~ ��sed_srt ��median �3I%=L%:J%=R%-1:T%=q%(M%):q%(M%)=q%(J%):q%(J%)=T% �W%=a%(q%(J%)) �� ��:I%=I%+1:�a%(q%(I%))>=W% ��:J%=J%-1:�a%(q%(J%))<=W% �,�I%<J%:T%=q%(J%):q%(J%)=q%(I%):q%(I%)=T% �0�J%<I%:T%=q%(I%):q%(I%)=q%(R%-1):q%(R%-1)=T% �V�(R%-I%)>(J%-L%):s%(S%)=I%+1:s%(S%+1)=R%:R%=I%-1:�:s%(S%)=L%:s%(S%+1)=I%-1:L%=I%+1 �S%=S%+2 �� �: ��heap M%=N% �L%=N%�2�1�-1:�dheap(L%):� � (;T%=q%(M%):q%(M%)=q%(1):q%(1)=T%:M%=M%-1:�M%>1:�dheap(1) 2 �M%=0 <� F: P��dheap(K%) ZW%=q%(K%):F%=�:G%=M%�2 d� n4J%=K%+K%:�J%<M%:�a%(q%(J%))<a%(q%(J%+1)):J%=J%+1 x2�a%(W%)>=a%(q%(J%)):F%=�:�:q%(K%)=q%(J%):K%=J% ��F%�K%>G%:q%(K%)=W% �� �: ���radix �M%=2:�:M%=M%*2:�M%>N% ��rad(1,N%,M%) �� �: ���rad(L%,R%,B%) � �R%<=L%:� ��I%,J%:I%=L%:J%=R% �� �9F%=�:�:�(((a%(q%(I%)))�B%)�1)=0:�I%<J%:I%=I%+1:�:F%=� �F% 7F%=�:�:�(((a%(q%(J%)))�B%)�1):�I%<J%:J%=J%-1:�:F%=� )�F%:T%=q%(J%):q%(J%)=q%(I%):q%(I%)=T% ")�J%=I%:�((a%(q%(R%))�B%)�1)=0:J%=J%+1 ,1�B%>1:B%=B%�2:�rad(L%,J%-1,B%):�rad(J%,R%,B%) 6� @: J��str_rad(G%) TM%=2^G%-1:G%=1 ^�:�J%=0�M%:c%(J%)=0:� h6�I%=1�N%:J%=((a%(q%(I%)))�G%)�M%:c%(J%)=c%(J%)+1:� r%�J%=1�M%:c%(J%)=c%(J%-1)+c%(J%):� |'�I%=N%�1�-1:J%=((a%(q%(I%)))�G%)�M% �)T%=c%(J%):s%(T%)=q%(I%):c%(J%)=T%-1:� �2�I%=1�N%:q%(I%)=s%(I%):�:G%=(M%+1)*G%:�G%>N%:� �: ���merge(L%,R%):�M% �M%=(L%+R%)�2 ��M%>L%:�merge(L%,M%) ��M%+1<R%:�merge(M%+1,R%) �#�I%=L%�M%:s%(I%)=q%(I%):�:I%=L% �3T%=R%+M%+1:�J%=M%+1�R%:s%(T%-J%)=q%(J%):�:J%=R% � �K%=L%�R% �H�a%(s%(I%))<a%(s%(J%)):q%(K%)=s%(I%):I%=I%+1:�:q%(K%)=s%(J%):J%=J%-1 �� �� : ��cont $�'"Press Spacebar to continue."; &�:I=�(delay):�I=32�I 0� :: D ��results Ndelay=2E5:print=�:�26,12 X� b�print:�':�2,21,16:*FX21,0 l�" METHOD"�22;"TIME" v7�mthd=first �last:T$=�time:�'M$(mthd)S$�36-�T$)T$:� � �'N$"was" �I�O%<5:�P$n$" in"'O$(O%)" order.":��R$"between 1 and "n$'"- "O$(O%)"." �P�:�print:�6,3:print=�:�:�"Do you want a Printout (Y/N)? ";:print=1-�in("NY") �C�print:�'"Left margin (0-43) : "I:�2,1,27,1,64,1,27,1,108,1,I,3 ���print � �cont �� �: �$ݤin(d$):�:I=�d$,�(��&DF)):�I:=I �: �#ݤtime:=�(10*time%(mthd))+" ms" �: � ��list �:F%=� �I%=1�N% �I%,q%(I%),a%(I%),a%(q%(I%)) !�a%(q%(I%))<a%(q%(I%-1)):F%=� *� 4�F%:�7:�"Discrepancy !" >� H: R��quit:@%=10:�3:*FX12,0 \�'"Press f0 to run again."; f� p�"SorTest" �
00000000 0d 00 0a 25 f4 3a 53 6f 72 54 65 73 74 20 62 79 |...%.:SorTest by| 00000010 20 4c 2e 4c 2e 4a 2e 56 69 63 6b 20 28 32 32 2f | L.L.J.Vick (22/| 00000020 32 2f 38 39 29 0d 00 14 1f ee 85 3a f6 3a f1 22 |2/89)......:.:."| 00000030 20 61 74 20 6c 69 6e 65 20 22 3b 9e 3a f2 71 75 | at line ";.:.qu| 00000040 69 74 3a e0 0d 00 1e 17 eb 37 3a 43 3d 28 93 2d |it:......7:C=(.-| 00000050 b8 50 2d 32 30 30 30 29 81 31 32 0d 00 28 31 de |.P-2000).12..(1.| 00000060 61 25 28 43 29 2c 71 25 28 43 29 2c 73 25 28 43 |a%(C),q%(C),s%(C| 00000070 29 2c 63 25 28 37 29 2c 74 69 6d 65 25 28 39 29 |),c%(7),time%(9)| 00000080 2c 4d 24 28 39 29 2c 4f 24 28 36 29 0d 00 32 1e |,M$(9),O$(6)..2.| 00000090 53 24 3d 22 20 53 6f 72 74 22 3a e3 49 3d 31 b8 |S$=" Sort":.I=1.| 000000a0 36 3a f3 4f 24 28 49 29 3a ed 0d 00 3c 0e 2a 4b |6:.O$(I):...<.*K| 000000b0 45 59 30 52 55 4e 7c 4d 0d 00 46 0e f5 3a eb 37 |EY0RUN|M..F..:.7| 000000c0 3a f2 69 6e 69 74 0d 00 50 15 e3 6d 74 68 64 3d |:.init..P..mthd=| 000000d0 66 69 72 73 74 20 b8 6c 61 73 74 0d 00 5a 22 e3 |first .last..Z".| 000000e0 49 25 3d 30 b8 4e 25 3a 71 25 28 49 25 29 3d 49 |I%=0.N%:q%(I%)=I| 000000f0 25 3a ed 3a 64 65 6c 61 79 3d 32 45 33 0d 00 64 |%:.:delay=2E3..d| 00000100 17 ef 32 36 2c 31 32 3a f1 27 4d 24 28 6d 74 68 |..26,12:.'M$(mth| 00000110 64 29 53 24 0d 00 6e 11 ef 32 38 2c 30 2c 32 34 |d)S$..n..28,0,24| 00000120 2c 33 39 2c 32 0d 00 78 1c f1 27 22 53 6f 72 74 |,39,2..x..'"Sort| 00000130 69 6e 67 20 69 6e 20 70 72 6f 67 72 65 73 73 2e |ing in progress.| 00000140 22 0d 00 82 07 d1 3d 30 0d 00 8c 18 e7 73 70 64 |".....=0.....spd| 00000150 3d 31 3a f2 73 6c 6f 77 3a 8b 3a f2 66 61 73 74 |=1:.slow:.:.fast| 00000160 0d 00 96 11 74 69 6d 65 25 28 6d 74 68 64 29 3d |....time%(mthd)=| 00000170 91 0d 00 a0 15 e7 6c 61 73 74 3d 66 69 72 73 74 |......last=first| 00000180 3a f2 6c 69 73 74 0d 00 aa 1a f1 27 22 54 69 6d |:.list.....'"Tim| 00000190 65 20 74 61 6b 65 6e 20 3d 20 22 a4 74 69 6d 65 |e taken = ".time| 000001a0 0d 00 b4 0b f2 63 6f 6e 74 3a ed 0d 00 be 18 e7 |.....cont:......| 000001b0 6c 61 73 74 3e 66 69 72 73 74 3a f2 72 65 73 75 |last>first:.resu| 000001c0 6c 74 73 0d 00 c8 06 fd a3 0d 00 d2 05 3a 0d 00 |lts..........:..| 000001d0 dc 0a dd f2 73 6c 6f 77 0d 00 e6 13 e7 6d 74 68 |....slow.....mth| 000001e0 64 3d 31 3a f2 62 75 62 62 6c 65 0d 00 f0 18 e7 |d=1:.bubble.....| 000001f0 6d 74 68 64 3d 32 3a f2 62 75 62 62 6c 65 5f 66 |mthd=2:.bubble_f| 00000200 6c 61 67 0d 00 fa 1b e7 6d 74 68 64 3d 33 3a f2 |lag.....mthd=3:.| 00000210 62 75 62 62 6c 65 5f 6d 6f 6e 69 74 6f 72 0d 01 |bubble_monitor..| 00000220 04 13 e7 6d 74 68 64 3d 34 3a f2 73 68 61 6b 65 |...mthd=4:.shake| 00000230 72 0d 01 0e 1a e7 6d 74 68 64 3d 35 3a f2 73 74 |r.....mthd=5:.st| 00000240 72 5f 69 6e 73 65 72 74 69 6f 6e 0d 01 18 1a e7 |r_insertion.....| 00000250 6d 74 68 64 3d 36 3a f2 62 69 6e 5f 69 6e 73 65 |mthd=6:.bin_inse| 00000260 72 74 69 6f 6e 0d 01 22 16 e7 6d 74 68 64 3d 37 |rtion.."..mthd=7| 00000270 3a f2 73 65 6c 65 63 74 69 6f 6e 0d 01 2c 05 e1 |:.selection..,..| 00000280 0d 01 36 05 3a 0d 01 40 0a dd f2 66 61 73 74 0d |..6.:..@...fast.| 00000290 01 4a 15 e7 6d 74 68 64 3d 31 3a f2 73 68 65 6c |.J..mthd=1:.shel| 000002a0 6c 28 32 29 0d 01 54 15 e7 6d 74 68 64 3d 32 3a |l(2)..T..mthd=2:| 000002b0 f2 73 68 65 6c 6c 28 33 29 0d 01 5e 12 e7 6d 74 |.shell(3)..^..mt| 000002c0 68 64 3d 33 3a f2 71 75 69 63 6b 0d 01 68 15 e7 |hd=3:.quick..h..| 000002d0 6d 74 68 64 3d 34 3a f2 71 75 69 63 6b 5f 6e 72 |mthd=4:.quick_nr| 000002e0 0d 01 72 18 e7 6d 74 68 64 3d 35 3a f2 71 75 69 |..r..mthd=5:.qui| 000002f0 63 6b 69 6e 73 65 72 74 0d 01 7c 11 e7 6d 74 68 |ckinsert..|..mth| 00000300 64 3d 36 3a f2 68 65 61 70 0d 01 86 12 e7 6d 74 |d=6:.heap.....mt| 00000310 68 64 3d 37 3a f2 72 61 64 69 78 0d 01 90 17 e7 |hd=7:.radix.....| 00000320 6d 74 68 64 3d 38 3a f2 73 74 72 5f 72 61 64 28 |mthd=8:.str_rad(| 00000330 33 29 0d 01 9a 18 e7 6d 74 68 64 3d 39 3a f2 6d |3).....mthd=9:.m| 00000340 65 72 67 65 28 31 2c 4e 25 29 0d 01 a4 05 e1 0d |erge(1,N%)......| 00000350 01 ae 05 3a 0d 01 b8 49 dc 50 65 72 66 65 63 74 |...:...I.Perfect| 00000360 2c 4e 65 61 72 2d 50 65 72 66 65 63 74 2c 52 65 |,Near-Perfect,Re| 00000370 76 65 72 73 65 2c 52 61 6e 64 6f 6d 2c 57 65 6c |verse,Random,Wel| 00000380 6c 20 64 69 73 74 72 69 62 75 74 65 64 2c 57 69 |l distributed,Wi| 00000390 74 68 20 6d 61 6e 79 20 65 71 75 61 6c 0d 01 c2 |th many equal...| 000003a0 6b dc 37 2c 42 75 62 62 6c 65 2c 42 75 62 62 6c |k.7,Bubble,Bubbl| 000003b0 65 20 28 77 69 74 68 20 46 6c 61 67 29 2c 42 75 |e (with Flag),Bu| 000003c0 62 62 6c 65 20 28 77 69 74 68 20 4d 6f 6e 69 74 |bble (with Monit| 000003d0 6f 72 29 2c 53 68 61 6b 65 72 2c 53 74 72 61 69 |or),Shaker,Strai| 000003e0 67 68 74 20 49 6e 73 65 72 74 69 6f 6e 2c 42 69 |ght Insertion,Bi| 000003f0 6e 61 72 79 20 49 6e 73 65 72 74 69 6f 6e 2c 53 |nary Insertion,S| 00000400 65 6c 65 63 74 69 6f 6e 0d 01 cc 79 dc 39 2c 53 |election...y.9,S| 00000410 68 65 6c 6c 28 32 29 2c 53 68 65 6c 6c 28 33 29 |hell(2),Shell(3)| 00000420 2c 51 75 69 63 6b 20 28 72 65 63 75 72 73 69 76 |,Quick (recursiv| 00000430 65 29 2c 51 75 69 63 6b 20 28 6e 6f 6e 2d 72 65 |e),Quick (non-re| 00000440 63 75 72 73 69 76 65 29 2c 51 75 69 63 6b 2f 49 |cursive),Quick/I| 00000450 6e 73 65 72 74 69 6f 6e 2c 48 65 61 70 2c 52 61 |nsertion,Heap,Ra| 00000460 64 69 78 20 45 78 63 68 61 6e 67 65 2c 53 74 72 |dix Exchange,Str| 00000470 61 69 67 68 74 20 52 61 64 69 78 2c 4d 65 72 67 |aight Radix,Merg| 00000480 65 0d 01 d6 05 3a 0d 01 e0 0a dd f2 69 6e 69 74 |e....:......init| 00000490 0d 01 ea 33 e3 49 3d 30 b8 31 3a f1 8a 33 2c 49 |...3.I=0.1:..3,I| 000004a0 29 bd 31 34 31 22 53 4f 52 54 49 4e 47 20 41 4c |).141"SORTING AL| 000004b0 47 4f 52 49 54 48 4d 53 20 4f 4e 20 54 45 53 54 |GORITHMS ON TEST| 000004c0 22 3a ed 0d 01 f4 19 40 25 3d 26 36 30 36 3a ef |":.....@%=&606:.| 000004d0 32 38 2c 31 2c 32 34 2c 33 39 2c 32 0d 01 fe 34 |28,1,24,39,2...4| 000004e0 f5 3a db 3a f1 8a 31 2c 39 29 22 43 68 6f 6f 73 |.:.:..1,9)"Choos| 000004f0 65 20 61 20 6e 75 6d 62 65 72 2c 20 6c 65 73 73 |e a number, less| 00000500 20 74 68 61 6e 20 22 c3 28 43 2b 31 29 22 2e 22 | than ".(C+1)"."| 00000510 0d 02 08 35 f1 8a 30 2c 32 30 29 22 50 72 65 73 |...5..0,20)"Pres| 00000520 73 20 48 20 28 52 45 54 55 52 4e 29 20 66 6f 72 |s H (RETURN) for| 00000530 20 48 65 6c 70 20 26 20 49 6e 66 6f 72 6d 61 74 | Help & Informat| 00000540 69 6f 6e 22 3b 0d 02 12 2c e8 8a 31 33 2c 31 31 |ion";...,..13,11| 00000550 29 22 4e 20 3d 20 22 6e 24 3a e7 a9 6e 24 3c 35 |)"N = "n$:..n$<5| 00000560 3a 4e 25 3d bb 6e 24 3a 8b 3a 4e 25 3d 30 3a ef |:N%=.n$:.:N%=0:.| 00000570 37 0d 02 1c 25 e7 6e 24 3d 22 48 22 84 6e 24 3d |7...%.n$="H".n$=| 00000580 22 68 22 3a 53 25 3d 32 3a ef 37 3a d7 22 54 2f |"h":S%=2:.7:."T/| 00000590 53 6f 72 74 73 22 0d 02 26 0f fd 4e 25 3e 31 80 |Sorts"..&..N%>1.| 000005a0 4e 25 3c 3d 43 0d 02 30 31 4e 24 3d 22 54 68 65 |N%<=C..01N$="The| 000005b0 20 6f 72 69 67 69 6e 61 6c 20 4e 75 6d 62 65 72 | original Number| 000005c0 20 53 65 71 75 65 6e 63 65 20 22 3a 6e 24 3d c3 | Sequence ":n$=.| 000005d0 28 4e 25 29 3a db 0d 02 3a 32 50 24 3d 22 61 20 |(N%):...:2P$="a | 000005e0 50 65 72 6d 75 74 61 74 69 6f 6e 20 6f 66 20 31 |Permutation of 1| 000005f0 20 74 6f 20 22 3a 52 24 3d 22 61 20 52 61 6e 64 | to ":R$="a Rand| 00000600 6f 6d 20 73 65 74 20 22 0d 02 44 3a f1 27 4e 24 |om set "..D:.'N$| 00000610 22 63 6f 6e 73 69 73 74 73 22 27 27 22 6f 66 20 |"consists"''"of | 00000620 61 20 73 65 74 20 6f 66 20 69 6e 74 65 67 65 72 |a set of integer| 00000630 73 20 77 68 69 63 68 20 63 61 6e 20 62 65 3a 2d |s which can be:-| 00000640 22 27 0d 02 4e 13 f1 22 45 49 54 48 45 52 20 22 |"'..N.."EITHER "| 00000650 50 24 6e 24 27 0d 02 58 25 e3 49 3d 31 b8 34 3a |P$n$'..X%.I=1.4:| 00000660 f1 49 22 2e 2e 2e 49 6e 20 22 4f 24 28 49 29 22 |.I"...In "O$(I)"| 00000670 20 6f 72 64 65 72 22 27 3a ed 0d 02 62 1c f1 22 | order"':...b.."| 00000680 4f 52 20 22 52 24 22 69 6e 20 74 68 69 73 20 72 |OR "R$"in this r| 00000690 61 6e 67 65 22 27 0d 02 6c 1a e3 49 3d 35 b8 36 |ange"'..l..I=5.6| 000006a0 3a f1 49 22 2e 2e 2e 22 4f 24 28 49 29 27 3a ed |:.I"..."O$(I)':.| 000006b0 0d 02 76 21 f5 3a f1 8a 35 2c 32 31 29 22 43 68 |..v!.:..5,21)"Ch| 000006c0 6f 6f 73 65 20 28 31 20 74 6f 20 36 29 20 3a 22 |oose (1 to 6) :"| 000006d0 3b 0d 02 80 16 4f 25 3d a5 2d 34 38 3a fd 4f 25 |;....O%=.-48:.O%| 000006e0 3e 30 80 4f 25 3c 37 0d 02 8a 1a f1 8a 32 34 2c |>0.O%<7......24,| 000006f0 32 31 29 c3 28 4f 25 29 22 20 77 61 69 74 21 22 |21).(O%)" wait!"| 00000700 3b 0d 02 94 18 e3 49 25 3d 30 b8 4e 25 3a 61 25 |;.....I%=0.N%:a%| 00000710 28 49 25 29 3d 49 25 3a ed 0d 02 9e 0d 49 25 3d |(I%)=I%:.....I%=| 00000720 b3 28 2d 4e 25 29 0d 02 a8 0f e7 4f 25 3d 32 3a |.(-N%).....O%=2:| 00000730 f2 6e 65 61 72 0d 02 b2 0e e7 4f 25 3d 33 3a f2 |.near.....O%=3:.| 00000740 72 65 76 0d 02 bc 0f e7 4f 25 3d 34 3a f2 70 65 |rev.....O%=4:.pe| 00000750 72 6d 0d 02 c6 11 e7 4f 25 3d 35 3a f2 72 61 6e |rm.....O%=5:.ran| 00000760 64 6f 6d 0d 02 d0 15 e7 4f 25 3d 36 3a f2 65 71 |dom.....O%=6:.eq| 00000770 75 61 6c 5f 6b 65 79 73 0d 02 da 4a db 3a f1 8a |ual_keys...J.:..| 00000780 30 2c 39 29 22 44 6f 20 79 6f 75 20 77 61 6e 74 |0,9)"Do you want| 00000790 20 74 68 65 20 27 73 6c 6f 77 27 20 6f 72 20 74 | the 'slow' or t| 000007a0 68 65 20 27 66 61 73 74 27 22 27 27 8a 38 29 22 |he 'fast'"''.8)"| 000007b0 6d 65 74 68 6f 64 73 3f 20 28 53 2f 46 29 20 3a |methods? (S/F) :| 000007c0 22 3b 0d 02 e4 11 73 70 64 3d a4 69 6e 28 22 53 |";....spd=.in("S| 000007d0 46 22 29 0d 02 ee 19 db 3a e7 73 70 64 3d 31 3a |F").....:.spd=1:| 000007e0 f7 8d 64 42 41 3a 8b f7 8d 64 4c 41 0d 02 f8 0c |..dBA:...dLA....| 000007f0 f3 6d 65 74 68 6f 64 73 0d 03 02 29 e3 49 3d 31 |.methods...).I=1| 00000800 b8 6d 65 74 68 6f 64 73 3a f3 4d 24 28 49 29 3a |.methods:.M$(I):| 00000810 f1 27 49 22 2e 2e 2e 22 4d 24 28 49 29 53 24 3a |.'I"..."M$(I)S$:| 00000820 ed 0d 03 0c 31 f5 3a f1 8a 30 2c 32 31 29 22 43 |....1.:..0,21)"C| 00000830 68 6f 6f 73 65 20 61 6e 20 41 6c 67 6f 72 69 74 |hoose an Algorit| 00000840 68 6d 20 28 41 20 66 6f 72 20 41 6c 6c 29 3a 20 |hm (A for All): | 00000850 22 3b 0d 03 16 27 49 3d a7 c0 22 31 32 33 34 35 |";...'I=.."12345| 00000860 36 37 38 39 22 2c 6d 65 74 68 6f 64 73 29 2b 22 |6789",methods)+"| 00000870 41 61 22 2c be 29 3a fd 49 0d 03 20 32 66 69 72 |Aa",.):.I.. 2fir| 00000880 73 74 3d 49 3a 6c 61 73 74 3d 49 3a e7 49 3e 6d |st=I:last=I:.I>m| 00000890 65 74 68 6f 64 73 3a 66 69 72 73 74 3d 31 3a 6c |ethods:first=1:l| 000008a0 61 73 74 3d 6d 65 74 68 6f 64 73 0d 03 2a 05 e1 |ast=methods..*..| 000008b0 0d 03 34 05 3a 0d 03 3e 0a dd f2 70 65 72 6d 0d |..4.:..>...perm.| 000008c0 03 48 15 e3 49 25 3d 31 b8 4e 25 3a 4a 25 3d b3 |.H..I%=1.N%:J%=.| 000008d0 28 4e 25 29 0d 03 52 25 54 25 3d 61 25 28 4a 25 |(N%)..R%T%=a%(J%| 000008e0 29 3a 61 25 28 4a 25 29 3d 61 25 28 49 25 29 3a |):a%(J%)=a%(I%):| 000008f0 61 25 28 49 25 29 3d 54 25 0d 03 5c 05 ed 0d 03 |a%(I%)=T%..\....| 00000900 66 05 e1 0d 03 70 05 3a 0d 03 7a 0a dd f2 6e 65 |f....p.:..z...ne| 00000910 61 72 0d 03 84 18 4c 25 3d 33 3a e7 4e 25 3c 38 |ar....L%=3:.N%<8| 00000920 3a 4c 25 3d 4e 25 81 34 2b 31 0d 03 8e 21 e3 49 |:L%=N%.4+1...!.I| 00000930 25 3d 4c 25 b8 4e 25 2d 4c 25 3a 4a 25 3d b3 28 |%=L%.N%-L%:J%=.(| 00000940 4c 25 2a 32 29 2b 49 25 2d 4c 25 0d 03 98 25 54 |L%*2)+I%-L%...%T| 00000950 25 3d 61 25 28 4a 25 29 3a 61 25 28 4a 25 29 3d |%=a%(J%):a%(J%)=| 00000960 61 25 28 49 25 29 3a 61 25 28 49 25 29 3d 54 25 |a%(I%):a%(I%)=T%| 00000970 0d 03 a2 05 ed 0d 03 ac 05 e1 0d 03 b6 05 3a 0d |..............:.| 00000980 03 c0 09 dd f2 72 65 76 0d 03 ca 0c e3 49 25 3d |.....rev.....I%=| 00000990 31 b8 4e 25 0d 03 d4 12 61 25 28 49 25 29 3d 4e |1.N%....a%(I%)=N| 000009a0 25 2b 31 2d 49 25 0d 03 de 05 ed 0d 03 e8 05 e1 |%+1-I%..........| 000009b0 0d 03 f2 05 3a 0d 03 fc 0c dd f2 72 61 6e 64 6f |....:......rando| 000009c0 6d 0d 04 06 0c e3 49 25 3d 31 b8 4e 25 0d 04 10 |m.....I%=1.N%...| 000009d0 10 61 25 28 49 25 29 3d b3 28 4e 25 29 0d 04 1a |.a%(I%)=.(N%)...| 000009e0 05 ed 0d 04 24 05 e1 0d 04 2e 05 3a 0d 04 38 10 |....$......:..8.| 000009f0 dd f2 65 71 75 61 6c 5f 6b 65 79 73 0d 04 42 17 |..equal_keys..B.| 00000a00 4b 25 3d aa 28 4e 25 2b 31 29 3a 54 25 3d 4e 25 |K%=.(N%+1):T%=N%| 00000a10 81 4b 25 0d 04 4c 1b e3 49 25 3d 31 b8 54 25 3a |.K%..L..I%=1.T%:| 00000a20 71 25 28 49 25 29 3d b3 28 54 25 29 3a ed 0d 04 |q%(I%)=.(T%):...| 00000a30 56 0c e3 49 25 3d 31 b8 4e 25 0d 04 60 17 61 25 |V..I%=1.N%..`.a%| 00000a40 28 49 25 29 3d 71 25 28 b3 28 54 25 29 29 2a 4b |(I%)=q%(.(T%))*K| 00000a50 25 0d 04 6a 05 ed 0d 04 74 05 e1 0d 04 7e 05 3a |%..j....t....~.:| 00000a60 0d 04 88 0c dd f2 62 75 62 62 6c 65 0d 04 92 0f |......bubble....| 00000a70 e3 49 25 3d 4e 25 b8 32 88 2d 31 0d 04 9c 1a e3 |.I%=N%.2.-1.....| 00000a80 4a 25 3d 31 b8 49 25 2d 31 3a 54 25 3d 71 25 28 |J%=1.I%-1:T%=q%(| 00000a90 4a 25 2b 31 29 0d 04 a6 30 e7 61 25 28 71 25 28 |J%+1)...0.a%(q%(| 00000aa0 4a 25 29 29 3e 61 25 28 54 25 29 3a 71 25 28 4a |J%))>a%(T%):q%(J| 00000ab0 25 2b 31 29 3d 71 25 28 4a 25 29 3a 71 25 28 4a |%+1)=q%(J%):q%(J| 00000ac0 25 29 3d 54 25 0d 04 b0 06 ed 2c 0d 04 ba 05 e1 |%)=T%.....,.....| 00000ad0 0d 04 c4 05 3a 0d 04 ce 11 dd f2 62 75 62 62 6c |....:......bubbl| 00000ae0 65 5f 66 6c 61 67 0d 04 d8 10 49 25 3d 4e 25 3a |e_flag....I%=N%:| 00000af0 f5 3a 46 25 3d b9 0d 04 e2 1a e3 4a 25 3d 31 b8 |.:F%=......J%=1.| 00000b00 49 25 2d 31 3a 54 25 3d 71 25 28 4a 25 2b 31 29 |I%-1:T%=q%(J%+1)| 00000b10 0d 04 ec 35 e7 61 25 28 71 25 28 4a 25 29 29 3e |...5.a%(q%(J%))>| 00000b20 61 25 28 54 25 29 3a 71 25 28 4a 25 2b 31 29 3d |a%(T%):q%(J%+1)=| 00000b30 71 25 28 4a 25 29 3a 71 25 28 4a 25 29 3d 54 25 |q%(J%):q%(J%)=T%| 00000b40 3a 46 25 3d a3 0d 04 f6 0d ed 3a 49 25 3d 49 25 |:F%=......:I%=I%| 00000b50 2d 31 0d 05 00 07 fd 46 25 0d 05 0a 05 e1 0d 05 |-1.....F%.......| 00000b60 14 05 3a 0d 05 1e 14 dd f2 62 75 62 62 6c 65 5f |..:......bubble_| 00000b70 6d 6f 6e 69 74 6f 72 0d 05 28 12 49 25 3d 4e 25 |monitor..(.I%=N%| 00000b80 2d 31 3a f5 3a 46 25 3d 31 0d 05 32 18 e3 4a 25 |-1:.:F%=1..2..J%| 00000b90 3d 31 b8 49 25 3a 54 25 3d 71 25 28 4a 25 2b 31 |=1.I%:T%=q%(J%+1| 00000ba0 29 0d 05 3c 36 e7 61 25 28 71 25 28 4a 25 29 29 |)..<6.a%(q%(J%))| 00000bb0 3e 61 25 28 54 25 29 3a 71 25 28 4a 25 2b 31 29 |>a%(T%):q%(J%+1)| 00000bc0 3d 71 25 28 4a 25 29 3a 71 25 28 4a 25 29 3d 54 |=q%(J%):q%(J%)=T| 00000bd0 25 3a 46 25 3d 4a 25 0d 05 46 0d ed 3a 49 25 3d |%:F%=J%..F..:I%=| 00000be0 46 25 2d 31 0d 05 50 09 fd 46 25 3d 31 0d 05 5a |F%-1..P..F%=1..Z| 00000bf0 05 e1 0d 05 64 05 3a 0d 05 6e 0c dd f2 73 68 61 |....d.:..n...sha| 00000c00 6b 65 72 0d 05 78 14 4c 25 3d 32 3a 52 25 3d 4e |ker..x.L%=2:R%=N| 00000c10 25 3a 4b 25 3d 4e 25 0d 05 82 05 f5 0d 05 8c 1c |%:K%=N%.........| 00000c20 e3 4a 25 3d 52 25 b8 4c 25 88 2d 31 3a 54 25 3d |.J%=R%.L%.-1:T%=| 00000c30 71 25 28 4a 25 2d 31 29 0d 05 96 36 e7 61 25 28 |q%(J%-1)...6.a%(| 00000c40 54 25 29 3e 61 25 28 71 25 28 4a 25 29 29 3a 71 |T%)>a%(q%(J%)):q| 00000c50 25 28 4a 25 2d 31 29 3d 71 25 28 4a 25 29 3a 71 |%(J%-1)=q%(J%):q| 00000c60 25 28 4a 25 29 3d 54 25 3a 4b 25 3d 4a 25 0d 05 |%(J%)=T%:K%=J%..| 00000c70 a0 0d ed 3a 4c 25 3d 4b 25 2b 31 0d 05 aa 19 e3 |...:L%=K%+1.....| 00000c80 4a 25 3d 4c 25 b8 52 25 3a 54 25 3d 71 25 28 4a |J%=L%.R%:T%=q%(J| 00000c90 25 2d 31 29 0d 05 b4 36 e7 61 25 28 54 25 29 3e |%-1)...6.a%(T%)>| 00000ca0 61 25 28 71 25 28 4a 25 29 29 3a 71 25 28 4a 25 |a%(q%(J%)):q%(J%| 00000cb0 2d 31 29 3d 71 25 28 4a 25 29 3a 71 25 28 4a 25 |-1)=q%(J%):q%(J%| 00000cc0 29 3d 54 25 3a 4b 25 3d 4a 25 0d 05 be 0d ed 3a |)=T%:K%=J%.....:| 00000cd0 52 25 3d 4b 25 2d 31 0d 05 c8 0a fd 4c 25 3e 52 |R%=K%-1.....L%>R| 00000ce0 25 0d 05 d2 05 e1 0d 05 dc 05 3a 0d 05 e6 23 dd |%.........:...#.| 00000cf0 f2 73 74 72 5f 69 6e 73 65 72 74 69 6f 6e 3a f2 |.str_insertion:.| 00000d00 69 6e 73 65 72 74 28 31 2c 4e 25 29 3a e1 0d 05 |insert(1,N%):...| 00000d10 f0 05 3a 0d 05 fa 13 dd f2 69 6e 73 65 72 74 28 |..:......insert(| 00000d20 4c 25 2c 52 25 29 0d 06 04 24 e3 49 25 3d 4c 25 |L%,R%)...$.I%=L%| 00000d30 2b 31 b8 52 25 3a 57 25 3d 71 25 28 49 25 29 3a |+1.R%:W%=q%(I%):| 00000d40 4a 25 3d 49 25 3a 46 25 3d a3 0d 06 0e 05 f5 0d |J%=I%:F%=.......| 00000d50 06 18 36 54 25 3d 71 25 28 4a 25 2d 31 29 3a e7 |..6T%=q%(J%-1):.| 00000d60 61 25 28 54 25 29 3e 61 25 28 57 25 29 3a 71 25 |a%(T%)>a%(W%):q%| 00000d70 28 4a 25 29 3d 54 25 3a 4a 25 3d 4a 25 2d 31 3a |(J%)=T%:J%=J%-1:| 00000d80 8b 46 25 3d b9 0d 06 22 07 fd 46 25 0d 06 2c 0d |.F%=..."..F%..,.| 00000d90 71 25 28 4a 25 29 3d 57 25 0d 06 36 05 ed 0d 06 |q%(J%)=W%..6....| 00000da0 40 05 e1 0d 06 4a 05 3a 0d 06 54 13 dd f2 62 69 |@....J.:..T...bi| 00000db0 6e 5f 69 6e 73 65 72 74 69 6f 6e 0d 06 5e 23 e3 |n_insertion..^#.| 00000dc0 49 25 3d 32 b8 4e 25 3a 57 25 3d 71 25 28 49 25 |I%=2.N%:W%=q%(I%| 00000dd0 29 3a 4c 25 3d 31 3a 52 25 3d 49 25 2d 31 0d 06 |):L%=1:R%=I%-1..| 00000de0 68 05 f5 0d 06 72 35 4d 25 3d 28 4c 25 2b 52 25 |h....r5M%=(L%+R%| 00000df0 29 81 32 3a e7 61 25 28 71 25 28 4d 25 29 29 3e |).2:.a%(q%(M%))>| 00000e00 61 25 28 57 25 29 3a 52 25 3d 4d 25 2d 31 3a 8b |a%(W%):R%=M%-1:.| 00000e10 3a 4c 25 3d 4d 25 2b 31 0d 06 7c 0a fd 4c 25 3e |:L%=M%+1..|..L%>| 00000e20 52 25 0d 06 86 35 e7 4c 25 3c 49 25 3a e3 4a 25 |R%...5.L%<I%:.J%| 00000e30 3d 49 25 2d 31 b8 4c 25 88 2d 31 3a 71 25 28 4a |=I%-1.L%.-1:q%(J| 00000e40 25 2b 31 29 3d 71 25 28 4a 25 29 3a ed 3a 71 25 |%+1)=q%(J%):.:q%| 00000e50 28 4c 25 29 3d 57 25 0d 06 90 05 ed 0d 06 9a 05 |(L%)=W%.........| 00000e60 e1 0d 06 a4 05 3a 0d 06 ae 0f dd f2 73 65 6c 65 |.....:......sele| 00000e70 63 74 69 6f 6e 0d 06 b8 14 e3 49 25 3d 31 b8 4e |ction.....I%=1.N| 00000e80 25 2d 31 3a 4d 25 3d 49 25 0d 06 c2 2e e3 4a 25 |%-1:M%=I%.....J%| 00000e90 3d 28 49 25 2b 31 29 b8 4e 25 3a e7 61 25 28 71 |=(I%+1).N%:.a%(q| 00000ea0 25 28 4a 25 29 29 3c 61 25 28 71 25 28 4d 25 29 |%(J%))<a%(q%(M%)| 00000eb0 29 3a 4d 25 3d 4a 25 0d 06 cc 27 ed 3a 54 25 3d |):M%=J%...'.:T%=| 00000ec0 71 25 28 4d 25 29 3a 71 25 28 4d 25 29 3d 71 25 |q%(M%):q%(M%)=q%| 00000ed0 28 49 25 29 3a 71 25 28 49 25 29 3d 54 25 0d 06 |(I%):q%(I%)=T%..| 00000ee0 d6 05 ed 0d 06 e0 05 e1 0d 06 ea 05 3a 0d 06 f4 |............:...| 00000ef0 0f dd f2 73 68 65 6c 6c 28 47 25 29 0d 06 fe 1c |...shell(G%)....| 00000f00 48 25 3d 31 3a f5 3a 48 25 3d 47 25 2a 48 25 2b |H%=1:.:H%=G%*H%+| 00000f10 31 3a fd 48 25 3e 4e 25 0d 07 08 0e f5 3a 48 25 |1:.H%>N%.....:H%| 00000f20 3d 48 25 81 47 25 0d 07 12 26 e3 49 25 3d 28 48 |=H%.G%...&.I%=(H| 00000f30 25 2b 31 29 b8 4e 25 3a 57 25 3d 71 25 28 49 25 |%+1).N%:W%=q%(I%| 00000f40 29 3a 4a 25 3d 49 25 3a 46 25 3d a3 0d 07 1c 05 |):J%=I%:F%=.....| 00000f50 f5 0d 07 26 45 e7 61 25 28 71 25 28 4a 25 2d 48 |...&E.a%(q%(J%-H| 00000f60 25 29 29 3e 61 25 28 57 25 29 3a 71 25 28 4a 25 |%))>a%(W%):q%(J%| 00000f70 29 3d 71 25 28 4a 25 2d 48 25 29 3a 4a 25 3d 4a |)=q%(J%-H%):J%=J| 00000f80 25 2d 48 25 3a 46 25 3d 28 4a 25 3c 3d 48 25 29 |%-H%:F%=(J%<=H%)| 00000f90 3a 8b 46 25 3d b9 0d 07 30 07 fd 46 25 0d 07 3a |:.F%=...0..F%..:| 00000fa0 0d 71 25 28 4a 25 29 3d 57 25 0d 07 44 05 ed 0d |.q%(J%)=W%..D...| 00000fb0 07 4e 09 fd 48 25 3d 31 0d 07 58 05 e1 0d 07 62 |.N..H%=1..X....b| 00000fc0 05 3a 0d 07 6c 24 dd f2 71 75 69 63 6b 3a 47 25 |.:..l$..quick:G%| 00000fd0 3d aa 28 4e 25 29 2b 33 3a f2 73 6f 72 74 28 31 |=.(N%)+3:.sort(1| 00000fe0 2c 4e 25 29 3a e1 0d 07 76 05 3a 0d 07 80 1b f4 |,N%):...v.:.....| 00000ff0 3a 51 75 69 63 6b 73 6f 72 74 20 3a 20 72 65 63 |:Quicksort : rec| 00001000 75 72 73 69 76 65 0d 07 8a 11 dd f2 73 6f 72 74 |ursive......sort| 00001010 28 4c 25 2c 52 25 29 0d 07 94 0a ea 49 25 2c 4a |(L%,R%).....I%,J| 00001020 25 0d 07 9e 1e e7 52 25 2d 4c 25 3c 47 25 3a f2 |%.....R%-L%<G%:.| 00001030 69 6e 73 65 72 74 28 4c 25 2c 52 25 29 3a e1 0d |insert(L%,R%):..| 00001040 07 a8 0b f2 6d 65 64 69 61 6e 0d 07 b2 1d 57 25 |....median....W%| 00001050 3d 61 25 28 71 25 28 4d 25 29 29 3a 49 25 3d 4c |=a%(q%(M%)):I%=L| 00001060 25 3a 4a 25 3d 52 25 0d 07 bc 05 f5 0d 07 c6 1d |%:J%=R%.........| 00001070 f5 3a 49 25 3d 49 25 2b 31 3a fd 61 25 28 71 25 |.:I%=I%+1:.a%(q%| 00001080 28 49 25 29 29 3e 3d 57 25 0d 07 d0 1d f5 3a 4a |(I%))>=W%.....:J| 00001090 25 3d 4a 25 2d 31 3a fd 61 25 28 71 25 28 4a 25 |%=J%-1:.a%(q%(J%| 000010a0 29 29 3c 3d 57 25 0d 07 da 2c e7 49 25 3c 4a 25 |))<=W%...,.I%<J%| 000010b0 3a 54 25 3d 71 25 28 4a 25 29 3a 71 25 28 4a 25 |:T%=q%(J%):q%(J%| 000010c0 29 3d 71 25 28 49 25 29 3a 71 25 28 49 25 29 3d |)=q%(I%):q%(I%)=| 000010d0 54 25 0d 07 e4 0a fd 4a 25 3c 49 25 0d 07 ee 4a |T%.....J%<I%...J| 000010e0 e7 28 52 25 2d 49 25 29 3e 28 4a 25 2d 4c 25 29 |.(R%-I%)>(J%-L%)| 000010f0 3a f2 73 6f 72 74 28 4c 25 2c 4a 25 29 3a f2 73 |:.sort(L%,J%):.s| 00001100 6f 72 74 28 49 25 2c 52 25 29 3a 8b 3a f2 73 6f |ort(I%,R%):.:.so| 00001110 72 74 28 49 25 2c 52 25 29 3a f2 73 6f 72 74 28 |rt(I%,R%):.sort(| 00001120 4c 25 2c 4a 25 29 0d 07 f8 05 e1 0d 08 02 05 3a |L%,J%).........:| 00001130 0d 08 0c 0c dd f2 6d 65 64 69 61 6e 0d 08 16 38 |......median...8| 00001140 54 25 3d 71 25 28 52 25 29 3a e7 61 25 28 71 25 |T%=q%(R%):.a%(q%| 00001150 28 4c 25 29 29 3e 61 25 28 54 25 29 3a 71 25 28 |(L%))>a%(T%):q%(| 00001160 52 25 29 3d 71 25 28 4c 25 29 3a 71 25 28 4c 25 |R%)=q%(L%):q%(L%| 00001170 29 3d 54 25 0d 08 20 10 4d 25 3d 28 4c 25 2b 52 |)=T%.. .M%=(L%+R| 00001180 25 29 81 32 0d 08 2a 38 54 25 3d 71 25 28 52 25 |%).2..*8T%=q%(R%| 00001190 29 3a e7 61 25 28 71 25 28 4d 25 29 29 3e 61 25 |):.a%(q%(M%))>a%| 000011a0 28 54 25 29 3a 71 25 28 52 25 29 3d 71 25 28 4d |(T%):q%(R%)=q%(M| 000011b0 25 29 3a 71 25 28 4d 25 29 3d 54 25 0d 08 34 38 |%):q%(M%)=T%..48| 000011c0 54 25 3d 71 25 28 4d 25 29 3a e7 61 25 28 71 25 |T%=q%(M%):.a%(q%| 000011d0 28 4c 25 29 29 3e 61 25 28 54 25 29 3a 71 25 28 |(L%))>a%(T%):q%(| 000011e0 4d 25 29 3d 71 25 28 4c 25 29 3a 71 25 28 4c 25 |M%)=q%(L%):q%(L%| 000011f0 29 3d 54 25 0d 08 3e 05 e1 0d 08 48 05 3a 0d 08 |)=T%..>....H.:..| 00001200 52 0e dd f2 71 75 69 63 6b 5f 6e 72 0d 08 5c 1e |R...quick_nr..\.| 00001210 47 25 3d aa 28 4e 25 29 2b 33 3a 4c 25 3d 31 3a |G%=.(N%)+3:L%=1:| 00001220 52 25 3d 4e 25 3a 53 25 3d 32 0d 08 66 05 f5 0d |R%=N%:S%=2..f...| 00001230 08 70 33 e7 52 25 3e 4c 25 3a f2 6e 72 5f 73 6f |.p3.R%>L%:.nr_so| 00001240 72 74 3a 8b 3a 53 25 3d 53 25 2d 32 3a 4c 25 3d |rt:.:S%=S%-2:L%=| 00001250 73 25 28 53 25 29 3a 52 25 3d 73 25 28 53 25 2b |s%(S%):R%=s%(S%+| 00001260 31 29 0d 08 7a 09 fd 53 25 3c 32 0d 08 84 05 e1 |1)..z..S%<2.....| 00001270 0d 08 8e 05 3a 0d 08 98 1f f4 3a 51 75 69 63 6b |....:.....:Quick| 00001280 73 6f 72 74 20 3a 20 6e 6f 6e 2d 72 65 63 75 72 |sort : non-recur| 00001290 73 69 76 65 0d 08 a2 0d dd f2 6e 72 5f 73 6f 72 |sive......nr_sor| 000012a0 74 0d 08 ac 24 e7 52 25 2d 4c 25 3c 47 25 3a f2 |t...$.R%-L%<G%:.| 000012b0 69 6e 73 65 72 74 28 4c 25 2c 52 25 29 3a 52 25 |insert(L%,R%):R%| 000012c0 3d 4c 25 3a e1 0d 08 b6 0b f2 6d 65 64 69 61 6e |=L%:......median| 000012d0 0d 08 c0 1d 57 25 3d 61 25 28 71 25 28 4d 25 29 |....W%=a%(q%(M%)| 000012e0 29 3a 49 25 3d 4c 25 3a 4a 25 3d 52 25 0d 08 ca |):I%=L%:J%=R%...| 000012f0 05 f5 0d 08 d4 1d f5 3a 49 25 3d 49 25 2b 31 3a |.......:I%=I%+1:| 00001300 fd 61 25 28 71 25 28 49 25 29 29 3e 3d 57 25 0d |.a%(q%(I%))>=W%.| 00001310 08 de 1d f5 3a 4a 25 3d 4a 25 2d 31 3a fd 61 25 |....:J%=J%-1:.a%| 00001320 28 71 25 28 4a 25 29 29 3c 3d 57 25 0d 08 e8 2c |(q%(J%))<=W%...,| 00001330 e7 49 25 3c 4a 25 3a 54 25 3d 71 25 28 4a 25 29 |.I%<J%:T%=q%(J%)| 00001340 3a 71 25 28 4a 25 29 3d 71 25 28 49 25 29 3a 71 |:q%(J%)=q%(I%):q| 00001350 25 28 49 25 29 3d 54 25 0d 08 f2 0a fd 4a 25 3c |%(I%)=T%.....J%<| 00001360 49 25 0d 08 fc 4e e7 28 52 25 2d 49 25 29 3e 28 |I%...N.(R%-I%)>(| 00001370 4a 25 2d 4c 25 29 3a 73 25 28 53 25 29 3d 49 25 |J%-L%):s%(S%)=I%| 00001380 3a 73 25 28 53 25 2b 31 29 3d 52 25 3a 52 25 3d |:s%(S%+1)=R%:R%=| 00001390 4a 25 3a 8b 3a 73 25 28 53 25 29 3d 4c 25 3a 73 |J%:.:s%(S%)=L%:s| 000013a0 25 28 53 25 2b 31 29 3d 4a 25 3a 4c 25 3d 49 25 |%(S%+1)=J%:L%=I%| 000013b0 0d 09 06 0b 53 25 3d 53 25 2b 32 0d 09 10 05 e1 |....S%=S%+2.....| 000013c0 0d 09 1a 05 3a 0d 09 24 11 dd f2 71 75 69 63 6b |....:..$...quick| 000013d0 69 6e 73 65 72 74 0d 09 2e 1e 47 25 3d aa 28 4e |insert....G%=.(N| 000013e0 25 29 2b 33 3a 4c 25 3d 31 3a 52 25 3d 4e 25 3a |%)+3:L%=1:R%=N%:| 000013f0 53 25 3d 32 0d 09 38 05 f5 0d 09 42 36 e7 52 25 |S%=2..8....B6.R%| 00001400 3e 4c 25 2b 47 25 3a f2 73 65 64 5f 73 72 74 3a |>L%+G%:.sed_srt:| 00001410 8b 3a 53 25 3d 53 25 2d 32 3a 4c 25 3d 73 25 28 |.:S%=S%-2:L%=s%(| 00001420 53 25 29 3a 52 25 3d 73 25 28 53 25 2b 31 29 0d |S%):R%=s%(S%+1).| 00001430 09 4c 09 fd 53 25 3c 32 0d 09 56 12 f2 73 74 72 |.L..S%<2..V..str| 00001440 5f 69 6e 73 65 72 74 69 6f 6e 0d 09 60 05 e1 0d |_insertion..`...| 00001450 09 6a 05 3a 0d 09 74 2e f4 3a 51 75 69 63 6b 73 |.j.:..t..:Quicks| 00001460 6f 72 74 20 61 20 6c 61 20 53 65 64 67 65 77 69 |ort a la Sedgewi| 00001470 63 6b 20 3a 20 6e 6f 6e 2d 72 65 63 75 72 73 69 |ck : non-recursi| 00001480 76 65 0d 09 7e 0d dd f2 73 65 64 5f 73 72 74 0d |ve..~...sed_srt.| 00001490 09 88 0b f2 6d 65 64 69 61 6e 0d 09 92 33 49 25 |....median...3I%| 000014a0 3d 4c 25 3a 4a 25 3d 52 25 2d 31 3a 54 25 3d 71 |=L%:J%=R%-1:T%=q| 000014b0 25 28 4d 25 29 3a 71 25 28 4d 25 29 3d 71 25 28 |%(M%):q%(M%)=q%(| 000014c0 4a 25 29 3a 71 25 28 4a 25 29 3d 54 25 0d 09 9c |J%):q%(J%)=T%...| 000014d0 11 57 25 3d 61 25 28 71 25 28 4a 25 29 29 0d 09 |.W%=a%(q%(J%))..| 000014e0 a6 05 f5 0d 09 b0 1d f5 3a 49 25 3d 49 25 2b 31 |........:I%=I%+1| 000014f0 3a fd 61 25 28 71 25 28 49 25 29 29 3e 3d 57 25 |:.a%(q%(I%))>=W%| 00001500 0d 09 ba 1d f5 3a 4a 25 3d 4a 25 2d 31 3a fd 61 |.....:J%=J%-1:.a| 00001510 25 28 71 25 28 4a 25 29 29 3c 3d 57 25 0d 09 c4 |%(q%(J%))<=W%...| 00001520 2c e7 49 25 3c 4a 25 3a 54 25 3d 71 25 28 4a 25 |,.I%<J%:T%=q%(J%| 00001530 29 3a 71 25 28 4a 25 29 3d 71 25 28 49 25 29 3a |):q%(J%)=q%(I%):| 00001540 71 25 28 49 25 29 3d 54 25 0d 09 ce 30 fd 4a 25 |q%(I%)=T%...0.J%| 00001550 3c 49 25 3a 54 25 3d 71 25 28 49 25 29 3a 71 25 |<I%:T%=q%(I%):q%| 00001560 28 49 25 29 3d 71 25 28 52 25 2d 31 29 3a 71 25 |(I%)=q%(R%-1):q%| 00001570 28 52 25 2d 31 29 3d 54 25 0d 09 d8 56 e7 28 52 |(R%-1)=T%...V.(R| 00001580 25 2d 49 25 29 3e 28 4a 25 2d 4c 25 29 3a 73 25 |%-I%)>(J%-L%):s%| 00001590 28 53 25 29 3d 49 25 2b 31 3a 73 25 28 53 25 2b |(S%)=I%+1:s%(S%+| 000015a0 31 29 3d 52 25 3a 52 25 3d 49 25 2d 31 3a 8b 3a |1)=R%:R%=I%-1:.:| 000015b0 73 25 28 53 25 29 3d 4c 25 3a 73 25 28 53 25 2b |s%(S%)=L%:s%(S%+| 000015c0 31 29 3d 49 25 2d 31 3a 4c 25 3d 49 25 2b 31 0d |1)=I%-1:L%=I%+1.| 000015d0 09 e2 0b 53 25 3d 53 25 2b 32 0d 09 ec 05 e1 0d |...S%=S%+2......| 000015e0 09 f6 05 3a 0d 0a 00 0a dd f2 68 65 61 70 0d 0a |...:......heap..| 000015f0 0a 09 4d 25 3d 4e 25 0d 0a 14 1e e3 4c 25 3d 4e |..M%=N%.....L%=N| 00001600 25 81 32 b8 31 88 2d 31 3a f2 64 68 65 61 70 28 |%.2.1.-1:.dheap(| 00001610 4c 25 29 3a ed 0d 0a 1e 05 f5 0d 0a 28 3b 54 25 |L%):........(;T%| 00001620 3d 71 25 28 4d 25 29 3a 71 25 28 4d 25 29 3d 71 |=q%(M%):q%(M%)=q| 00001630 25 28 31 29 3a 71 25 28 31 29 3d 54 25 3a 4d 25 |%(1):q%(1)=T%:M%| 00001640 3d 4d 25 2d 31 3a e7 4d 25 3e 31 3a f2 64 68 65 |=M%-1:.M%>1:.dhe| 00001650 61 70 28 31 29 0d 0a 32 09 fd 4d 25 3d 30 0d 0a |ap(1)..2..M%=0..| 00001660 3c 05 e1 0d 0a 46 05 3a 0d 0a 50 0f dd f2 64 68 |<....F.:..P...dh| 00001670 65 61 70 28 4b 25 29 0d 0a 5a 1a 57 25 3d 71 25 |eap(K%)..Z.W%=q%| 00001680 28 4b 25 29 3a 46 25 3d a3 3a 47 25 3d 4d 25 81 |(K%):F%=.:G%=M%.| 00001690 32 0d 0a 64 05 f5 0d 0a 6e 34 4a 25 3d 4b 25 2b |2..d....n4J%=K%+| 000016a0 4b 25 3a e7 4a 25 3c 4d 25 3a e7 61 25 28 71 25 |K%:.J%<M%:.a%(q%| 000016b0 28 4a 25 29 29 3c 61 25 28 71 25 28 4a 25 2b 31 |(J%))<a%(q%(J%+1| 000016c0 29 29 3a 4a 25 3d 4a 25 2b 31 0d 0a 78 32 e7 61 |)):J%=J%+1..x2.a| 000016d0 25 28 57 25 29 3e 3d 61 25 28 71 25 28 4a 25 29 |%(W%)>=a%(q%(J%)| 000016e0 29 3a 46 25 3d b9 3a 8b 3a 71 25 28 4b 25 29 3d |):F%=.:.:q%(K%)=| 000016f0 71 25 28 4a 25 29 3a 4b 25 3d 4a 25 0d 0a 82 17 |q%(J%):K%=J%....| 00001700 fd 46 25 84 4b 25 3e 47 25 3a 71 25 28 4b 25 29 |.F%.K%>G%:q%(K%)| 00001710 3d 57 25 0d 0a 8c 05 e1 0d 0a 96 05 3a 0d 0a a0 |=W%.........:...| 00001720 0b dd f2 72 61 64 69 78 0d 0a aa 19 4d 25 3d 32 |...radix....M%=2| 00001730 3a f5 3a 4d 25 3d 4d 25 2a 32 3a fd 4d 25 3e 4e |:.:M%=M%*2:.M%>N| 00001740 25 0d 0a b4 11 f2 72 61 64 28 31 2c 4e 25 2c 4d |%.....rad(1,N%,M| 00001750 25 29 0d 0a be 05 e1 0d 0a c8 05 3a 0d 0a d2 13 |%).........:....| 00001760 dd f2 72 61 64 28 4c 25 2c 52 25 2c 42 25 29 0d |..rad(L%,R%,B%).| 00001770 0a dc 0d e7 52 25 3c 3d 4c 25 3a e1 0d 0a e6 16 |....R%<=L%:.....| 00001780 ea 49 25 2c 4a 25 3a 49 25 3d 4c 25 3a 4a 25 3d |.I%,J%:I%=L%:J%=| 00001790 52 25 0d 0a f0 05 f5 0d 0a fa 39 46 25 3d a3 3a |R%........9F%=.:| 000017a0 f5 3a e7 28 28 28 61 25 28 71 25 28 49 25 29 29 |.:.(((a%(q%(I%))| 000017b0 29 81 42 25 29 80 31 29 3d 30 3a e7 49 25 3c 4a |).B%).1)=0:.I%<J| 000017c0 25 3a 49 25 3d 49 25 2b 31 3a 8b 3a 46 25 3d b9 |%:I%=I%+1:.:F%=.| 000017d0 0d 0b 04 07 fd 46 25 0d 0b 0e 37 46 25 3d a3 3a |.....F%...7F%=.:| 000017e0 f5 3a e7 28 28 28 61 25 28 71 25 28 4a 25 29 29 |.:.(((a%(q%(J%))| 000017f0 29 81 42 25 29 80 31 29 3a e7 49 25 3c 4a 25 3a |).B%).1):.I%<J%:| 00001800 4a 25 3d 4a 25 2d 31 3a 8b 3a 46 25 3d b9 0d 0b |J%=J%-1:.:F%=...| 00001810 18 29 fd 46 25 3a 54 25 3d 71 25 28 4a 25 29 3a |.).F%:T%=q%(J%):| 00001820 71 25 28 4a 25 29 3d 71 25 28 49 25 29 3a 71 25 |q%(J%)=q%(I%):q%| 00001830 28 49 25 29 3d 54 25 0d 0b 22 29 fd 4a 25 3d 49 |(I%)=T%..").J%=I| 00001840 25 3a e7 28 28 61 25 28 71 25 28 52 25 29 29 81 |%:.((a%(q%(R%)).| 00001850 42 25 29 80 31 29 3d 30 3a 4a 25 3d 4a 25 2b 31 |B%).1)=0:J%=J%+1| 00001860 0d 0b 2c 31 e7 42 25 3e 31 3a 42 25 3d 42 25 81 |..,1.B%>1:B%=B%.| 00001870 32 3a f2 72 61 64 28 4c 25 2c 4a 25 2d 31 2c 42 |2:.rad(L%,J%-1,B| 00001880 25 29 3a f2 72 61 64 28 4a 25 2c 52 25 2c 42 25 |%):.rad(J%,R%,B%| 00001890 29 0d 0b 36 05 e1 0d 0b 40 05 3a 0d 0b 4a 11 dd |)..6....@.:..J..| 000018a0 f2 73 74 72 5f 72 61 64 28 47 25 29 0d 0b 54 12 |.str_rad(G%)..T.| 000018b0 4d 25 3d 32 5e 47 25 2d 31 3a 47 25 3d 31 0d 0b |M%=2^G%-1:G%=1..| 000018c0 5e 19 f5 3a e3 4a 25 3d 30 b8 4d 25 3a 63 25 28 |^..:.J%=0.M%:c%(| 000018d0 4a 25 29 3d 30 3a ed 0d 0b 68 36 e3 49 25 3d 31 |J%)=0:...h6.I%=1| 000018e0 b8 4e 25 3a 4a 25 3d 28 28 61 25 28 71 25 28 49 |.N%:J%=((a%(q%(I| 000018f0 25 29 29 29 81 47 25 29 80 4d 25 3a 63 25 28 4a |%))).G%).M%:c%(J| 00001900 25 29 3d 63 25 28 4a 25 29 2b 31 3a ed 0d 0b 72 |%)=c%(J%)+1:...r| 00001910 25 e3 4a 25 3d 31 b8 4d 25 3a 63 25 28 4a 25 29 |%.J%=1.M%:c%(J%)| 00001920 3d 63 25 28 4a 25 2d 31 29 2b 63 25 28 4a 25 29 |=c%(J%-1)+c%(J%)| 00001930 3a ed 0d 0b 7c 27 e3 49 25 3d 4e 25 b8 31 88 2d |:...|'.I%=N%.1.-| 00001940 31 3a 4a 25 3d 28 28 61 25 28 71 25 28 49 25 29 |1:J%=((a%(q%(I%)| 00001950 29 29 81 47 25 29 80 4d 25 0d 0b 86 29 54 25 3d |)).G%).M%...)T%=| 00001960 63 25 28 4a 25 29 3a 73 25 28 54 25 29 3d 71 25 |c%(J%):s%(T%)=q%| 00001970 28 49 25 29 3a 63 25 28 4a 25 29 3d 54 25 2d 31 |(I%):c%(J%)=T%-1| 00001980 3a ed 0d 0b 90 32 e3 49 25 3d 31 b8 4e 25 3a 71 |:....2.I%=1.N%:q| 00001990 25 28 49 25 29 3d 73 25 28 49 25 29 3a ed 3a 47 |%(I%)=s%(I%):.:G| 000019a0 25 3d 28 4d 25 2b 31 29 2a 47 25 3a fd 47 25 3e |%=(M%+1)*G%:.G%>| 000019b0 4e 25 3a e1 0d 0b 9a 05 3a 0d 0b a4 16 dd f2 6d |N%:.....:......m| 000019c0 65 72 67 65 28 4c 25 2c 52 25 29 3a ea 4d 25 0d |erge(L%,R%):.M%.| 000019d0 0b ae 10 4d 25 3d 28 4c 25 2b 52 25 29 81 32 0d |...M%=(L%+R%).2.| 000019e0 0b b8 18 e7 4d 25 3e 4c 25 3a f2 6d 65 72 67 65 |....M%>L%:.merge| 000019f0 28 4c 25 2c 4d 25 29 0d 0b c2 1c e7 4d 25 2b 31 |(L%,M%).....M%+1| 00001a00 3c 52 25 3a f2 6d 65 72 67 65 28 4d 25 2b 31 2c |<R%:.merge(M%+1,| 00001a10 52 25 29 0d 0b cc 23 e3 49 25 3d 4c 25 b8 4d 25 |R%)...#.I%=L%.M%| 00001a20 3a 73 25 28 49 25 29 3d 71 25 28 49 25 29 3a ed |:s%(I%)=q%(I%):.| 00001a30 3a 49 25 3d 4c 25 0d 0b d6 33 54 25 3d 52 25 2b |:I%=L%...3T%=R%+| 00001a40 4d 25 2b 31 3a e3 4a 25 3d 4d 25 2b 31 b8 52 25 |M%+1:.J%=M%+1.R%| 00001a50 3a 73 25 28 54 25 2d 4a 25 29 3d 71 25 28 4a 25 |:s%(T%-J%)=q%(J%| 00001a60 29 3a ed 3a 4a 25 3d 52 25 0d 0b e0 0d e3 4b 25 |):.:J%=R%.....K%| 00001a70 3d 4c 25 b8 52 25 0d 0b ea 48 e7 61 25 28 73 25 |=L%.R%...H.a%(s%| 00001a80 28 49 25 29 29 3c 61 25 28 73 25 28 4a 25 29 29 |(I%))<a%(s%(J%))| 00001a90 3a 71 25 28 4b 25 29 3d 73 25 28 49 25 29 3a 49 |:q%(K%)=s%(I%):I| 00001aa0 25 3d 49 25 2b 31 3a 8b 3a 71 25 28 4b 25 29 3d |%=I%+1:.:q%(K%)=| 00001ab0 73 25 28 4a 25 29 3a 4a 25 3d 4a 25 2d 31 0d 0b |s%(J%):J%=J%-1..| 00001ac0 f4 05 ed 0d 0b fe 05 e1 0d 0c 08 05 3a 0d 0c 12 |............:...| 00001ad0 0a dd f2 63 6f 6e 74 0d 0c 1c 24 f1 27 22 50 72 |...cont...$.'"Pr| 00001ae0 65 73 73 20 53 70 61 63 65 62 61 72 20 74 6f 20 |ess Spacebar to | 00001af0 63 6f 6e 74 69 6e 75 65 2e 22 3b 0d 0c 26 18 f5 |continue.";..&..| 00001b00 3a 49 3d a6 28 64 65 6c 61 79 29 3a fd 49 3d 33 |:I=.(delay):.I=3| 00001b10 32 84 49 0d 0c 30 05 e1 0d 0c 3a 05 3a 0d 0c 44 |2.I..0....:.:..D| 00001b20 0d dd f2 72 65 73 75 6c 74 73 0d 0c 4e 1c 64 65 |...results..N.de| 00001b30 6c 61 79 3d 32 45 35 3a 70 72 69 6e 74 3d a3 3a |lay=2E5:print=.:| 00001b40 ef 32 36 2c 31 32 0d 0c 58 05 f5 0d 0c 62 1e e7 |.26,12..X....b..| 00001b50 70 72 69 6e 74 3a f1 27 3a ef 32 2c 32 31 2c 31 |print:.':.2,21,1| 00001b60 36 3a 2a 46 58 32 31 2c 30 0d 0c 6c 19 f1 22 20 |6:*FX21,0..l.." | 00001b70 20 4d 45 54 48 4f 44 22 89 32 32 3b 22 54 49 4d | METHOD".22;"TIM| 00001b80 45 22 0d 0c 76 37 e3 6d 74 68 64 3d 66 69 72 73 |E"..v7.mthd=firs| 00001b90 74 20 b8 6c 61 73 74 3a 54 24 3d a4 74 69 6d 65 |t .last:T$=.time| 00001ba0 3a f1 27 4d 24 28 6d 74 68 64 29 53 24 8a 33 36 |:.'M$(mthd)S$.36| 00001bb0 2d a9 54 24 29 54 24 3a ed 0d 0c 80 0d f1 27 4e |-.T$)T$:......'N| 00001bc0 24 22 77 61 73 22 0d 0c 8a 49 e7 4f 25 3c 35 3a |$"was"...I.O%<5:| 00001bd0 f1 50 24 6e 24 22 20 69 6e 22 27 4f 24 28 4f 25 |.P$n$" in"'O$(O%| 00001be0 29 22 20 6f 72 64 65 72 2e 22 3a 8b f1 52 24 22 |)" order.":..R$"| 00001bf0 62 65 74 77 65 65 6e 20 31 20 61 6e 64 20 22 6e |between 1 and "n| 00001c00 24 27 22 2d 20 22 4f 24 28 4f 25 29 22 2e 22 0d |$'"- "O$(O%)".".| 00001c10 0c 94 50 f1 3a e7 70 72 69 6e 74 3a ef 36 2c 33 |..P.:.print:.6,3| 00001c20 3a 70 72 69 6e 74 3d a3 3a 8b 3a f1 22 44 6f 20 |:print=.:.:."Do | 00001c30 79 6f 75 20 77 61 6e 74 20 61 20 50 72 69 6e 74 |you want a Print| 00001c40 6f 75 74 20 28 59 2f 4e 29 3f 20 22 3b 3a 70 72 |out (Y/N)? ";:pr| 00001c50 69 6e 74 3d 31 2d a4 69 6e 28 22 4e 59 22 29 0d |int=1-.in("NY").| 00001c60 0c 9e 43 e7 70 72 69 6e 74 3a e8 27 22 4c 65 66 |..C.print:.'"Lef| 00001c70 74 20 6d 61 72 67 69 6e 20 28 30 2d 34 33 29 20 |t margin (0-43) | 00001c80 3a 20 22 49 3a ef 32 2c 31 2c 32 37 2c 31 2c 36 |: "I:.2,1,27,1,6| 00001c90 34 2c 31 2c 32 37 2c 31 2c 31 30 38 2c 31 2c 49 |4,1,27,1,108,1,I| 00001ca0 2c 33 0d 0c a8 0b fd ac 70 72 69 6e 74 0d 0c b2 |,3......print...| 00001cb0 09 f2 63 6f 6e 74 0d 0c bc 05 e1 0d 0c c6 05 3a |..cont.........:| 00001cc0 0d 0c d0 24 dd a4 69 6e 28 64 24 29 3a f5 3a 49 |...$..in(d$):.:I| 00001cd0 3d a7 64 24 2c bd 28 a5 80 26 44 46 29 29 3a fd |=.d$,.(..&DF)):.| 00001ce0 49 3a 3d 49 0d 0c da 05 3a 0d 0c e4 23 dd a4 74 |I:=I....:...#..t| 00001cf0 69 6d 65 3a 3d c3 28 31 30 2a 74 69 6d 65 25 28 |ime:=.(10*time%(| 00001d00 6d 74 68 64 29 29 2b 22 20 6d 73 22 0d 0c ee 05 |mthd))+" ms"....| 00001d10 3a 0d 0c f8 0a dd f2 6c 69 73 74 0d 0d 02 0a db |:......list.....| 00001d20 3a 46 25 3d a3 0d 0d 0c 0c e3 49 25 3d 31 b8 4e |:F%=......I%=1.N| 00001d30 25 0d 0d 16 20 f1 49 25 2c 71 25 28 49 25 29 2c |%... .I%,q%(I%),| 00001d40 61 25 28 49 25 29 2c 61 25 28 71 25 28 49 25 29 |a%(I%),a%(q%(I%)| 00001d50 29 0d 0d 20 21 e7 61 25 28 71 25 28 49 25 29 29 |).. !.a%(q%(I%))| 00001d60 3c 61 25 28 71 25 28 49 25 2d 31 29 29 3a 46 25 |<a%(q%(I%-1)):F%| 00001d70 3d b9 0d 0d 2a 05 ed 0d 0d 34 1b e7 46 25 3a ef |=...*....4..F%:.| 00001d80 37 3a f1 22 44 69 73 63 72 65 70 61 6e 63 79 20 |7:."Discrepancy | 00001d90 21 22 0d 0d 3e 05 e1 0d 0d 48 05 3a 0d 0d 52 1b |!"..>....H.:..R.| 00001da0 dd f2 71 75 69 74 3a 40 25 3d 31 30 3a ef 33 3a |..quit:@%=10:.3:| 00001db0 2a 46 58 31 32 2c 30 0d 0d 5c 1f f1 27 22 50 72 |*FX12,0..\..'"Pr| 00001dc0 65 73 73 20 66 30 20 74 6f 20 72 75 6e 20 61 67 |ess f0 to run ag| 00001dd0 61 69 6e 2e 22 3b 0d 0d 66 05 e1 0d 0d 70 0e cd |ain.";..f....p..| 00001de0 22 53 6f 72 54 65 73 74 22 0d ff |"SorTest"..| 00001deb