POV-Ray : Newsgroups : povray.off-topic : FizzBuzz : Re: Binary search Server Time
4 Sep 2024 05:17:12 EDT (-0400)
  Re: Binary search  
From: Invisible
Date: 5 Jul 2010 03:58:09
Message: <4c319091$1@news.povray.org>
Slime wrote:
>  > find :: (Ord y) => (x -> y) -> y -> IArray x -> (Int,Int) -> Maybe x
>  > find field target array (base,size)
>  > | size < 0 = error "invalid subrange size"
>  > | size == 0 = Nothing
>  > | size == 1 = if field (array ! base) == target then Just (array !
>  > base) else Nothing
>  > | otherwise =
>  > let size2 = size `div` 2
>  > in find field target array (base, size2) `mappend` find field target
>  > array (base + size2, size - size2)
> 
> I don't know Haskell, but my best guess at understanding this code looks 
> like you're always recursing into both sides, without actually doing the 
> comparison of the center element to the target element.

Oh... my god... >_<



I blame Warp. I was so busy making sure that there's no off-by-one 
errors that I totally forgot to actually, you know, IMPLEMENT THE RIGHT 
ALGORITHM!


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.