program Test;

uses Use32;

const
  Taille = 4;

const
  vec : array[0..Taille-1] of real
      = ( 0.4829629131445341,  0.8365163037378079,
          0.2241438680420134,  0.1294095225512604 );

const
  n = 8;

var
  bbest : integer;
  best  : integer;
  nbest : integer;
  ka    : array[0..Taille-1] of integer;
  k, i  : integer;
  a, b  : integer;

function n_bits( x : integer ) : integer;
var
  m, c, d : integer;
begin
  c := 0;
  d := 7;

  m := $80000000;
  while (m <> 0) and (x and m = 0) do m := m shr 1;

  while (m <> 0) and (d > 0) do
  begin
    if x and m <> 0 then inc(c);
    dec(d);
    m := m shr 1;
  end;

  n_bits := c;
end;


begin
  bbest := 0;
  nbest := 32;
  best  := 0;

  for k := 1 to (1 shl n)-1 do
  begin
    a := 0;
    for i := 0 to Taille-1 do a := a or Trunc( (1 shl 16)*vec[i]*k );

    b := n_bits(a);
    if b < nbest then
      begin
        bbest := a;
        nbest := b;
        best  := k;
      end;
  end;

  Writeln('best = ',best,', ',bbest,', ',nbest,' bits' );
end.
