In general the solutions I like will scale easily. Meaning what would it take in each solution if the problem changed slightly in the future (which in practice does way too often). Like what if now there was five numbers or 50. Which solutions are easy to adapt and which are not? Yehuda wrote: > > 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 > -- =============================================================== George Mills email: mills@softronix.com http://www.softronix.com The www page contains some very powerful educational software. Our single most important investment is our kids. --------------------------------------------------------------- Please post messages to the Logo forum to logo-l@gsn.org. Mail questions about the list administration to logofdn@gsn.org. To unsubscribe send unsubscribe logo-l to majordomo@gsn.org.
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