1. sorting questing

I have a list of words that I want to sort by word length.
The longest words first, down to the shortest word.
Do I make another sequence that holds the word length,
then sort that? If so, then how to relate the two lists?
Its probably a simple algorithm, but its been a hard week
and I can't get it to work out.
JOHN

new topic     » topic index » view message » categorize

2. Re: sorting questing

On Fri, 28 Apr 2000 20:20:48 +0100, John McAdam wrote:

>I have a list of words that I want to sort by word length.
>The longest words first, down to the shortest word.
>Do I make another sequence that holds the word length,
>then sort that? If so, then how to relate the two lists?
>Its probably a simple algorithm, but its been a hard week
>and I can't get it to work out.

One possible solution would be to 'prepend' the length of each sequence
element to each sequence element (so each element is like { 4, "word" } )
then run that through 'sort', then 'reverse' it.

-- Brian

new topic     » goto parent     » topic index » view message » categorize

3. Re: sorting questing

----- Original Message -----
From: "John McAdam" <john.mcadam at MAIL.TELEPAC.PT>
To: <EUPHORIA at LISTSERV.MUOHIO.EDU>
Sent: Friday, April 28, 2000 2:20 PM
Subject: sorting questing


> I have a list of words that I want to sort by word length.
> The longest words first, down to the shortest word.
> Do I make another sequence that holds the word length,
> then sort that? If so, then how to relate the two lists?
> Its probably a simple algorithm, but its been a hard week
> and I can't get it to work out.
> JOHN

Aren't there sorting routines on the contributors page?
Kat

new topic     » goto parent     » topic index » view message » categorize

4. Re: sorting questing

Maybe you can attach a "length indicator," such as "000x", where x is the
value of the length of the item.

sort that list.

remove the indicator.

For example:

For the following list
    { "one, two, three, four, five, six, seventeen, twenty, etc" }

the indicator list would be


en","0006twenty","0003etc"}

You would sort that... which should be a natural for the built-in sorter...

Then go back and remove the indicator items...

You know...
    for t= 1 to length(list)
        list[t] = list[t][5..length(list[t])]
    end for

The key is, make the indicators the same length!
The benefit is, you only have to sort one list.

...or something like that.

-ck

----- Original Message -----
From: John McAdam <john.mcadam at MAIL.TELEPAC.PT>
To: <EUPHORIA at LISTSERV.MUOHIO.EDU>
Sent: Friday, April 28, 2000 2:20 PM
Subject: sorting questing


> I have a list of words that I want to sort by word length.
> The longest words first, down to the shortest word.
> Do I make another sequence that holds the word length,
> then sort that? If so, then how to relate the two lists?
> Its probably a simple algorithm, but its been a hard week
> and I can't get it to work out.
> JOHN
>

new topic     » goto parent     » topic index » view message » categorize

5. Re: sorting questing

Use my INDEX SORT from the contributions page of the rds site.

Pete King, Spectre Software.

-----Original Message-----
From: John McAdam <john.mcadam at MAIL.TELEPAC.PT>
To: EUPHORIA at LISTSERV.MUOHIO.EDU <EUPHORIA at LISTSERV.MUOHIO.EDU>
Date: Friday, April 28, 2000 8:23 PM
Subject: sorting questing


>I have a list of words that I want to sort by word length.
>The longest words first, down to the shortest word.
>Do I make another sequence that holds the word length,
>then sort that? If so, then how to relate the two lists?
>Its probably a simple algorithm, but its been a hard week
>and I can't get it to work out.
>JOHN
>

new topic     » goto parent     » topic index » view message » categorize

6. Re: sorting questing

John McAdam wrote:

> I have a list of words that I want to sort
> by word length.

How about:

  include sort.e
  sequence q
  q = { "z", "foo", "bar", "ba", "grill", "za" }

  -- attach the negative length
  for i = 1 to length( q ) do
      q[i] = { -length(q[i]), q[i] }
  end for

  -- sort
  q = sort( q )

  -- display; element #2 is the text
  for i = 1 to length( q ) do
      puts( 1, q[i][2] & '\n' )
  end for

-- David Cuny

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu