[ create a new paste ] login | about

Link: http://codepad.org/skMeBDfc    [ raw code | output | fork ]

Ruby, pasted on Mar 6:
T = 1000 # times
DICE = [5, 10, 15, 20, 30] # dice
CR = [6, 7, 8, 9, 10, 11].reverse # crit

# Calc
tbl = CR.map {|cr|
  DICE.map {|dice|
    total = 0
    T.times {
      r = 0
      d = dice
      loop {
        a = Array.new(d).map{ rand(10) + 1 }
        d = a.select{|e| e >= cr }.size
        if (d > 0) then
          r += 10
        else
          r += a.max
          break
        end
      }
      total += r
    }
    total / T.to_f
  }
}

# View
print 'C/D', DICE.map {|e| sprintf("%8d", e) }.join, "\n"
tbl.each_with_index {|e, i|
  print CR[i] > 10 ? 'non' : sprintf("%3d", CR[i]), e.map {|f| sprintf("%8.2f", f) }.join, "\n"
}


Output:
1
2
3
4
5
6
7
8
C/D       5      10      15      20      30
non    8.85    9.54    9.76    9.89    9.95
 10   11.56   14.02   16.45   17.26   19.06
  9   14.47   18.48   20.65   23.20   24.83
  8   18.36   24.08   27.28   29.12   32.62
  7   23.11   30.64   35.92   38.42   42.34
  6   30.55   40.12   45.10   51.16   55.90



Create a new paste based on this one


Comments: