Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #49142

Tricky sorting

From "WJ" <w_a_x_man@yahoo.com>
Newsgroups comp.lang.forth
Subject Tricky sorting
Date 2016-07-14 06:13 +0000
Organization A noiseless patient Spider
Message-ID <nm7ain$gd2$1@dont-email.me> (permalink)

Show all headers | View raw


You have a list of pairs.  After sorting, if you look only
at the first element of each pair, it should seem that
nothing has changed.

Example.  (Since we're temporarily ignoring the second
elements, they're represented by underscores.)

Before:
[(5,_); (5,_); (2,_); (2,_)]

After:
[(5,_); (5,_); (2,_); (2,_)]

However, the list should be ordered by the second elements,
in so far as that can be done without changing the order of
the first elements.

Before:
[(5,8); (5,0); (2,6); (2,3)]

After:
[(5,0); (5,8); (2,3); (2,6)]



OCaml:

List.sort
  (fun (a,b) (c,d) -> if a=c then compare b d else 0)
  [3,5; 3,1; 3,3; 1,2; 1,7; 1,1; 888,9; 3,42; 3,0] ;;5

 ===>
[(3, 1); (3, 3); (3, 5); (1, 1); (1, 2); (1, 7); (888, 9); (3, 0); (3, 42)]


For this task, or any task not trivially simple, why would one
want to use ANS Forth, a language lacking sorting, lists, arrays,
tuples, and just about everything else?


-- 
Amazon bans book.  After nearly a month on the site, all traces of the book and
its 80 reviews have been removed.
http://jamesfetzer.blogspot.com/2015/11/debunking-sandy-hook-debunkers-5.html
https://www.youtube.com/watch?v=EEl_1HWFRfo

Back to comp.lang.forth | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

Tricky sorting "WJ" <w_a_x_man@yahoo.com> - 2016-07-14 06:13 +0000
  Re: Tricky sorting "WJ" <w_a_x_man@yahoo.com> - 2016-07-14 06:25 +0000
  Re: Tricky sorting "WJ" <w_a_x_man@yahoo.com> - 2016-07-14 06:44 +0000
    Re: Tricky sorting Richard Todd <richard.wesley.todd@gmail.com> - 2016-07-14 14:56 -0700

csiph-web