Created
July 9, 2012 06:46
-
-
Save VienosNotes/3074664 to your computer and use it in GitHub Desktop.
コインを10枚振った時のすべての組み合わせを、表の出た回数別に分けて出力する
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
| use v6; | |
| my @count = 0 xx 10; | |
| my @tmp; | |
| my $i; | |
| for 0..1023 -> $n { | |
| $i = 0; | |
| @tmp = $n.fmt("%010b").comb; | |
| for @tmp { | |
| if $_ == 1 { | |
| $i++; | |
| } | |
| } | |
| @count[$i]++; | |
| } | |
| for 0..^@count.elems { | |
| say $_, " -> ", @count[$_], " : ", @count[$_] / 1024; | |
| } | |
| # 実行結果 | |
| # 0 -> 1 : 0.000977 | |
| # 1 -> 10 : 0.009766 | |
| # 2 -> 45 : 0.043945 | |
| # 3 -> 120 : 0.117188 | |
| # 4 -> 210 : 0.205078 | |
| # 5 -> 252 : 0.246094 | |
| # 6 -> 210 : 0.205078 | |
| # 7 -> 120 : 0.117188 | |
| # 8 -> 45 : 0.043945 | |
| # 9 -> 10 : 0.009766 | |
| # 10 -> 1 : 0.000977 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment