どれだけ引けば・・・

by narutohyper
スゴイ自販機でコンプリートするまでに、どんだけ引かないといけないのか?

抽選券とフィギュアの出る確立を2:1と仮定すると・・・

@author narutohyper
♥8 | Line 56 | Modified 2011-02-14 18:52:16 | MIT License
play

ActionScript3 source code

/**
 * Copyright narutohyper ( http://wonderfl.net/user/narutohyper )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/weHd
 */

package
{
    import flash.display.Sprite;
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;
    import flash.text.TextFormat;
    
    /**
     * スゴイ自販機でコンプリートするまでに、どんだけ引かないといけないのか?
     *
     * 抽選券とフィギュアの出る確立を2:1と仮定すると・・・
     *
     * @author narutohyper
     */
    public class CocaCola extends Sprite
    {
        public function CocaCola()
        {
            var counters:Array=[]
            var i:int = 0;
            var count:int = 91
            for (i = 0; i < count; i++)
            {
                counters[i]=0
            }
            
            var check:uint = 0;
            var random:int
            var counter:int = 0
            while (check < 91) {
                random=Math.floor(Math.random() * 3)
                if(!random) {
                    //フィギュア
                    random=Math.floor(Math.random() * 90)+1
                    counters[random]++
                    if (counters[random]==1) {
                        check++
                    }
                } else {
                    //抽選券
                    counters[0]++
                    if (counters[0]==1) {
                        check++
                    }
                }
                counter++;
            }
            
            for (i = 1; i < count; i++)
            {
                var n:int = 0;
                for (n = 0; n < counters[i]; n++)
                {
                    graphics.beginFill(i < 70?0xCC0000:0x009900);
                    graphics.drawRect(n * 4+20, i * 4, 3, 3);
                }
            }
            
            var txt:TextField = new TextField();
            txt.autoSize = TextFieldAutoSize.LEFT;
            var fmt:TextFormat = new TextFormat(null, 12, 0);
            txt.defaultTextFormat = fmt
            txt.text = "Completeまでの道のり\n抽選回数:" + counter + "回\n抽選券:" + counters[0] + "枚"
            this.addChild(txt)
            txt.x = 20;
            txt.y = 370
            
            
        }
        
    }

}