Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: More on expressions

From: sunandadh:aol at: 2-Feb-2003 16:55

Joel:
> 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:
Sorry for that. My mistake. I cut and pasted the code incorrectly into my torture test. When pasted straight, it does indeed produce the median every time. By way of compensation or entertainment, here's another slightly demented way of doing it. The first three additions must give us Median + twice Maximum. So a quick subtraction of twice the maximum, and the job is done. (max a b) + (max b c) + (max a c) - (2 * (max a max b c)) Of course this only works on the original spec -- numbers -- but it's better than your solution because it uses less min's.....So this is *the* solution to remember if challenged to do it without using if, sort, first, second, third, either or min. One day that might save your life. To make it work with non-numbers, tweak it into inserting and removing items in a block, Sunanda Whose hoping his code examples will win him the first ever "Rebol without a clue" award.