Created
June 13, 2013 15:07
-
-
Save tokoroten/ca89303a8cbce437c957 to your computer and use it in GitHub Desktop.
アミダクジは公平な仕組みなのかの検証。
縦線が10本のアミダクジでは、横線を150本程度ひかないと公平なアミダクジにはなりませんでした。
それ以下の場合、当たりがある場所の真上を選択すると当たり確率が高いです。
This file contains 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
#coding:utf-8 | |
import random | |
def amida_shuffle(line_num, exchange_num): | |
lines = range(line_num) | |
for i in xrange(exchange_num): | |
p = random.randrange(line_num - 1) | |
lines[p], lines[p+1] = lines[p+1], lines[p] | |
return lines | |
def range_shuffle(range_num): | |
lines = range(range_num) | |
random.shuffle(lines) | |
return lines | |
def main(): | |
try_num = 100 | |
line_num = 10 | |
exchange_num = 15 | |
same_count = [0, 0] | |
for i in xrange(try_num): | |
amida_list = amida_shuffle(line_num, exchange_num) | |
shuffle_list = range_shuffle(line_num) | |
for k in xrange(line_num): | |
if amida_list[k] == k: | |
same_count[0] += 1 | |
if shuffle_list[k] == k: | |
same_count[1] += 1 | |
print same_count | |
# [265, 108] | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment