"dice roll to add total to array lua" Code Answer's
You're definitely familiar with the best coding language Lua that developers use to develop their projects and they get all their queries like "dice roll to add total to array lua" answered properly. Developers are finding an appropriate answer about dice roll to add total to array lua related to the Lua coding language. By visiting this online portal developers get answers concerning Lua codes question like dice roll to add total to array lua. Enter your desired code related query in the search bar and get every piece of information about Lua code related question on dice roll to add total to array lua.
dice roll to add total to array lua
local function comp(ndice1, nsides1, ndice2, nsides2) local function throws(ndice, nsides) local sums = {} for i = 1, ndice*nsides do sums[i] = 0 end local function throw(ndice, nsides, s) if (ndice==0) then sums[s] = sums[s] + 1 else for i = 1, nsides do throw(ndice-1, nsides, s+i) end end return sums end return throw(ndice, nsides, 0) end local p1 = throws(ndice1, nsides1) local p2 = throws(ndice2, nsides2) local wins, coms = 0, nsides1^ndice1 * nsides2^ndice2 for k1,v1 in pairs(p1) do for k2,v2 in pairs(p2) do if (k1 > k2) then wins = wins + v1 * v2 end end end print("computed: p1 = "..ndice1.."d"..nsides1..", p2 = "..ndice2.."d"..nsides2..", prob = "..wins.." / "..coms.." = "..(wins/coms))end comp(9, 4, 6, 6)comp(5, 10, 6, 7)
Source: www.rosettacode.org
All those coders who are working on the Lua based application and are stuck on dice roll to add total to array lua can get a collection of related answers to their query. Programmers need to enter their query on dice roll to add total to array lua related to Lua code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about dice roll to add total to array lua for the programmers working on Lua code while coding their module. Coders are also allowed to rectify already present answers of dice roll to add total to array lua while working on the Lua language code. Developers can add up suggestions if they deem fit any other answer relating to "dice roll to add total to array lua". Visit this developer's friendly online web community, CodeProZone, and get your queries like dice roll to add total to array lua resolved professionally and stay updated to the latest Lua updates.