๋นจ๊ฐ•๐Ÿ’Ž์—ด๋‹ค๐Ÿบ์›ํ•˜๋‹ค

4510 ๋‹จ์–ด PHP

์ถœ์ฒ˜

<?php
$beer = "ใƒ“ใƒผใƒซ";
$ruby = "ใƒซใƒ“ใƒผ";
$num = 10000;
for($j=0;$j<100;$j++) {
    $count = 0;
    for ($i = 0; $i < $num; $i++) {
        if (mt_str_shuffle($ruby) === $beer) $count++;
    }

    echo $count / $num;
    echo "\n";
}

/**
 * @param  string $str  ๅ…ฅๅŠ›ใ•ใ‚ŒใŸๆ–‡ๅญ—ๅˆ—ใ‚’
 * @return string $str2 ใ‚ทใƒฃใƒƒใƒ•ใƒซใ—ใฆ่ฟ”ใ™
 */
function mt_str_shuffle(string $str):string{
    $num = mb_strlen($str);
    $arr = array_fill(0,$num,false);
    $str2 = "";
    for($i=0;$i<$num;$i++){
        do{
            $rand = mt_rand(0,$num-1);
        }while($arr[$rand]);
        $str2 .= mb_substr($str,$rand,1);
        $arr[$rand] = true;
    }
    return $str2;
}

๊ฒฐ์‹ค



๊ฒฐ๋ก 


๐Ÿบ๋งˆ์‹œ๋‹ค

์ข‹์€ ์›นํŽ˜์ด์ง€ ์ฆ๊ฒจ์ฐพ๊ธฐ