PDA

View Full Version : Math question



pasko77
2012-01-31, 06:28 AM
Hello!
I need a little help from the math geeks to compute the average for this:

Roll [X] [K]sided dice, keep the best [N].
For any value of X, K, N.

So, 4d6b3 is an example of this formula (incidentally it is also the typical 3.5 chargen algorithm), and it averages, to my knowledge, around 12.

I'm not really interested in numeric solutions (i.e. run a simulation 10^6 times, take the average), I can do that myself. I'd like to know how to find the formula for the averages.

Thanks in advance, Pasko

Kolonel
2012-01-31, 03:00 PM
Not a big help, but:

I think you should approach this problem by changing it to a subtraction:
avg(4d6b3) = avg(4d6) - avg(min(4d6))
The average of the 4d6 sum, minus the average of the minimum die. (Or dice in other cases.)

The average of XdK is easy to find: (smallest result+largest result) / 2.

Only the average (sum) of the minimal die (dice) remains, which I don't know, but you should be able to find a formula for "sum of Y minimal values of X variables with dK (Uni(1;K)) distribution" somewhere.

Salanmander
2012-01-31, 03:43 PM
Not a big help, but:

I think you should approach this problem by changing it to a subtraction:
avg(4d6b3) = avg(4d6) - avg(min(4d6))


I'm not convinced that average is linear like that. Is avg(4d6) - avg(min(4d6)) = avg(4d6 - min(4d6))?

So, if you think of the 2d6 case, you can clearly find the probability distribution for the highest die, or the lowest die, simply by enumerating the possibilities. If there's a way to do that analytically, I suspect you can expand it to XdK, and then get the probability distribution for the 2nd highest, etc.

HMS Invincible
2012-01-31, 03:46 PM
The lazy way is to simulate the results a bunch of times on excel or some statistical software. But if you access to that, might as well ask your professor.

