pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

Groovy pastebin - collaborative debugging tool View Help


Posted by Anonymous on Thu 24 Apr 14:04
report abuse | download | new post

  1. import java.util.Random
  2.  
  3. def diceString(String s) {
  4.     s.replaceAll("(\\d+)d(\\d+)", "\$1.d(\$2)")
  5. }
  6.  
  7. class DiceRoller {
  8.  
  9.     def private static generator = new Random()
  10.  
  11.     public static Integer d(Integer self, Integer facets) {
  12.        def results = []
  13.         for( i in (1..self)) {
  14.             results << (generator.nextInt(facets) + 1)
  15.         }
  16.         println "$results"
  17.         return results.inject(0) { sum, value -> sum += value }
  18.     }
  19. }
  20.  
  21. use(DiceRoller) {
  22.     Eval.me(diceString("3d6 + 3"))
  23. }

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with @@


Remember me so that I can delete my post