[ create a new paste ] login | about

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

Lua, pasted on Jan 17:
for drives=2, 20, 2 do
  local dead = 3

  local live = 0
  local total = 0

  for i=1, 10000 do
    local killarray = {}
    for k=1, dead do
      table.insert(killarray, math.random(drives))
    end
    table.sort(killarray)
    local valid = true
    local surviving = true
    for k=1, dead - 1 do
      if killarray[k] == killarray[k + 1] then
        valid = false
        break
      end
      if math.ceil(killarray[k] / 2) == math.ceil(killarray[k + 1] / 2) then
        surviving = false
      end
    end
    if valid then
      if surviving then
        live = live + 1
      end
      total = total + 1
    end
  end

  print(string.format("%d: %d/%d - %f%%", drives, live, total, live / total * 100))
end


Output:
1
2
3
4
5
6
7
8
9
10
2: 0/0 - nan%
4: 0/3782 - 0.000000%
6: 2264/5567 - 40.668223%
8: 3746/6524 - 57.418761%
10: 4762/7206 - 66.083819%
12: 5549/7634 - 72.687975%
14: 6067/7951 - 76.304867%
16: 6543/8174 - 80.046489%
18: 6936/8454 - 82.044003%
20: 7246/8571 - 84.540894%


Create a new paste based on this one


Comments: