Re: Best way to...
- Posted by Spock Oct 17, 2010
- 1776 views
irv said...
Thanks for the suggestions. The following code, copied from a javascript version, works and gives a reasonably accurate distance, as well. This takes slightly more than 1 second on my computer, which is acceptable.
SNIP
Hi Irv,
Your code has several math identities to exploit for faster execution, as we all know. Another speed-up could be to sort the 3 shortest distances inside the main loop, eg:
atom km, a, b, c -- a, b, c get initialized with some ridiculous default value before entering the main loop -- at the end of the loop perform this optimized sort if km < c then if km < b then if km < a then c=b b=a a=km else c=b b=km end if else c=km end if end if
More code infrastructure is required but this shows the idea.
Spock