Last active
September 19, 2019 14:49
-
-
Save dkwingsmt/1c146ba596d41d6a41a2f1585c23e006 to your computer and use it in GitHub Desktop.
Random ducks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| round=1;suc=1; | |
| while true | |
| if randomDucks() | |
| suc=suc+1; | |
| end | |
| round=round+1; | |
| sprintf('%f (%d/%d)', suc/round, suc, round) | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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