Author | Message |
---|
Meka][Meka Unstopable Posts: 700
| ok for this, there will be 3 n half days to complete ( starting from now ) the thread wlll be closed on Saturday.... ok your program must sort a randomized array of characters... so, you will be using a to z of characters.... abcdefghijklmnopqrstuvwxyz the first line to be called should be s = GetTickCount() and the second last must be e = GetTickCount() then last line will be messagebox to show the time taken in miliseconds.... i or someone i choose to test the code will record the speed of the array sort.... this will include building the array then sorting it. ok the example follows the char array must be 10000 characters long
Code: | program Sortarray s = GetTickCount(); Randomize; do loop array = randomchar(); loop until done lol //ok now sort the array do loop SortTheArrayOFCharsIntoAlphabeticalOrder() finish when comleted sorting e = GetTickCount(); messagebox ( e-s..'ms' ); | im at work now... so if i get time i will write my version here (if i get time that is) btw the rules are as follows: 1: you may not copy someone elses routine and make it faster, it must be your own routine... 2: it can be written in any language. 3. you can post as many as you like, but read rule 1. 4: the contest closes on saturday. [EDIT] extended til sunday night, due to requests. 5. do not find code on the internet, if found to be doing so you will be disqualified. 6. you may not use built in sorting routines, they must be coded yourself.
|
Meka][Meka Unstopable Posts: 700
| ok quick one i've just put together, tested in delphi 7 and above, i won't bother testing speed here at work, i'll test it on Judging PC once i get home, and then post the speed, and then i'll make it quicker :-P for this i've chose the easy route.....
Code: | program ArraySort; uses SysUtils, Windows; const arrA : array[0..25] of char = ('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'); var s: Integer; myArr : array of char; iArr: Integer; sTemp: char; bFound: Boolean; begin s := GetTickCount(); SetLength(myArr, 10000); Randomize; for iArr := 0 to 9999 do myArr[iArr] := arrA[Random(25)]; while 1=1 do begin bFound := False; iArr := 0; while iArr < 9999 do begin if myArr[iArr] > myArr[iArr+1] then begin sTemp := myArr[iArr]; myArr[iArr] := myArr[iArr+1]; myArr[iArr+1] := sTemp; bFound := True; end; Inc(iArr); end; if bFound = False then break; end; myArr[9999] := #0; s := GetTickCount() - s; MessageBox(0, PAnsiChar(IntToStr(s) + 'ms'),'Result', MB_OK); end. |
|
Meka][Meka Unstopable Posts: 700
| ok a slightly faster version:
Code: | program ArraySort; uses SysUtils, Windows; const arrA : array[0..25] of byte = (97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122); var s: Cardinal; myArr : array of byte; iArr: Cardinal; byTemp: byte; bFound: Boolean; begin s := GetTickCount(); SetLength(myArr, 10000); Randomize; for iArr := 0 to 9999 do myArr[iArr] := arrA[Random(25)]; while 1=1 do begin bFound := False; iArr := 0; while iArr < 9999 do begin if myArr[iArr] > myArr[iArr+1] then begin byTemp := myArr[iArr]; myArr[iArr] := myArr[iArr+1]; myArr[iArr+1] := byTemp; bFound := True; end; Inc(iArr); end; if bFound = False then break; end; myArr[9999] := 0; s := GetTickCount() - s; MessageBox(0, PAnsiChar(IntToStr(s) + 'ms'),'Result', MB_OK); end. | simply using bytes, and also using cardinal rather then integer, i dont know why but cardinal seems to be inc quicker.
|
Meka][Meka Unstopable Posts: 700
| ok as a request i'm making the target counter large it is now 30,000 characters
Code: | program ArraySort; uses SysUtils, Windows; const arrA : array[0..25] of byte = (97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122); var s: Cardinal; myArr : array of byte; iArr: Cardinal; byTemp: byte; bFound: Boolean; begin s := GetTickCount(); SetLength(myArr, 30000); Randomize; for iArr := 0 to 29999 do myArr[iArr] := arrA[Random(25)]; while 1=1 do begin bFound := False; iArr := 0; while iArr < 29999 do begin if myArr[iArr] > myArr[iArr+1] then begin byTemp := myArr[iArr]; myArr[iArr] := myArr[iArr+1]; myArr[iArr+1] := byTemp; bFound := True; end; Inc(iArr); end; if bFound = False then break; end; myArr[29999] := 0; s := GetTickCount() - s; MessageBox(0, PAnsiChar(IntToStr(s) + 'ms'),'Result', MB_OK); end. |
|
dzadzuks Ametuar Posts: 135
| My C code (with 30000 chars):
Code: | #include <windows.h> #include <stdio.h> #include <stdlib.h> #include <time.h> void SortArray() { long start,stop; int counter=0,counter2=0; char wildArray[30001],sortedArray[30001]; start=GetTickCount(); srand((unsigned int)time(NULL)); for (counter=0;counter!=30000;counter++) { wildArray[counter]=((rand() % 26) + 97); } wildArray[30000]='\0'; for (counter=97;counter!=123;counter++) { for (int i=0;i!=30000;i++) { if (wildArray[i]==counter) { sortedArray[counter2]=counter; counter2++; } } } sortedArray[30000]='\0'; stop=GetTickCount(); char result[10]; sprintf(result,"%ld",(stop-start)); MessageBoxA(0,(const char*)result,"Result in ms...",MB_OK); } int main() { SortArray(); return 0; } | :twisted:
|
Meka][Meka Unstopable Posts: 700
| dzad, your choice for sorting array is far superior to the sample ive done, im sure it will be very difficult to compare with, it is light speed. well done
|
dzadzuks Ametuar Posts: 135
| thanks
|
Meka][Meka Unstopable Posts: 700
| sorry im late been exception Busy() end; CLOSED dzadzuks is by far the contest winner!
|