1. Sort problem
- Posted by don cole <doncole at pacbell.net> Jun 09, 2007
- 679 views
- Last edited Jun 10, 2007
Hello Anybody maybe Andy Serpa, I am trying to sort some numbers. These are all strings. Lowest number "0888". highest number "4430". After sort() or nat_sort() I still get "0888" as the highest number and "1067" as the lowest. Any advice welcome. Don Cole
2. Re: Sort problem
- Posted by Bernie Ryan <xotron at bluefrog.com> Jun 09, 2007
- 565 views
- Last edited Jun 10, 2007
don cole wrote: > > > Hello Anybody maybe Andy Serpa, > > I am trying to sort some numbers. These are all strings. > > Lowest number "0888". highest number "4430". > > After sort() or nat_sort() I still get "0888" as the highest number and "1067" > as the lowest. > > Any advice welcome. > Don: Is it because you are sorting text and not numbers ? Bernie My files in archive: WMOTOR, XMOTOR, W32ENGIN, MIXEDLIB, EU_ENGIN, WIN32ERU, WIN32API Can be downloaded here: http://www.rapideuphoria.com/cgi-bin/asearch.exu?dos=on&win=on&lnx=on&gen=on&keywords=bernie+ryan
3. Re: Sort problem
- Posted by Andy Serpa <ac at onehorseshy.com> Jun 10, 2007
- 592 views
don cole wrote: > > > Hello Anybody maybe Andy Serpa, > > I am trying to sort some numbers. These are all strings. > > Lowest number "0888". highest number "4430". > > After sort() or nat_sort() I still get "0888" as the highest number and "1067" > as the lowest. > > Any advice welcome. > You must be doing something wrong? If you use leading zeros like in "0888" so that all strings are the same length even regular sort will work correctly (in numeric order). Take a closer look at your code, or post it...
4. Re: Sort problem
- Posted by don cole <doncole at pacbell.net> Jun 10, 2007
- 586 views
Thanks Brian and Andy, Here' my code very simplified.
sequence db
db=repeat({},3)
db[1]={"0888","2485","1476"} db[2]={"A1071","A3108","A3011"} db[3]={"D0970","D1078","D2530","D1233"}
for x=1 to length(db) do db[x]=nat_sort(db[x]) end for
Don Cole }}}
5. Re: Sort problem
- Posted by Juergen Luethje <j.lue at gmx.de> Jun 10, 2007
- 620 views
I don't know nat_sort() but in this case, as Andy wrote, Euphoria's standard sort() works fine:
include sort.e include misc.e sequence db db = repeat({},3) db[1] = {"0888","2485","1476"} db[2] = {"A1071","A3108","A3011"} db[3] = {"D0970","D1078","D2530","D1233"} for x = 1 to length(db) do db[x] = sort(db[x]) pretty_print(1, db[x], {3}) puts(1, "\n--------------------------\n") end for
Regards, Juergen
6. Re: Sort problem
- Posted by Derek Parnell <ddparnell at bigpond.com> Jun 10, 2007
- 559 views
don cole wrote: > Here' my code very simplified. ... Don, you need to be a bit more helpful if you really want some help <G> For example, when *you* run this program what is the result you are getting and what is the result you were expecting? To me, both nat_sort() and sort() both work perfectly well in the example you gave us so I don't see what your problem is. -- Derek Parnell Melbourne, Australia Skype name: derek.j.parnell
7. Re: Sort problem
- Posted by don cole <doncole at pacbell.net> Jun 11, 2007
- 580 views
Derek Parnell wrote: > > don cole wrote: > > > Here' my code very simplified. ... > > Don, > you need to be a bit more helpful if you really want some help <G> > > For example, when *you* run this program what is the result you are getting > and what is the result you were expecting? > > To me, both nat_sort() and sort() both work perfectly well in the example you > gave us so I don't see what your problem is. > > -- > Derek Parnell > Melbourne, Australia > Skype name: derek.j.parnell Hello Derek and all others, This program and data is too lengthy to post here. I will try to cut it down to the important parts. db[1]={"0888","2485","1476"} db[2]={"A1071","A3108","A3011"} db[3]={"D0970","D1078","D2530","D1233"} --Really db[1]= -- db[1][1]=number -- db[1][2]=title -- db[1][3]=prod co. -- db[1][4]=cost -- etc etc.. --this is all saved and loaded in a binary way using fn = open(file_name, "wb") fn = open(file_name, "rb") --I don't think ther is any problem in this because I am loading and reading the --right files only the sort is messed up --the way I read results after sort setText(aETS[x],length(db[x])) --the number of files in the data base setText(bETS[x],db[x][1][1]) --the first record setText(cETS[x],db[x][$][1]) --the last record num of records first record last record --- -- ------- ----- ------ ---- ------ 2514 0888 5105 -- this seems ok now 2527 A1121 A0985 -- this is wrong 3164 D1000 D0999 -- this is wrong Don Cole
8. Re: Sort problem
- Posted by Derek Parnell <ddparnell at bigpond.com> Jun 11, 2007
- 624 views
don cole wrote: > > This program and data is too lengthy to post here. > > I will try to cut it down to the important parts. However you have cut too much out. I can't understand what you are saying by the example below. > db[1]={"0888","2485","1476"} > db[2]={"A1071","A3108","A3011"} > db[3]={"D0970","D1078","D2530","D1233"} > > --Really db[1]= > -- db[1][1]=number > -- db[1][2]=title > -- db[1][3]=prod co. > -- db[1][4]=cost > -- etc etc.. By this are you saying that db[1][1] which is "0888" is the number, and db[1][2] which is "2485" is the title, and db[1][3] which is "1476" is the prod co. ??? but you say that db[1][4] is the cost but there is no db[1][4]!? Or are you saying that the first record is really {"0888", "A1071", "D0970"} ... but that can't be right either because there is still no 'cost' field. I just don't get what you are trying to say. But regardless of that, can you give us a sample of the PRESORTED sequence and the sequence after YOU sort it? This should take just three lines of code ... for example: constant presorted = {"A1071", "A3108", "A3011"} ? presorted ? sort(presorted) -- {"A1071", "A3011", "A3108" > --this is all saved and loaded in a binary way using > fn = open(file_name, "wb") > fn = open(file_name, "rb") > > --I don't think ther is any problem in this because I am loading > and reading the > --right files only the sort is messed up > > --the way I read results after sort What is the source code of your sort? > > setText(aETS[x],length(db[x])) --the number of files in the data base > setText(bETS[x],db[x][1][1]) --the first record > setText(cETS[x],db[x][$][1]) --the last record > > num of records first record last record > --- -- ------- ----- ------ ---- ------ > 2514 0888 5105 -- this seems ok now > 2527 A1121 A0985 -- this is wrong > 3164 D1000 D0999 -- this is wrong These values have nothing to do with the example data you just gave us. How can we help if you don't tell us what exactly what you have, what you are getting and what you expected? In short, the example you gave us doesn't make sense to me. -- Derek Parnell Melbourne, Australia Skype name: derek.j.parnell
9. Re: Sort problem
- Posted by don cole <doncole at pacbell.net> Jun 12, 2007
- 615 views
ok for this example: db[1][1][1]="3409"--movie number db[1][1][2]="hello dolly"--title db[1][1][3]=".50"--cost db[1][2][1]="2395" db[1][2][2]="matrix" db[1][2][3]="1.25" db[1][3][1]="1920" db[1][3][2]="boomtown" db[1][3][3]=".50" db[2][1][1]="A2009"--movie number db[2][1][2]="debbie does dallas again"--title db[2][1][3]="12.00"--cost db[2][2][1]="A1060" db[2][2][2]="Caligula db[2][2][3]="1.25" db[2][3][1]="A1150" db[2][3][2]="girls gone wild 17" db[2][3][3]="2" db[3][1][1]="D2019"--movie number db[3][1][2]="the unforgiven"--title db[3][1][3]="2.00"--cost db[3][2][1]="D1066" db[3][2][2]="spiderman" db[3][2][3]="1.25" db[3][3][1]="D1256" db[3][3][2]="thug" db[3][3][3]=".50" This is a shortened group to show the way it is set up not REAL data. Notice there are 3 groups reg, adult and dvd.In reality there are six groups openreg,openadult,opendvd,soldreg,soldadult,and solddvsd. Each field has a movie number, tite and price. In reality there are 9 fields for reg and adult and 11 fields for dvds. In this demo there are 3 movies in each db where as in reality there are many,many more. Notice also in each movie the movie number is #1 as per the sort documentation. My windows set up number first last of movie movie movies number number ------ ------ ------ reg EditText1 EditText2 EditText3 adult EditText4 EditText5 EditText6 dvd EditText7 EditText8 EditText9 setText(EditText1,length(db[1]) setText(EditText2,db[1][1][1]) setText(EditText3,db[1][$][1]) setText(EditText4,length(db[2]) setText(EditText5,db[2[1][1]) setText(EditText6,db[2][$][1]) setText(EditText7,length(db[3]) setText(EditText8,db[3][1][1]) setText(EditText9,db[3][$][1]) Sorting: for x= 1 to 6 do db[x]=sort(db[x]) end for I have never tried sorting the DEMO data that I have shown here. I don't see any point in it. After sorting using the REAL data I get: number first last of movie movie movies number number ------ ------ ------ reg 271 3119 4907 adult 24 A4730 A5582 dvd 330 D1031 D4234 soldreg 2514 0888 5150 soldadult 2527 A1121 A0985 solddvd 3164 D1000 D0999 I expect all this information is correct except for soldadult and solddvd. If this is not enough information maybe I could email you the whole thing. Don Cole
10. Re: Sort problem
- Posted by CChris <christian.cuvier at agriculture.gouv.fr> Jun 12, 2007
- 570 views
don cole wrote: > > ok for this example: > > db[1][1][1]="3409"--movie number > db[1][1][2]="hello dolly"--title > db[1][1][3]=".50"--cost > db[1][2][1]="2395" > db[1][2][2]="matrix" > db[1][2][3]="1.25" > db[1][3][1]="1920" > db[1][3][2]="boomtown" > db[1][3][3]=".50" > > db[2][1][1]="A2009"--movie number > db[2][1][2]="debbie does dallas again"--title > db[2][1][3]="12.00"--cost > db[2][2][1]="A1060" > db[2][2][2]="Caligula > db[2][2][3]="1.25" > db[2][3][1]="A1150" > db[2][3][2]="girls gone wild 17" > db[2][3][3]="2" > > db[3][1][1]="D2019"--movie number > db[3][1][2]="the unforgiven"--title > db[3][1][3]="2.00"--cost > db[3][2][1]="D1066" > db[3][2][2]="spiderman" > db[3][2][3]="1.25" > db[3][3][1]="D1256" > db[3][3][2]="thug" > db[3][3][3]=".50" > > This is a shortened group to show the way it is set up not REAL data. > > Notice there are 3 groups reg, adult and dvd.In reality there are six groups > openreg,openadult,opendvd,soldreg,soldadult,and solddvsd. > > Each field has a movie number, tite and price. In reality there are 9 fields > for reg > and adult and 11 fields for dvds. > > In this demo there are 3 movies in each db where as in reality there are > many,many > more. > > Notice also in each movie the movie number is #1 as per the sort > documentation. > > My windows set up > > number first last > of movie movie > movies number number > ------ ------ ------ > > reg EditText1 EditText2 EditText3 > > adult EditText4 EditText5 EditText6 > > dvd EditText7 EditText8 EditText9 > > setText(EditText1,length(db[1]) > setText(EditText2,db[1][1][1]) > setText(EditText3,db[1][$][1]) > > setText(EditText4,length(db[2]) > setText(EditText5,db[2[1][1]) > setText(EditText6,db[2][$][1]) > > setText(EditText7,length(db[3]) > setText(EditText8,db[3][1][1]) > setText(EditText9,db[3][$][1]) > > Sorting: > > for x= 1 to 6 do > db[x]=sort(db[x]) > end for > > I have never tried sorting the DEMO data that I have shown here. > I don't see any point in it. > > After sorting using the REAL data I get: > > number first last > of movie movie > movies number number > ------ ------ ------ > reg 271 3119 4907 > > adult 24 A4730 A5582 > > dvd 330 D1031 D4234 > > soldreg 2514 0888 5150 > > soldadult 2527 A1121 A0985 > > solddvd 3164 D1000 D0999 > > I expect all this information is correct except for soldadult and solddvd. > > > If this is not enough information maybe I could email you the whole thing. > > Don Cole I'd expect some sort of corruption occurred in your actual dataset, at least in the groups with unexpected results. More precisely, I suspect some records don't have the same length. Could you please check the actual individual entry with movie number "D1000" in the solddvd group, and see if it has the same length as the one with number "D0999"? I expect it to be shorter. At this point, there may be extra data in the "last" item or missing data in the "first" one just as well. Or wrong labelling, causing a dvd to be in a nondvd category or vice versa. CChris
11. Re: Sort problem
- Posted by Pete Lomax <petelomax at blueyonder.co.uk> Jun 12, 2007
- 600 views
don cole wrote: > Sorting: > > for x= 1 to 6 do > db[x]=sort(db[x]) > end for > > I have never tried sorting the DEMO data that I have shown here. > I don't see any point in it. Sigh. That would be our job, right? It really does seem that you are hell-bent on making it as difficult as possible for anyone to help you... > > After sorting using the REAL data I get: > > number first last > of movie movie > movies number number > ------ ------ ------ > reg 271 3119 4907 > > adult 24 A4730 A5582 > > dvd 330 D1031 D4234 > > soldreg 2514 0888 5150 > > soldadult 2527 A1121 A0985 > > solddvd 3164 D1000 D0999 > OK, so what you do here is this:
sequence dbg dbg={db[5][1],db[5][$]} ?dbg ?sort(dbg)
You may want to use pretty_print or similar, and you may want to try the same with [6]. Can you see why I suggest this? Just to be clear that was not a rhetorical question: Can you see why I suggest this? >In reality there are 9 fields for reg and adult and 11 fields for dvds. Any my GUESS would be that you have {{'A',"1121"},{'A',"985"}} or similar instead of the {"A1121","A0985"} that you claim. Regards, Pete
12. Re: Sort problem
- Posted by don cole <doncole at pacbell.net> Jun 12, 2007
- 577 views
CChris wrote: > > I'd expect some sort of corruption occurred in your actual dataset, at least > in the groups with unexpected results. More precisely, I suspect some records > don't have the same length. > > Could you please check the actual individual entry with movie number "D1000" > in the solddvd group, and see if it has the same length as the one with > number "D0999"? I expect it to be shorter. At this point, there may be extra > data in the "last" item or missing data in the "first" one just as well. > Or wrong labelling, causing a dvd to be in a nondvd category or vice versa. > > CChris Thanks to CChris and Pete, I think you are both right about my data being corrupt. That's what got me stared on this in the first place. What I didn't show you was my complete window which is: number first last movnum db letter history of movie movie length length length movies number number errors errors errors errors ------ ------ ------ ------ ------ ------ ------ reg 271 3119 4907 0 0 0 0 adult 24 A4730 A5582 0 0 0 0 dvd 330 D1031 D4234 0 0 0 0 soldreg 2514 0888 5150 0 0 0 0 soldadult 2527 A1121 A0985 0 0 0 0 solddvd 3164 D1000 D0999 0 0 0 0 Let me go back and check my error checking and try Pete's experiment. Don Cole
13. Re: Sort problem
- Posted by don cole <doncole at pacbell.net> Jun 13, 2007
- 604 views
To everybody who tried to help, I want to thank you. I copied and brought home from work all my databases and now everything seems to sort fine. So I don't know, the error must have been do to database corruption. Don Cole