Re: Computer language shootout
- Posted by Kenneth Rhodes <ken_rhodes30436 at yahoo.com> Feb 09, 2006
- 537 views
Jason, I noticed in the fasta code: function selectRandom(sequence genelist) -- C version uses binary search, this works better than find(). integer ix, lo, hi atom r r = gen_random(1) lo = 1 hi = length(genelist) if r < genelist[1] then return CODES[1] end if while hi > lo + 1 do ix = floor((hi + lo) / 2) if r < genelist[ix] then hi = ix else lo = ix end if end while return CODES[hi] end function -- selectRandom Can this euphoria code be of use? global function bfind(object x, sequence s) -- does a binary search on a sorted sequence -- returns index location if found, 0 if not -- assumes that sequence s has been sorted prior to this call -- Gabriel Boehme's code -- Earlier Joe Otto's routine is almost identical. integer lo, hi, mid, c lo = 1 hi = length(s) while lo <= hi do mid = floor((lo + hi) / 2) c = compare(x, s[mid]) if c < 0 then -- x < s[mid] hi = mid - 1 elsif c > 0 then -- x > s[mid] lo = mid + 1 else -- x = s[mid] return mid end if end while return 0 end function Ken Rhodes 100% MicroSoft Free SuSE Linux 10.0 No AddWare, SpyWare, or Viruses! Life is Good