[REBOL] Re: More on expressions
From: joel:neely:fedex at: 2-Feb-2003 15:14
Hi, Sunanda,
... proving once again that notation can be too much fun ... ;-)
Thanks for the correction of my prefix-vs-infix blunder! I'm so used
to thinking of the operations in question as first-class operators
(comparable to + - * and /) instead of programming language procedures
that I typed what I was thinking instead of what I should have been
writing!
Now on to the real issue...
Skip
the
rest
of
this
email
for
those
still
playing
with
the
puzzle
...
[SunandaDH--aol--com] wrote:
> Joel,
>
> Spoiler on Joel's solution below:
> .
> ..
> ...
> .....
> ......
> .....
> ....
> ...
> ..
> .
>
>
> max (min a b) (min (max a b) c)
>
I'm puzzled that you said it didn't work for you. Here's a small
torture test that shows the right result every time:
median3: func [a b c] [max (min a b) (min (max a b) c)]
loop 40 [
trio: random [1 2 3]
print [mold trio tab median3 trio/1 trio/2 trio/3]
]
... which produces results resembling ...
[2 1 3] 2
[2 1 3] 2
[3 1 2] 2
[3 2 1] 2
[1 3 2] 2
[3 1 2] 2
[3 1 2] 2
[1 2 3] 2
[1 3 2] 2
...
[2 3 1] 2
[2 3 1] 2
[2 1 3] 2
[1 3 2] 2
... and a non-numeric variation ...
loop 40 [
trio: random ["1-A" "1-B" "1-C"]
print [mold trio tab median3 trio/1 trio/2 trio/3]
]
... which produces results resembling ...
["1-B" "1-C" "1-A"] 1-B
["1-C" "1-B" "1-A"] 1-B
["1-C" "1-A" "1-B"] 1-B
["1-A" "1-C" "1-B"] 1-B
...
["1-B" "1-A" "1-C"] 1-B
["1-A" "1-B" "1-C"] 1-B
["1-B" "1-C" "1-A"] 1-B
["1-A" "1-B" "1-C"] 1-B
Can you reproduce the problem using the above code?
-jn-