% 確率をシミュレーションにより求める
% n人の中に誕生日が同じ人がいる場合とすべて異なる場合を数える

%n = 23;
n = 50;

same = 0;
diff = 0;

for iteration=1:1000
    birthday = ceil(365*rand(1,n));
    found = 0;
    for k=1:n
        if ismember(birthday(k), birthday(k+1:n))
            found = 1;
            break;
        end
    end
    if found
        same = same + 1;
    else
        diff = diff + 1;
    end
end

fprintf("  %2d 人     同じ人がいる %d 回     すべて異なる %d 回\n", n, same, diff);
