Last active
June 29, 2017 21:14
-
-
Save greenbagels/756a8af8c1773b7b7da04314cc82d001 to your computer and use it in GitHub Desktop.
simulates dice rolling
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 | |
puts "Enter a dice roll in the form 'PdQ'" | |
input = /(\d+)d(\d+)/.match(gets).values_at(1,2).map!{&:to_i} | |
total = (1..input[0]).map{|idx| rand(input[1]) + 1}.each{|num| puts "You rolled #{num}"}.reduce(:+) | |
puts "You totaled #{total}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment