Skip to content

Instantly share code, notes, and snippets.

@nateberkopec
Last active August 29, 2015 14:17
Show Gist options
  • Save nateberkopec/981ec2808f0daf20998f to your computer and use it in GitHub Desktop.
Save nateberkopec/981ec2808f0daf20998f to your computer and use it in GitHub Desktop.
rolldie.rb
#!/usr/bin/env ruby
def roll_die(die_string)
num_of_die, die_type = die_string.split("d").map(&:to_i)
(1..num_of_die).reduce(0) { |s, i| s + rand(die_type) + 1 }
end
puts roll_die(ARGV[0])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment