Last active
December 22, 2015 05:29
-
-
Save richardkazuomiller/6424412 to your computer and use it in GitHub Desktop.
コンプレするまでももクロマンを何個買わないといけないか
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
var success_count = 0; | |
var trial_count = 1000000; //とりあえず1000000回繰り返す | |
var unique_sticker_count = 22; //22種のシール | |
var purchase_count = 40; //40枚買った | |
for(var i = 0; i < trial_count; i++){ | |
var collection = []; | |
for(var j = 0; j < purchase_count; j++){ | |
collection.push(Math.floor(Math.random()*unique_sticker_count)); | |
} | |
var unique_collection = []; | |
for(var j = 0; j < collection.length; j++){ | |
var sticker = collection[j]; | |
if(unique_collection.indexOf(sticker) == -1){ | |
unique_collection.push(sticker); | |
} | |
} | |
if(unique_collection.length == unique_sticker_count){ | |
success_count++; | |
} | |
} | |
console.log('シミュレーションの数:',success_count); | |
console.log('成功回数:',success_count); | |
console.log('成功確率:',((success_count/trial_count)*100+'%')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
このコードだと「全部のシールが均等の確率で出現する」っていう前提に立ってるから、実際にはもっと確率は低いかもしれないし、逆にもっと高いかもしれないね。
一箱にバラけるように出荷されてたらコンプできる確率は高くなるし、逆にシールの出現確率に勾配がつけてあるともっと低くなりそうだね。