Skip to content

Instantly share code, notes, and snippets.

@greenbagels
Last active June 29, 2017 21:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save greenbagels/756a8af8c1773b7b7da04314cc82d001 to your computer and use it in GitHub Desktop.
Save greenbagels/756a8af8c1773b7b7da04314cc82d001 to your computer and use it in GitHub Desktop.
simulates dice rolling
#!/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