Siosilvar
2012-01-31, 03:54 PM
I use this (http://anydice.com/program/115) to simulate it. Change the numbers around as you want; it's currently at 4d6b3. I'm not aware of any real formula.

A quick Google gives me this:
For n dice, d sides, dropping k, and l is the highest roll that you drop, r is anything else you drop, and u is the number of dice that are showing the number l:

1/n^d * [the sum over l = 1...r of the sum over r = 0...k-1 of the sum over u = 1..n - r of (n over r) * ((n - r) over u) * (l - 1)^r * (l*(u - (k - r)) + (n - u - r) * ((d + 1) * d / 2 - (l + 1) * l / 2)].

Found here (http://www.enworld.org/forum/general-rpg-discussion/56352-5d6-drop-lowest-two-math.html).

EDIT:
I'm not convinced that average is linear like that. Is avg(4d6) - avg(min(4d6)) = avg(4d6 - min(4d6))?Some quick simulation testing with AnyDice (linked to above) tells me that those two do in fact have the same average. They don't have the same range of values or standard deviation, but they do end up with the same average. Test it yourself (http://anydice.com/program/e0b); change N to whatever you want.

Manateee
2012-01-31, 05:19 PM
Because I'm incredibly lazy, I'd just plug the Probability 101 method (sum the products of population and probabilities) into R.


poss<-matrix(nr=6^4, nc=4)
for (i in 1:4){
poss[,i]<-rep(1:6, 6^(i-1), each=6^(4-i))
}
roll<-matrix(nr=6^4, nc=1)
for (i in 1:6^4){
roll[i,]<-sum(poss[i,])-min(poss[i,])
}
sum(roll*6^-4)
So 4d6 best 3:

> sum(roll*6^-4)
[1] 12.2446

edit:
Coming back to this thread, you're looking for a generalized formula.
Just transforming the R code into a generalizable function:

XdKbN<-function(x,k,n){
if(x<n) return("ERROR: N>X")
poss<-matrix(nr=k^x, nc=x)
for (i in 1:x) poss[,i]<-rep(1:k, k^(i-1), each=k^(x-i))
roll<-matrix(nr=k^x, nc=1)
for (i in 1:k^x){
if(x>n) roll[i,]<-sum(poss[i,])-sum(sort(poss[i,])[1:(x-n)])
if(x==n) roll[i,]<-sum(poss[i,])
}
sum(roll*k^(-1*x))
}Then just checking the formula, it looks good:


> XdKbN(x=4,k=6,n=3)
[1] 12.2446
> XdKbN(x=2,k=4,n=2)
[1] 5
> XdKbN(x=5,k=3,n=8)
[1] "ERROR: N>X"
> XdKbN(x=5,k=3,n=2)
[1] 5.358025
EDIT EDIT:
Oh, and a bit of a warning: I might be able to think of a less efficient/more computationally intensive method here, but I'd have to sit down and think about it. This should work great for low numbers, but watch out when you start looking at things like 5d20 or 3d100.

Binks
2012-01-31, 05:48 PM
Hmm. Let's see what we can do.

*Standard I am not a mathematician I just play one on the internet disclaimer*.

To get the average we need to get the total of all possibilities (after taking the best N, which can be done by subtracting the lowest result). We then divide by the number of possibilities, K^N in this case. Doing this for an arbitrary set of dice should be possible, therefore, by finding a formula that gives us, for any values of K,X, and N, the following information:
1. What is the sum for the ith possible combination of rolls and
2. What is the lowest result in the ith possible combination of rolls.

The ideal formula would be one that generated a unique permutation for each possible result of rolling the X dice. It just so happens that such a formula exists, and is pretty easy to think of (just very hard to write out as a mathematical formula, so I'll got with an analogy for how to derive it).

Imagine, if you will, counting from 1 to some arbitrary value in base 6 with 4 significant digits (assuming I'm using that term right). It would look something like:
0000,0001,0002,0003,0004,0005,0010,0011,0012,0013, 0014,0015,0100,0101 etc.
Now imagine adding 1 to each of those digits, ie:
1111,1112,1113,1114,1115,1116,1121,1122,1123,1124, 1125,1126,1211,1212 etc.
Does that remind you of anything? Say, for instance, the possible permutations of 4d6? Counting in Base K with X digits and adding 1 to each digit nets us a nice series of all possible values for XdK, a series we can make use of.

With that information in hand we move on to dropping the worst (X-N), or keeping the best N results. If we treat each digit as a member of an array (111 = [1,1,1] etc) we can just remove the minimum value in the array (X-N) times then sum the array to get the best N results for that combination of die rolls.

Obviously this is a lot of steps to go through, and not a formula, but it's a start I suppose. I can't figure out how to make a mathematical formula out of all of that, but it's easily made into a java program (or any other programming language of your choice, would have loved to do it in python but don't have it on this machine).


import java.util.Scanner;

public class Dieaverage
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);

System.out.print("X = ");
int X = scan.nextInt();
System.out.print("K = ");
int K = scan.nextInt();
System.out.print("N = ");
int N = scan.nextInt();

double sum = 0, number = Math.pow(K, X), ik;
int[] res = new int[X];
int min, minloc;
System.out.println(number);

for (int i=0; i<number; i++)
{
// Get the Number
// DOES NOT WORK FOR K > 9. NEED TO FIND ANOTHER WAY TO DO THIS.
ik = Integer.parseInt(Integer.toString(i, (K+1)), 10);
// Convert it to an array
for (int v=0; v<X; v++)
res[v] = (int) (Math.floor((ik/Math.pow(10,(X-v-1)))%10)+1);
// Drop the bottom X-N results
for (int v2=0; v2<X-N; v2++)
{
// Min will get set to the first result
min = K+1;
minloc = 0;
for (int v=0; v<X; v++)
{
if (res[v] < min && res[v] != 0)
{
min = res[v];
minloc = v;
}
}
res[minloc] = 0;
}
// Add to sum
for (int v=0; v<X; v++)
sum += res[v];
}
System.out.println("Average: "+(sum/number));
}
}

I'm about 80% certain that works. I tried it for known values (1d6 best 1 yielded 3.5, 1d10 best 1 yielded 5.5, 4d6b3 yielded ~12.5, so it looks ok) and the other results I tried looked right, but I can't be certain. Also it doesn't work for die sizes above 9 yet (there's a comment in there noting the line that has an issue, something to work on later).

Hopefully someone more mathematically inclined than myself can come along and derive a formula from this :smallbiggrin:

Jay R
2012-01-31, 06:17 PM
The general case is more than I'm willing to do, but by summing all possibilities, I found that the average of 4d6b3 is 15869/1296 = 12.24459877.

DonDuckie
2012-01-31, 07:14 PM
I wrote a simulator and tested it for standard dice(2,3,4,6,8,10,12,20) for up to 9dXb9

The code(c/c++):
the simulator:


#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;

//
// Gives the average of NdXbY
//
void sort(int n, long long* A)
{
int key, j;
for( int i=1 ; i<n ; i++)
{
key = A[i];
j = i-1;
while(j >= 0 && A[j] < key)
{
A[j+1]=A[j];
j--;
}
A[j+1] = key;
}
}

int main(int argc, char **argv)
{
int runs=100000, N, X, Y;

if(argc==4)
{
N = atoi(argv[1]);
X = atoi(argv[2]);
Y = atoi(argv[3]);
if(Y>N || N<1 || X<1 || Y<1)
{
cout << "N X Y - Error: all values must be positive and Y cannot be larger than N." << endl;
exit(0);
}
}
else
{
cout << "Usage: ndxby <N> <X> <Y>" << endl << "gives you the average of rolling NdX and keeping the best Y" << endl;
exit(0);
}

double total=0;
long long* rolls = (long long*) malloc(N*sizeof(long long));

srand48(time(NULL));
for(int i=0; i<runs; i++)
{
for(int j=0; j<N; j++)
rolls[j] = (lrand48()%X)+1;

sort(N, rolls);
for(int k=1; k<Y; k++)
rolls[0] += rolls[k];

total += rolls[0];
}
cout << N << "d" << X << "b" << Y << ": " << total/runs << endl;
free(rolls);
}
the tester:


#include <stdlib.h>
#include <stdio.h>

int main(int argc, char** argv)
{
int dice[8] = {2,3,4,6,8,10,12,20};

int maxN=10, maxX=8, Y;
char* str = (char*) malloc(20*sizeof(char));

for(int i = 0; i<maxX; i++)
{
for(int j = 1; j<maxN; j++)
{
for(int k=1; k<=j; k++)
{
sprintf(str, "./ndxby %d %d %d", j, dice[i], k);
system(str);
}
}
}
return 0;
}

The result(360 lines:smallbiggrin:):
1d2b1: 1.49952
2d2b1: 1.74919
2d2b2: 2.99931
3d2b1: 1.87409
3d2b2: 3.37469
3d2b3: 4.49913
4d2b1: 1.93773
4d2b2: 3.62474
4d2b3: 4.93685
4d2b4: 5.99969
5d2b1: 1.96882
5d2b2: 3.78165
5d2b3: 5.2808
5d2b4: 6.46812
5d2b5: 7.49978
6d2b1: 1.98461
6d2b2: 3.87541
6d2b3: 5.53187
6d2b4: 6.87555
6d2b5: 7.98495
6d2b6: 9.00049
7d2b1: 1.99218
7d2b2: 3.92926
7d2b3: 5.70334
7d2b4: 7.20362
7d2b5: 8.43038
7d2b6: 9.49275
7d2b7: 10.4999
8d2b1: 1.99644
8d2b2: 3.96032
8d2b3: 5.81688
8d2b4: 7.45312
8d2b5: 8.81688
8d2b6: 9.95977
8d2b7: 10.9959
8d2b8: 11.9995
9d2b1: 1.99797
9d2b2: 3.97902
9d2b3: 5.89022
9d2b4: 7.63514
9d2b5: 9.13517
9d2b6: 10.3893
9d2b7: 11.4789
9d2b8: 12.4986
9d2b9: 13.501
1d3b1: 1.99955
2d3b1: 2.44301
2d3b2: 3.99741
3d3b1: 2.6656
3d3b2: 4.66213
3d3b3: 5.99737
4d3b1: 2.78855
4d3b2: 5.08374
4d3b3: 6.78723
4d3b4: 7.99772
5d3b1: 2.86401
5d3b2: 5.35581
5d3b3: 7.35324
5d3b4: 8.85752
5d3b5: 9.99214
6d3b1: 2.91029
6d3b2: 5.5404
6d3b3: 7.75847
6d3b4: 9.53727
6d3b5: 10.91
6d3b6: 12.0003
7d3b1: 2.94037
7d3b2: 5.67148
7d3b3: 8.0545
7d3b4: 10.0544
7d3b5: 11.6699
7d3b6: 12.9383
7d3b7: 13.9972
8d3b1: 2.96169
8d3b2: 5.76277
8d3b3: 8.27209
8d3b4: 10.4418
8d3b5: 12.2634
8d3b6: 13.751
8d3b7: 14.9475
8d3b8: 15.9865
9d3b1: 2.97364
9d3b2: 5.82893
9d3b3: 8.44389
9d3b4: 10.7502
9d3b5: 12.7513
9d3b6: 14.4447
9d3b7: 15.8208
9d3b8: 16.9645
9d3b9: 17.9908
1d4b1: 2.49696
2d4b1: 3.12324
2d4b2: 4.99497
3d4b1: 3.43328
3d4b2: 5.93006
3d4b3: 7.49019
4d4b1: 3.61687
4d4b2: 6.51284
4d4b3: 8.61334
4d4b4: 9.99646
5d4b1: 3.73135
5d4b2: 6.89608
5d4b3: 9.39431
5d4b4: 11.2318
5d4b5: 12.5015
6d4b1: 3.80589
6d4b2: 7.15582
6d4b3: 9.94269
6d4b4: 12.1562
6d4b5: 13.8046
6d4b6: 14.9987
7d4b1: 3.85794
7d4b2: 7.34866
7d4b3: 10.353
7d4b4: 12.8518
7d4b5: 14.8473
7d4b6: 16.3556
7d4b7: 17.5039
8d4b1: 3.89609
8d4b2: 7.49549
8d4b3: 10.6684
8d4b4: 13.3892
8d4b5: 15.6708
8d4b6: 17.4998
8d4b7: 18.901
8d4b8: 20.0053
9d4b1: 3.92282
9d4b2: 7.6028
9d4b3: 10.9106
9d4b4: 13.8128
9d4b5: 16.3107
9d4b6: 18.4094
9d4b7: 20.1006
9d4b8: 21.4194
9d4b9: 22.4923
1d6b1: 3.49882
2d6b1: 4.47486
2d6b2: 7.00127
3d6b1: 4.95806
3d6b2: 8.4604
3d6b3: 10.4998
4d6b1: 5.24547
4d6b2: 9.348
4d6b3: 12.2519
4d6b4: 14.0087
5d6b1: 5.43009
5d6b2: 9.92973
5d6b3: 13.4293
5d6b4: 15.9306
5d6b5: 17.5097
6d6b1: 5.55966
6d6b2: 10.3487
6d6b3: 14.2826
6d6b4: 17.3541
6d6b5: 19.5709
6d6b6: 21.0104
7d6b1: 5.65397
7d6b2: 10.6484
7d6b3: 14.8975
7d6b4: 18.3956
7d6b5: 21.1437
7d6b6: 23.1454
7d6b7: 24.5001
8d6b1: 5.72529
8d6b2: 10.89
8d6b3: 15.3936
8d6b4: 19.2297
8d6b5: 22.3948
8d6b6: 24.8838
8d6b7: 26.7207
8d6b8: 27.9964
9d6b1: 5.77389
9d6b2: 11.0624
9d6b3: 15.7696
9d6b4: 19.8697
9d6b5: 23.3703
9d6b6: 26.2707
9d6b7: 28.5674
9d6b8: 30.2632
9d6b9: 31.4848
1d8b1: 4.51013
2d8b1: 5.81712
2d8b2: 9.00702
3d8b1: 6.46641
3d8b2: 10.9655
3d8b3: 13.4957
4d8b1: 6.85816
4d8b2: 12.1523
4d8b3: 15.841
4d8b4: 17.9785
5d8b1: 7.11006
5d8b2: 12.9402
5d8b3: 17.4319
5d8b4: 20.5905
5d8b5: 22.4749
6d8b1: 7.29153
6d8b2: 13.4991
6d8b3: 18.5734
6d8b4: 22.4942
6d8b5: 25.2784
6d8b6: 26.9837
7d8b1: 7.42598
7d8b2: 13.9198
7d8b3: 19.4165
7d8b4: 23.922
7d8b5: 27.4197
7d8b6: 29.9218
7d8b7: 31.4932
8d8b1: 7.52675
8d8b2: 14.2444
8d8b3: 20.082
8d8b4: 25.0265
8d8b5: 29.0801
8d8b6: 32.2483
8d8b7: 34.5424
8d8b8: 36.0142
9d8b1: 7.6101
9d8b2: 14.5084
9d8b3: 20.6119
9d8b4: 25.9169
9d8b5: 30.4176
9d8b6: 34.1187
9d8b7: 37.0202
9d8b8: 39.1235
9d8b9: 40.5056
1d10b1: 5.49576
2d10b1: 7.1471
2d10b2: 11.0019
3d10b1: 7.96906
3d10b2: 13.47
3d10b3: 16.4928
4d10b1: 8.46229
4d10b2: 14.9579
4d10b3: 19.4601
4d10b4: 21.9928
5d10b1: 8.79924
5d10b2: 15.9741
5d10b3: 21.4777
5d10b4: 25.312
5d10b5: 27.5223
6d10b1: 9.02427
6d10b2: 16.6726
6d10b3: 22.8932
6d10b4: 27.6816
6d10b5: 31.0272
6d10b6: 33.0102
7d10b1: 9.19479
7d10b2: 17.1928
7d10b3: 23.9415
7d10b4: 29.4396
7d10b5: 33.6951
7d10b6: 36.6861
7d10b7: 38.4878
8d10b1: 9.32565
8d10b2: 17.607
8d10b3: 24.7768
8d10b4: 30.8268
8d10b5: 35.7708
8d10b6: 39.6035
8d10b7: 42.3267
8d10b8: 44.0042
9d10b1: 9.42804
9d10b2: 17.9289
9d10b3: 25.4364
9d10b4: 31.9477
9d10b5: 37.4419
9d10b6: 41.9472
9d10b7: 45.4521
9d10b8: 47.9581
9d10b9: 49.5371
1d12b1: 6.50273
2d12b1: 8.4934
2d12b2: 13.0105
3d12b1: 9.47591
3d12b2: 15.9797
3d12b3: 19.5064
4d12b1: 10.073
4d12b2: 17.7744
4d12b3: 23.0776
4d12b4: 26.0121
5d12b1: 10.4642
5d12b2: 18.9537
5d12b3: 25.4452
5d12b4: 29.9427
5d12b5: 32.4744
6d12b1: 10.7411
6d12b2: 19.8117
6d12b3: 27.16
6d12b4: 32.7957
6d12b5: 36.7373
6d12b6: 38.9881
7d12b1: 10.9511
7d12b2: 20.4453
7d12b3: 28.4361
7d12b4: 34.9429
7d12b5: 39.9426
7d12b6: 43.4377
7d12b7: 45.4808
8d12b1: 11.1131
8d12b2: 20.9448
8d12b3: 29.4331
8d12b4: 36.5916
8d12b5: 42.4153
8d12b6: 46.9083
8d12b7: 50.0725
8d12b8: 52.0115
9d12b1: 11.2402
9d12b2: 21.3463
9d12b3: 30.2545
9d12b4: 37.9566
9d12b5: 44.4245
9d12b6: 49.7201
9d12b7: 53.8197
9d12b8: 56.7241
9d12b9: 58.5129
1d20b1: 10.5183
2d20b1: 13.827
2d20b2: 21.0033
3d20b1: 15.4876
3d20b2: 25.9884
3d20b3: 31.512
4d20b1: 16.482
4d20b2: 28.984
4d20b3: 37.4717
4d20b4: 41.992
5d20b1: 17.1491
5d20b2: 30.9902
5d20b3: 41.497
5d20b4: 48.6707
5d20b5: 52.529
6d20b1: 17.6198
6d20b2: 32.4164
6d20b3: 44.3542
6d20b4: 53.4334
6d20b5: 59.6298
6d20b6: 63.0074
7d20b1: 17.975
7d20b2: 33.4787
7d20b3: 46.4765
7d20b4: 56.9747
7d20b5: 64.9803
7d20b6: 70.4831
7d20b7: 73.5095
8d20b1: 18.235
8d20b2: 34.2845
8d20b3: 48.131
8d20b4: 59.7325
8d20b5: 69.1098
8d20b6: 76.2613
8d20b7: 81.19
8d20b8: 84.0263
9d20b1: 18.4715
9d20b2: 34.9786
9d20b3: 49.4806
9d20b4: 61.979
9d20b5: 72.5652
9d20b6: 81.0767
9d20b7: 87.5841
9d20b8: 92.0895
9d20b9: 94.5346

Manateee
2012-01-31, 08:51 PM
A quick Google gives me this:
That hurt my head to parse.

I dug through that ENworld thread and found a better presentation.
Here it is, after editing some obvious oversights/errors:
http://img850.imageshack.us/img850/1879/quickformula.png (http://imageshack.us/photo/my-images/850/quickformula.png/)
Where
n = number of dice
d = number of sides
k = number of dice dropped

I'm going to give it a closer look later on, but that might be what you're looking for.

Also, if you're into R, that thread pointed out the absolutely amazing dice (http://cran.r-project.org/web/packages/dice/index.html) package. I do believe I'll be playing with it for the next couple of whiles.

pasko77
2012-02-01, 08:06 AM
Thanks everybody for your kind attention. :)


A quick Google gives me this:
For n dice, d sides, dropping k, and l is the highest roll that you drop, r is anything else you drop, and u is the number of dice that are showing the number l:


Found here (http://www.enworld.org/forum/general-rpg-discussion/56352-5d6-drop-lowest-two-math.html).

Thanks, this is what I was searching!




XdKbN<-function(x,k,n){
if(x<n) return("ERROR: N>X")
poss<-matrix(nr=k^x, nc=x)
for (i in 1:x) poss[,i]<-rep(1:k, k^(i-1), each=k^(x-i))
roll<-matrix(nr=k^x, nc=1)
for (i in 1:k^x){
if(x>n) roll[i,]<-sum(poss[i,])-sum(sort(poss[i,])[1:(x-n)])
if(x==n) roll[i,]<-sum(poss[i,])
}
sum(roll*k^(-1*x))
}

I suppose this is Matlab, right? Unfortunately I'm not very proficient in it.


Imagine, if you will, counting from 1 to some arbitrary value in base 6 with 4 significant digits (assuming I'm using that term right). It would look something like:
0000,0001,0002,0003,0004,0005,0010,0011,0012,0013, 0014,0015,0100,0101 etc.
Now imagine adding 1 to each of those digits, ie:
1111,1112,1113,1114,1115,1116,1121,1122,1123,1124, 1125,1126,1211,1212 etc.
Does that remind you of anything? Say, for instance, the possible permutations of 4d6?

Very clever idea, thanks :)
Thanks for the code, too.



http://img850.imageshack.us/img850/1879/quickformula.png (http://imageshack.us/photo/my-images/850/quickformula.png/)
Where
n = number of dice
d = number of sides
k = number of dice dropped

I'm going to give it a closer look later on, but that might be what you're looking for.



Yes, thank you! This is perfect :)
I parsed this function from the thread pointed earlier, but this image is definately better :)

Tyndmyr
2012-02-01, 08:41 AM
How does this change if dices explode? IE, when they roll the max value, another 1k1 dice are added?

Actually important for a number of games I play, and it's remarkably hard to deduce a general formula. I can get all instances where kept dice are the same as rolled dice, but other instances are...challenging.

Radar
2012-02-02, 04:44 PM
How does this change if dices explode? IE, when they roll the max value, another 1k1 dice are added?

Actually important for a number of games I play, and it's remarkably hard to deduce a general formula. I can get all instances where kept dice are the same as rolled dice, but other instances are...challenging.
A single exploding die isn't that complicated. Let's take a d10:
Outcomes from 1 to 9 will have probability 1/10 as usual.
Instead of 10 you'll get any number from 11 to 20 with equal probabilities, which means that outcomes from 11 to 19 have probabilities 1/100 (20 means another exploding die). In essence:
An outcome of 10n+k (where k is an integer from 1 to 9 and n is any non-negative integer) has probability of 1/10^n.
Anything else can be derived from that as usual.

Manateee
2012-02-02, 05:34 PM
I haven't had a chance to even verify the previous formulas, but I'll have some free time this weekend.

Regarding the exploding dice, do the extra rolls count as additions to the first, or do they count as extra individual dice?

eg. in an exploding 3d4b2, if I roll a 2, 3 and 4, and the extra die comes up a 1, is the total 8 or 9?

Razanir
2012-02-02, 06:13 PM
@Manateee: I THINK it would be 8. What happens is this:
Roll 1- 2
Roll 2- 3
Roll 3- 4
Oh look, it's a 4! let's roll again and add to the 4
Roll 3a- 1
2, 3, 5
Minimum is 2
3 + 5 = 8

Back to the general discussion, exploding dice are easy enough when you don't try only taking the max roll. All you need is an infinite geometric sum. For XdKbN, exploding dice, there is a probability of 1/X that we roll again FOR EVERY DIE. So we add (K+1)/2 (average of one die). There's another 1/X chance. etc. etc. The initial value is (K+1)/(2*X), divide by 1-r = 1-1/X. Long math explanation short, if you're rolling XdKbN and make it exploding, add N*(K+1)/(2X-1)

And Binks, I'll work on porting that to python... just not the input parts (I'm learning the language, and haven't learned that yet)