At 22:21 14.8.1998 +0300, Yehuda wrote:
> Hi, I have a list of 3 numbers. How do I extract from them the
>middle-valued number?
Hi,
A nice small problem.
I tried to use just testing without changing the order of items.
My program uses 2.6666... tests in average to get the middle value:
to mid :li
op if item 2 :li < first :li ~
[if last :li < item 2 :li ~
[item 2 :li] ~
[if last :li < first :li ~
[last :li] ~
[first :li]]] ~
[if last :li < first :li ~
[first :li] ~
[if last :li < item 2 :li ~
[last :li] ~
[item 2 :li]]]
end
In MSW Logo and MicroWorlds you have to write IFELSE instead of IF and
ommit the ~ character at the end of lines.
I attach also a graphical representation (maybe more clear).
Peter Tomcsanyi tomcsany@internet.sk
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