<?xml version="1.0" encoding="windows-1252"?>
<node id="929384" title="Re: bit-vector &gt; global minimum" created="2011-10-03 13:23:24" updated="2011-10-03 13:23:24">
<type id="11">
note</type>
<author id="171588">
BrowserUk</author>
<data>
<field name="doctext">
&lt;blockquote&gt;&lt;i&gt;&lt;/i&gt;&lt;/blockquote&gt;

&lt;p&gt;This seems too easy, (which usually means I didn't understand the question but...):&lt;code&gt;
#! perl -slw
use strict;

sub minpos {
    my( $v, $s, $e ) = @_;
    my( $n, $min, $o ) = ( 0, 1e30, 0 );
    for my $p ( $s .. $e ) {
        $n += vec( $v, $p, 1 ) ? 1 : -1;
        ( $min, $o ) = ( $n, $p ) if $n &lt; $min;
    }
    return $o;
}

my $vec = pack 'b*', '100101000100';
my( $s, $e ) = ( 1 , 7 );

printf "The minima between %d - %d is at %d\n",
    $s, $e, minpos( $vec, $s, $e );

__END__

C:\test&gt;junk5
The minima between 1 - 7 is at 7

&lt;/code&gt;



&lt;div class="pmsig"&gt;&lt;div class="pmsig-171588"&gt;
&lt;hr /&gt;
&lt;font size=1 &gt;
&lt;div&gt;Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.&lt;/div&gt;
&lt;div&gt;"Science is about questioning the status quo. Questioning authority". &lt;/div&gt;
&lt;div&gt;In the absence of evidence, opinion is indistinguishable from prejudice.&lt;/div&gt;
&lt;/font&gt;

&lt;/div&gt;&lt;/div&gt;</field>
<field name="root_node">
929375</field>
<field name="parent_node">
929375</field>
</data>
</node>
