clear;

%rng(1);

a = 1;
b = 1;
heads = 0;
truth = 0.4;

x = linspace(0, 1, 1000)';

ii = 1;
while 1
  post_a = a + heads;
  post_b = b + ii - heads;
  
  plot(x, betapdf(x, post_a, post_b));
  xlim([0 1]);
  
  pause;
  
  
  if rand() < truth
    heads = heads + 1;
    fprintf('heads\n');
  else
    fprintf('tails\n');
  end

  
  ii = ii + 1;
end