Skip to content

Instantly share code, notes, and snippets.

@dkwingsmt
Last active September 19, 2019 14:49
Show Gist options
  • Select an option

  • Save dkwingsmt/1c146ba596d41d6a41a2f1585c23e006 to your computer and use it in GitHub Desktop.

Select an option

Save dkwingsmt/1c146ba596d41d6a41a2f1585c23e006 to your computer and use it in GitHub Desktop.
Random ducks
round=1;suc=1;
while true
if randomDucks()
suc=suc+1;
end
round=round+1;
sprintf('%f (%d/%d)', suc/round, suc, round)
end
function [hasHalf] = randomDucks()
%RANDOMDUCKS 此处显示有关此函数的摘要
% 此处显示详细说明
coords=zeros(4,2);
for i=1:4
while 1
co=rand(1,2)*2-1;
if norm(co) <= 1
coords(i,:)=co;
break;
end
end
end
thetas=cart2pol(coords(:,1), coords(:,2));
sorted=sort(thetas);
hasHalf=max(sorted - [sorted(4)-2*pi; sorted(1:3)])>pi;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment