[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

LOGO-L> Mid-Value of Three Numbers



Hi,

It was nice to get those many replies for solving the mid-value number problem.
 

Generally speaking, the solutions reached so far, were in  3 flavors:

1    Sort the 3 numbers. The second number obtained is the MID. Here's a typical solution (each number is supplied individually):

    to mid :a :b :c
     if :a>:b[op mid :b :a :c]
     if :b>:c[op mid :a :c :b]
     op :b
    end
 

2    Find the maximal of the 3 numbers, remove it, the maximal of the remaining 2 numbers is the MID. A typical program might be this (the
numbers are given in a list):
 

    to mid :lst
     op max (remove (max :lst) :lst)
    end

    to remove :obj :lst
     if emptyp :lst[op []]
     if :obj=first :lst[op bf :lst]
     op fput first :lst (remove :obj bf :lst)
    end

    to max :lst
     op reduce "bigger :lst
    end

    to bigger :a :b
     op ifelse :a>:b[:a][:b]
    end
 

3    One of the solutions sent in, used an arithmetic trick:

    to middle :lst
     if betweenp first :lst bf :lst[op first :lst]
     if betweenp last  :lst bl :lst[op  last :lst]
     op item 2 :lst
    end

    to betweenp :n :lst
     op not (:n - first :lst)*(:n - last :lst) > 0
    end

The above solutions do the job well - each in a different algorithm. I wish to thank all posters.

Regards...

[[Yehuda]]

    _/    _/     _/ _/_/_/_/_/ _/_/_/_/
   _/   _/     _/_/    _/          _/
  _/_/_/     _/  _/   _/        _/
 _/   _/   _/_/_/_/  _/      _/
_/     _/_/      _/ _/     _/_/_/_/

http://www.geocities.com/CollegePark/lab/2276/
e-mail: yehuka@beitberl.ac.il
 



Global SchoolNet Foundation - Linking Kids Around the World!
Copyright GSN - All Rights Reserved - Comments & Questions
Visit GSN's Global Schoolhouse for more exciting learning resources!
Search our Site - Home