Created
March 8, 2016 05:51
-
-
Save nisei/141926a9ab4b4c817007 to your computer and use it in GitHub Desktop.
ruby easyLottery.rb [大当たり確率(1/n)] [大当たり回数] example: $ ruby easyLottery.rb 300 10 (1/300の大当たり確率を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
| def main() | |
| prob = ARGV[0].to_i | |
| hit = ARGV[1].to_i | |
| random = Random.new | |
| begin | |
| if !prob || prob == 0 || !hit || hit == 0 then | |
| raise "bad argument..." | |
| end | |
| # exec | |
| (1..hit).each do | |
| count = 0 | |
| graph = "" | |
| loop do | |
| count = count + 1 | |
| lot = random.rand(1..prob).to_i | |
| if lot == 1 then | |
| break | |
| end | |
| end | |
| division = count.div(100) + 1 | |
| (1..division).each do | |
| graph << "■" | |
| end | |
| display_count = sprintf("% 5d", count) | |
| puts "#{display_count}: #{graph}" | |
| end | |
| rescue => e | |
| puts e.message | |
| end | |
| end | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment