Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

Sort Problem

 [1/4] from: louisaturk::coxinet::net at: 15-Nov-2001 5:13


Fellow Rebolers, Why won't this script work? Also, is there an easier or better way to do this? Sample data is at the bottom of this message. Important: I want to reverse sort by integer not by string (for example, sort 115 not "115"). I do not want the word strings considered in the sort. I want results as follows: a 115 abraam 73 agaqa 11 abussou 6 agaqe 6 aarwn 5 and so forth. I put the numbers before the words in the script trying to get it to work, but I really want the numbers after the words. I converted the database to objects trying to get a sort by integer, but that is not necessary. I just want a sort routine that will work. Many thanks in advance. Louis REBOL[ Title: "Frequency Sort" Date: 14-Nov-2001 Version: 0.1.6 File: %frequency.r Author: "Louis A. Turk" Email: [louisaturk--eudoramail--com] Language: 'English Purpose: {Sorts each line in a file by the integer number field largest to smallest integer} Comments: {} ] record: context [word: number: none] database: copy [] data: read/lines %gsorted.txt foreach line data [ foreach [gword num] parse line " " [ record: make object! [ number: to-integer num word: to-string gword ] database: join database record ] ] database: sort database /reverse foreach record database [ print join record/number join " " record/word ] { %gsorted.txt contains the following data: a 115 aarwn 5 abaddwn 1 abarh 1 abba 3 abel 4 abia 3 abiaqar 1 abilhnhj 1 abioud 2 abraam 73 abusson 3 abussou 6 agaboj 2 agagein 3 agagete 4 agagh 2 agagonta 1 agagontej 1 agagwsin 1 agaqa 11 agaqaj 2 agaqe 6 agaqh 4 }

 [2/4] from: media:quazart at: 15-Nov-2001 12:46


Hi Dr. Louis, here is my solution! rebol [] data: load %testdata.txt revorder: func [block /local tmp] [ tmp: copy [] foreach [name age] data[ append tmp reduce [age name] ] tmp ] data: to-block data data: revorder data data: sort/skip/reverse data 2 data: revorder data probe data ;----------------------------------- ; --- here you save out or use data as you want!!! ask "" -MAx

 [3/4] from: tomc:darkwing:uoregon at: 15-Nov-2001 10:42


comment: { to benchmarkers only considering the efficency of my effort } foo: parse read/lines %gsorted.txt none bar: copy [] foreach line foo [append/only bar parse line none] sort/compare bar (func[a b][(load a/2) > (load b/2)]) clear foo foreach line bar[append foo rejoin [line/1 " " line/2 newline]] write %gsorted.txt to-string foo On Thu, 15 Nov 2001, Dr. Louis A. Turk wrote:

 [4/4] from: louisaturk:eudoramail at: 15-Nov-2001 12:41


Max, At 12:46 PM 11/15/2001 -0500, you wrote:
>Hi Dr. Louis, >here is my solution!
<<quoted lines omitted: 16>>
>ask "" >-MAx
That works beautifully! Many thanks! I'll be studying your code for a while this morning to try to learn. Rebol and the people on the Rebol list never cease to amaze me. Thanks again! Louis

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted