Created
September 7, 2013 03:02
-
-
Save chuckwagoncomputing/6472460 to your computer and use it in GitHub Desktop.
Random Number Occurence Counter
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
#!/usr/bin/env ruby | |
$one = 0 | |
$two = 0 | |
$three = 0 | |
$four = 0 | |
$five = 0 | |
$six = 0 | |
$seven = 0 | |
$eight = 0 | |
$nine = 0 | |
ARGV[0].to_i.times do | |
num = rand(1..9) | |
if num == 1 | |
$one += 1 | |
elsif num == 2 | |
$two += 1 | |
elsif num == 3 | |
$three += 1 | |
elsif num == 4 | |
$four += 1 | |
elsif num == 5 | |
$five += 1 | |
elsif num == 6 | |
$six += 1 | |
elsif num == 7 | |
$seven += 1 | |
elsif num == 8 | |
$eight += 1 | |
elsif num == 9 | |
$nine += 1 | |
else | |
puts "fatal error" | |
end | |
end | |
puts "one: #{$one}" | |
puts "two: #{$two}" | |
puts "three: #{$three}" | |
puts "four: #{$four}" | |
puts "five: #{$five}" | |
puts "six: #{$six}" | |
puts "seven: #{$seven}" | |
puts "eight: #{$eight}" | |
puts "nine: #{$nine}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment