Former player
Joined: 8/12/2004
Posts: 651
Location: Alberta, Canada
Here. I was too lazy to put error checking into it, so entering letters where it expects numbers will cause bad things. So just don't be dumb. ;p I juggled datatypes and it can now go higher than 10d6. I tested with 13d8 and it seemed to work fine. Not sure what it can go up to now. Though it does take a quite a while to calculate numbers that high.
Player (201)
Joined: 7/6/2004
Posts: 511
Here is a more efficient algorithm for solving it, it can solve past 100 dice with 100 sides instantly. It doesn't work much past that due to overflow, however you can fix this by changing the type of v, sum, total to a big integer or big decimal. Here is the java code, you can download compiled version at http://wam.umd.edu/~darreon/dice To run, download and at the command line go to its directory and type java dice2 8 6 4 (for n = 8, s = 6, r = 4). BTW does anyone know of any open jobs doing this kind of programming? I need a job and this stuff is fun :)
public class dice2 {
	public static void main(String [] args) {
		System.out.println(solver(atoi(args[0]), atoi(args[1]), atoi(args[2])));
	}
	static double solver(int n, int s, int r) {
		double v = 1, sum = 0, total = 0;
		int t = n, t2 = n * s;
		for(int i=1; t<t2; i++, t++, t2--) {
			sum += (reduce(t, r) + reduce(t2, r)) * v;
			total += 2 * v;
			v = v / i * t;
		}
		if(t == t2) { sum += reduce(t, r) * v; total += v; }
		return (double)sum/total;
	}
	static int reduce(int x, int r) { return x < r ? 0 : x - r; }
	static int atoi(String s) { return (int) (Long.decode(s)).longValue(); }
}
g,o,p,i=1e4,a[10001];main(x){for(;p?g=g/x*p+a[p]*i+2*!o: 53^(printf("%.4d",o+g/i),p=i,o=g%i);a[p--]=g%x)x=p*2-1;}
Skilled player (1827)
Joined: 4/20/2005
Posts: 2161
Location: Norrköping, Sweden
BoltR: Your program didn't work, After I typed in number of dice, sides per dice and the damage reduction, and pressed enter, the programwindow shuts down automatically. It seems like you missed a system("PAUSE") at the end line perhaps. flagitious: Your program worked just fine, thanks a lot man! :D