wu :: forums
« wu :: forums - Set of Three Sort »

Welcome, Guest. Please Login or Register.
Mar 28th, 2024, 12:29pm

RIDDLES SITE WRITE MATH! Home Home Help Help Search Search Members Members Login Login Register Register
   wu :: forums
   riddles
   cs
(Moderators: ThudnBlunder, Grimbal, Eigenray, SMQ, Icarus, towr, william wu)
   Set of Three Sort
« Previous topic | Next topic »
Pages: 1  Reply Reply Notify of replies Notify of replies Send Topic Send Topic Print Print
   Author  Topic: Set of Three Sort  (Read 1587 times)
Sir Col
Uberpuzzler
*****




impudens simia et macrologus profundus fabulae

   
WWW

Gender: male
Posts: 1825
Set of Three Sort  
« on: Feb 2nd, 2005, 1:31pm »
Quote Quote Modify Modify

S is a set of unsorted values, {a,b,c}, not necessarily distinct.
Let x=minimum value, y=median value, and z=maximum value.
 
Develop "efficient" algorithms to find,
(i) x
(ii) y
(iii) x and z
(iv) x and y
(v) x, y, and z
IP Logged

mathschallenge.net / projecteuler.net
towr
wu::riddles Moderator
Uberpuzzler
*****



Some people are average, some are just mean.

   


Gender: male
Posts: 13730
Re: Set of Three Sort  
« Reply #1 on: Feb 2nd, 2005, 2:32pm »
Quote Quote Modify Modify

::
In the case less is asked for, simply trim the branches to accommodate.
 
if (a <= b)
{
  if (a <= c)  
    x=a;
  else /* a > c */
    x=c,y=a;
 
  if (b <= c)
    z=c,y=b;
  else /* b > c */
    z=b;
}
else /* a > b */
{
  if (b <= c)
    x=b;
  else /* b > c */
    x=c,y=b;
 
  if (a <= c)
    z=c,y=a;
  else /* a > c */
    z=a;
}
::
« Last Edit: Feb 2nd, 2005, 2:40pm by towr » IP Logged

Wikipedia, Google, Mathworld, Integer sequence DB
igni_ferroque
Newbie
*





   


Posts: 11
Re: Set of Three Sort  
« Reply #2 on: Feb 4th, 2005, 10:13pm »
Quote Quote Modify Modify

def f(S):
 a, b, c = S
 x, y, z = S
 if a < b:
  x = a
  y = b
 else:
  y = a
  x = b
 if y > c:
  z = y  
  y = c
 if c < x:
  y = x
  x = c
 return (x,y,z)  
IP Logged
Pages: 1  Reply Reply Notify of replies Notify of replies Send Topic Send Topic Print Print

« Previous topic | Next topic »

Powered by YaBB 1 Gold - SP 1.4!
Forum software copyright © 2000-2004 Yet another Bulletin Board