It has been a while since my last Friday puzzle, but I ran across something yesterday that I thought would be an excellent little coding challenge. Even better, this one I guarantee shouldn't take you more than 5 minutes. Honest!
Your challenge this week is to implement a common RPG mechanism involving die rolls. For those of you who aren't gaming nerds, a typical part of these games is to roll a die, or multiple dice, to see if you succeed at some particular task. Because this is used so often, a shorthand way of representing what you should roll is used. So for example, to roll a typical six sided die twice, you would see: 2d6. To roll one twelve sided die once, it would be 1d12. Many times a bonus, or penalty, is applied to roll. So for example, you have a sword that does 2d6 damage, but because it has the Blessing of Awesome-itude, you get to add two to the roll. That would be designated as 2d6+2. On the flip side, you have a wand that does 3d12 damage (pretty impressive), but the creator was drunk when she created it so you get a penalty of minus four: 3d12-4.
Your task is simple. Write a program that accepts the input, parses it, and returns the result. It should gracefully handle errors in the input. For brownie points, return the total as well as what each individual die roll was. You can solve this in any language, but please remember to post a Pastebin or Gist link for server-side code. For client-side code use JSBin (or something similar).
And hey - I'll give you a prize too. How about a 30 gig USB card from Adobe? It is the size of a business card so I can slip it in the mail - but only for folks in America. Because - um - I'm cheap.

Archived Comments
Responses are logged to console so open it to see results...
http://jsfiddle.net/seancoy...
Nice. To be picky, I don't like the outputs in the rollDice func. It should be returning results to the caller instead.
Yeah, not exactly "production ready" code.
Btw - no offense made. In general, I like to nit pick the submissions. Totally arbitrary of course. ;)
None taken at all. Was fun to write. Hadn't generated a random number, as simple as it is, in JS before. Just never had a need I guess.
Super quick and dirty
https://gist.github.com/dan...
Nice - any reason you didn't use JSBin? (I ask because I keep going back and forth on whether I like them. I find them awkward at times.
Oh - I see you called it Node Roller - so the assumption was back end perhaps?
Yeah, quick and dirty so I just went with the back-end.
I'm in the same boat as you when it comes to JSBin...cool mostly but akward
Here is my attempt it is very ugly and doesn't handle a case of the minimum number of sides a dice can have i assumed that number of sides and number of dice had to be more then zero
I forgot the link
http://jsbin.com/mofuqina/9...
Quick and dirty in Groovy: https://gist.github.com/s99...
I wasn't sure if a roll result could be negative (e.g. 1d6-20), so I just let it happen.
Fascinating. I learned Groovy years ago, but haven't used it - I forget how nice it is.
I'm still very much in the early stages of learning Groovy (read: that code could probably be way better), but it's been a blast so far! Really fun language to code in.
Some regular expression fun with JavaScript. I bet there are some edge cases it misses, but it works pretty well.
http://jsbin.com/bogolewa/5...
http://pastebin.com/Kmwb3dMZ
Can't wait for the warm weather ^^;