Ten/Die/Prime

  • 69 results
  • 1
  • 2
Avatar image for pomeroy
pomeroy

163

Forum Posts

232

Wiki Points

0

Followers

Reviews: 0

User Lists: 1

#1  Edited By pomeroy

As a math major I'm completely fascinated by the sheer math behind it....but I'm feeling a little lazy because I don't know the tricks/formulas. If I were to calculate the chances of getting a prime number I'd just crank out each permutation and calculate the percentage. Anyone else want to do it for me?

By all means, through in graphs and maybe even do calculations for other types of die.

I know what you're thinking, "Pomeroy, you're a really shitty math major." FOR NOW I AM....I'm at the point in school where everything is calculus and rote applications, not more pure, fun stuff.

Avatar image for b0nd07
B0nd07

1775

Forum Posts

2506

Wiki Points

0

Followers

Reviews: 0

User Lists: 15

#3  Edited By B0nd07

It's 10-die-prime. Straight from the source.

@ChristianConservativeVinny: It's a dice game that Dave made up and showed on the Happy Hour. Basically, you start by having all wanting to play ante up by betting one dollar (or however much all involved agree on). Then you roll one six-sided die to see who goes first, the winner then rolls 10 six-sided dice. If the result is a prime number, he/she wins the pot; if not, they add other dollar to the pot and the next person rolls. The game continues until all agree to quit, or all but one is out of money.

@Pomeroy: I'm no math major, but when rolling ten (six-sided) dice, you can roll any number between 10 and 60 inclusive, that's 51 numbers. Between 10 and 60 are 13 prime numbers; 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, and 59. So, you have a 13 out of 51 chance of rolling a prime, or ~25.5% (or a ~2%, 1/51, chance of rolling any particular prime).

That's what my post 3am mind is telling me is right, anyway. Also, I haven't had a math class in 2 1/2 years, and none of them were statistics.

Avatar image for slaker117
Slaker117

4873

Forum Posts

3305

Wiki Points

0

Followers

Reviews: 1

User Lists: 11

#4  Edited By Slaker117

@B0nd07: Unfortunately it's not quite that simple. There are 51 different possible numbers, but 60,466,176 (6^10) possible combinations of the dice. Just like a simple two dice game, where it is common knowledge that 7 is the most likely number, the chances of rolling a specific number vary, favoring the number as you approach the middle from either direction.

With 10 six-sided die, 35 is the middle number and the most likely roll, making both 31 and 37 fairly likely winners. As for anything more specific, I can swear I've been given similar questions before in high school for either math or computer science, and I'm pretty sure I could work this out, but it's 2 AM, so probably not going to do it right now.

Avatar image for slaker117
Slaker117

4873

Forum Posts

3305

Wiki Points

0

Followers

Reviews: 1

User Lists: 11

#5  Edited By Slaker117

@Pomeroy:

So I'm pretty sure there is a more elegant way to get this mathematically, but I couldn't figure out how. Instead I wrote a small java program to calculate the odds through the brute force of simulation. Here they are.

10: 1.0/60,466,176 = 1.6538172E-6%
11: 10.0/60,466,176 = 1.6538172E-5%
12: 55.0/60,466,176 = 9.095995E-5%
13: 220.0/60,466,176 = 3.638398E-4%
14: 715.0/60,466,176 = 0.0011824793%
15: 2002.0/60,466,176 = 0.003310942%
16: 4995.0/60,466,176 = 0.008260816%
17: 11340.0/60,466,176 = 0.018754287%
18: 23760.0/60,466,176 = 0.039294697%
19: 46420.0/60,466,176 = 0.076770194%
20: 85228.0/60,466,176 = 0.14095153%
21: 147940.0/60,466,176 = 0.24466571%
22: 243925.0/60,466,176 = 0.40340737%
23: 383470.0/60,466,176 = 0.63418925%
24: 576565.0/60,466,176 = 0.9535331%
25: 831204.0/60,466,176 = 1.3746594%
26: 1151370.0/60,466,176 = 1.9041555%
27: 1535040.0/60,466,176 = 2.5386755%
28: 1972630.0/60,466,176 = 3.2623694%
29: 2446300.0/60,466,176 = 4.045733%
30: 2930455.0/60,466,176 = 4.846437%
31: 3393610.0/60,466,176 = 5.6124105%
32: 3801535.0/60,466,176 = 6.2870436%
33: 4121260.0/60,466,176 = 6.8158107%
34: 4325310.0/60,466,176 = 7.1532717%
35: 4395456.0/60,466,176 = 7.2692804%
36: 4325310.0/60,466,176 = 7.1532717%
37: 4121260.0/60,466,176 = 6.8158107%
38: 3801535.0/60,466,176 = 6.2870436%
39: 3393610.0/60,466,176 = 5.6124105%
40: 2930455.0/60,466,176 = 4.846437%
41: 2446300.0/60,466,176 = 4.045733%
42: 1972630.0/60,466,176 = 3.2623694%
43: 1535040.0/60,466,176 = 2.5386755%
44: 1151370.0/60,466,176 = 1.9041555%
45: 831204.0/60,466,176 = 1.3746594%
46: 576565.0/60,466,176 = 0.9535331%
47: 383470.0/60,466,176 = 0.63418925%
48: 243925.0/60,466,176 = 0.40340737%
49: 147940.0/60,466,176 = 0.24466571%
50: 85228.0/60,466,176 = 0.14095153%
51: 46420.0/60,466,176 = 0.076770194%
52: 23760.0/60,466,176 = 0.039294697%
53: 11340.0/60,466,176 = 0.018754287%
54: 4995.0/60,466,176 = 0.008260816%
55: 2002.0/60,466,176 = 0.003310942%
56: 715.0/60,466,176 = 0.0011824793%
57: 220.0/60,466,176 = 3.638398E-4%
58: 55.0/60,466,176 = 9.095995E-5%
59: 10.0/60,466,176 = 1.6538172E-5%
60: 1.0/60,466,176 = 1.6538172E-6%

That should be right, though it is possible that I messed up my simulation, so I'll post it below for anyone interested. Be warned, by its nature it's all ugly and nested, and I hadn't coded anything in java for about a year, so it's probably a little bloated as I was mostly just trying to remember how to do anything. That said, pretty simple stuff, so a quick glace to make sure my logic is sound couldn't hurt.

class tenDiePrime {

public static void main(String[] args) {

int die1=1;

int die2=1;

int die3=1;

int die4=1;

int die5=1;

int die6=1;

int die7=1;

int die8=1;

int die9=1;

int die10=1;

float[] array;

array = new float[51];

for (int count = 0; count < 51; count++){

array[count]=0;

}

for (int count1=0; count1<6; count1++){

for (int count2=0; count2<6; count2++){

for (int count3=0; count3<6; count3++){

for (int count4=0; count4<6; count4++){

for (int count5=0; count5<6; count5++){

for (int count6=0; count6<6; count6++){

for (int count7=0; count7<6; count7++){

for (int count8=0; count8<6; count8++){

for (int count9=0; count9<6; count9++){

for (int count10=0; count10<6; count10++){

array[(die1+die2+die3+die4+die5+die6+die7+die8+die9+die10)-10]++;

die10++;

}

die9++;

die10=1;

}

die8++;

die9=1;

}

die7++;

die8=1;

}

die6++;

die7=1;

}

die5++;

die6=1;

}

die4++;

die5=1;

}

die3++;

die4=1;

}

die2++;

die3=1;

}

die1++;

die2=1;

}

for (int count = 0; count < 51; count++){

System.out.println ((count+10) + ": " + array[count] + "/60,466,176 = " + (array[count]/60466176)*100 + "%");

}

}

}

Avatar image for insidioustuna
InsidiousTuna

577

Forum Posts

122

Wiki Points

0

Followers

Reviews: 0

User Lists: 0

#6  Edited By InsidiousTuna

@Slaker117: Good god, man.

Avatar image for slaker117
Slaker117

4873

Forum Posts

3305

Wiki Points

0

Followers

Reviews: 1

User Lists: 11

#7  Edited By Slaker117

Fuck me, I totally made the most mindless mistake at the end after getting everything else right. Fixed the percentages so they are actually per cent and not the stupidly low numbers I had before.

Avatar image for choffy
Choffy

484

Forum Posts

2484

Wiki Points

0

Followers

Reviews: 0

User Lists: 2

#8  Edited By Choffy

DAVE'S A CHEATER.

Avatar image for snide
snide

2692

Forum Posts

1858

Wiki Points

0

Followers

Reviews: 3

User Lists: 14

#9  Edited By snide

@Slaker117: I get that you've calculated the percentage per number but what would be the chance to throw one of the 13 primes? Also, no math whiz, but shouldn't those percentages add up to 100? A quick scan has them over 100% if added.

I'd also imagine that you'd have a pure bell curve between 10 and 60. Why do the ends have spikes (12,13,57,58)?

We continued playing this last night and I can definitely say it's a lot more fun while drinking.

Avatar image for slaker117
Slaker117

4873

Forum Posts

3305

Wiki Points

0

Followers

Reviews: 1

User Lists: 11

#10  Edited By Slaker117

@snide: The odds of rolling any prime are actually not bad at about 24.441%.

As for the bell curve, it is. The spikes you are seeing are probably because you are missing where the computer auto truncated with "E-x" at the end, which probably takes care of the problem of the percentages adding up to over 100% as well.

If you aren't familiar with the notation, "E-x" means "move the decimal to the left x times," so something like 3.638398E-4% becomes .0003638398%.

Avatar image for origina1penguin
Origina1Penguin

3530

Forum Posts

2867

Wiki Points

0

Followers

Reviews: 1

User Lists: 2

#11  Edited By Origina1Penguin

Here. That will let you see a visual of the bell curve. If you want precise percentages, click the Export button. Slaker's numbers are accurate.

Avatar image for ajamafalous
ajamafalous

13992

Forum Posts

905

Wiki Points

0

Followers

Reviews: 0

User Lists: 9

#12  Edited By ajamafalous

You guys are crazy.

Avatar image for mcghee
McGhee

6128

Forum Posts

0

Wiki Points

0

Followers

Reviews: 0

User Lists: 2

#13  Edited By McGhee

@Slaker117 said:

@snide: The odds of rolling any prime are actually not bad at about 24.538%.

As for the bell curve, it is. The spikes you are seeing are probably because you are missing where the computer auto truncated with "E-x" at the end, which probably takes care of the problem of the percentages adding up to over 100% as well.

If you aren't familiar with the notation, "E-x" means "move the decimal to the left x times," so something like 3.638398E-4% becomes .0003638398%.

So this is what wizards talking magic must sound like.

Avatar image for slaker117
Slaker117

4873

Forum Posts

3305

Wiki Points

0

Followers

Reviews: 1

User Lists: 11

#14  Edited By Slaker117

^________^

At the risk of sounding extremely arrogant, nothing I did would be considered complicated to someone who completed an introductory programming class. The logic is quite simple, the scariest part is when it displays a ton of messy numbers at the end. I've probably spent more time posting in this thread than I did coding, and I did that mostly as an excuse to revisit java and see if I still remembered the syntax. Not that I'm not still a huge nerd, but whatever.

Avatar image for i_smell
I_smell

4221

Forum Posts

1650

Wiki Points

0

Followers

Reviews: 5

User Lists: 11

#15  Edited By I_smell

Conbrats on workin out which numbers are more likely to show up guys, but that aint gon do shit when you got ten die in yr hands n yr last buck on the table.

Dice is dice!

Avatar image for citizenkane
citizenkane

10894

Forum Posts

29122

Wiki Points

0

Followers

Reviews: 0

User Lists: 106

#16  Edited By citizenkane

I'll try to get a program going tomorrow that tests all kinds of probabilities for you.

Avatar image for levio
Levio

1953

Forum Posts

11

Wiki Points

0

Followers

Reviews: 9

User Lists: 0

#17  Edited By Levio

Heh, you're all suckers cause you just bet 1 dollar at a time. Using my Martingale doubling method, I'm guaranteed to win 1 dollar every time I roll, leaving the "luck" aspect to my clueless companions.

Avatar image for jabbrwky
JaBBrwky

3

Forum Posts

1

Wiki Points

0

Followers

Reviews: 0

User Lists: 0

#18  Edited By JaBBrwky

I've been teaching myself java and had a class for dice-probability calculating all ready to go. Combine with a quick&dirty prime checker, and I got:

Probability of getting a prime number when rolling 1 6-sided dice is 0.6666667.
Probability of getting a prime number when rolling 2 6-sided dice is 0.41666666.
Probability of getting a prime number when rolling 3 6-sided dice is 0.33796296.
Probability of getting a prime number when rolling 4 6-sided dice is 0.33333334.
Probability of getting a prime number when rolling 5 6-sided dice is 0.31712964.
Probability of getting a prime number when rolling 6 6-sided dice is 0.27199075.
Probability of getting a prime number when rolling 7 6-sided dice is 0.24158378.
Probability of getting a prime number when rolling 8 6-sided dice is 0.23570625.
Probability of getting a prime number when rolling 9 6-sided dice is 0.23605664.
Probability of getting a prime number when rolling 10 6-sided dice is 0.24441415.
Probability of getting a prime number when rolling 11 6-sided dice is 0.2574141.
Probability of getting a prime number when rolling 12 6-sided dice is 0.25824347.
Probability of getting a prime number when rolling 13 6-sided dice is 0.24224402.
Probability of getting a prime number when rolling 14 6-sided dice is 0.22278926.

It shows some interesting ups and downs as the peak of the distribution of the number rolled passes over concentrations of primes. You're almost on 37, 41, and 43 with 10 dice, but adding an 11th helps a bit. As you go to a large number n of dice, the density of primes around your peak will be roughly 1/ln(3.5*n), so overall the probability of rolling a prime should slowly decrease as you add dice. Probabilities for 15-40 below the spoiler thingy.

Probability of getting a prime number when rolling 15 6-sided dice is 0.21331981.
Probability of getting a prime number when rolling 16 6-sided dice is 0.21552263.
Probability of getting a prime number when rolling 17 6-sided dice is 0.22379509.
Probability of getting a prime number when rolling 18 6-sided dice is 0.23270558.
Probability of getting a prime number when rolling 19 6-sided dice is 0.23859675.
Probability of getting a prime number when rolling 20 6-sided dice is 0.23890679.
Probability of getting a prime number when rolling 21 6-sided dice is 0.23263493.
Probability of getting a prime number when rolling 22 6-sided dice is 0.22089463.
Probability of getting a prime number when rolling 23 6-sided dice is 0.20677933.
Probability of getting a prime number when rolling 24 6-sided dice is 0.19492872.
Probability of getting a prime number when rolling 25 6-sided dice is 0.19035602.
Probability of getting a prime number when rolling 26 6-sided dice is 0.19603851.
Probability of getting a prime number when rolling 27 6-sided dice is 0.21047686.
Probability of getting a prime number when rolling 28 6-sided dice is 0.22738528.
Probability of getting a prime number when rolling 29 6-sided dice is 0.23837127.
Probability of getting a prime number when rolling 30 6-sided dice is 0.23720594.
Probability of getting a prime number when rolling 31 6-sided dice is 0.22307776.
Probability of getting a prime number when rolling 32 6-sided dice is 0.20086832.
Probability of getting a prime number when rolling 33 6-sided dice is 0.17841189.
Probability of getting a prime number when rolling 34 6-sided dice is 0.16254617.
Probability of getting a prime number when rolling 35 6-sided dice is 0.15628628.
Probability of getting a prime number when rolling 36 6-sided dice is 0.15843984.
Probability of getting a prime number when rolling 37 6-sided dice is 0.1653193.
Probability of getting a prime number when rolling 38 6-sided dice is 0.17310192.
Probability of getting a prime number when rolling 39 6-sided dice is 0.1794245.
Probability of getting a prime number when rolling 40 6-sided dice is 0.18366864.
Avatar image for burzmali
Burzmali

456

Forum Posts

0

Wiki Points

0

Followers

Reviews: 0

User Lists: 2

#19  Edited By Burzmali

@Slaker117 said:

^________^

At the risk of sounding extremely arrogant, nothing I did would be considered complicated to someone who completed an introductory programming class. The logic is quite simple, the scariest part is when it displays a ton of messy numbers at the end. I've probably spent more time posting in this thread than I did coding, and I did that mostly as an excuse to revisit java and see if I still remembered the syntax. Not that I'm not still a huge nerd, but whatever.

Yep, what he said. Just a quarter of the way into an intro programming class should be enough to write such a program. All you need is to know how to do a for loop, generate a random number, and how to output to the console. And you need to know how use math operators, but anyone who can read should know how those work already.

Avatar image for gkhan
gkhan

1192

Forum Posts

2

Wiki Points

0

Followers

Reviews: 0

User Lists: 4

#20  Edited By gkhan
@Burzmali said:

@Slaker117 said:

^________^

At the risk of sounding extremely arrogant, nothing I did would be considered complicated to someone who completed an introductory programming class. The logic is quite simple, the scariest part is when it displays a ton of messy numbers at the end. I've probably spent more time posting in this thread than I did coding, and I did that mostly as an excuse to revisit java and see if I still remembered the syntax. Not that I'm not still a huge nerd, but whatever.

Yep, what he said. Just a quarter of the way into an intro programming class should be enough to write such a program. All you need is to know how to do a for loop, generate a random number, and how to output to the console. And you need to know how use math operators, but anyone who can read should know how those work already.

That's good if you only want an approximation of what the real answer is (what we call a "monte carlo" simulation, technically). If you want to get the real number, you need to use some dynamic programming, and that's definitely not taught in introductory classes.  

LADIES AND GENTLEMEN, I GIVE YOU THE EXACT ANSWER: The probability of hitting a prime with ten dice is exactly 7389395/30233088 
 
Or, for those of you who think that looks like nonsense, approximately 24.44141663%. How do you solve a problem like this? Well, here's the quick explanation: Lets say we have a function F(n,s) which gives you how many ways "n" dice can sum up to "s". So, for instance, since two dice can sum up to 7 in six different ways, F(2,7) = 6. Or since three dice can sum up to 3 in only one way (all dice show 1), F(3,3) = 1. Or since two dice can sum to three in two different ways, F(2,3) = 2. 
 
Ok, so how do we calculate F(n,s) for any numbers "n" and "s". The answer lies in the deep dark art of recursion. Simply put: if we only have one dice, it can only sum up to numbers 1 through 6, and only in one way. Hence F(1,1) , F(1,2), F(1,3), F(1,4), F(1,5) and F(1,6) are all equal to 1. Any other number, like F(1,10), is equal to zero, because there's no way one die can sum up to ten. 
 
Now then: assume we have 10 dice, and we want to find out how many ways they can sum to 50. That is, we want to find F(10,50). Here's where the good part comes in: the only way 10 dice can sum up to 50 is if the first 9 dice sum up to something between 44 and 49, because the last die is going to show a number between one and six. So the number of ways 10 dice can sum to 50 is the sum of the number of ways 9 dice can sum up to 44,45,46,47,48 or 49. In other words, F(10,50) = F(9,44) + F(9,45) + F(9,46) + F(9,47) + F(9,48) + F(9,49).    

If we generalize this, we see that we get F(n,s) = F(n-1,s-6) + F(n-1,s-5) + F(n-1,s-4) + F(n-1,s-3) + F(n-1,s-2) + F(n-1,s-1) . This, along with our previous insight about the values of F(1,s), gives us enough to solve the problem. If you were to write pseudocode for this, it would look something like: 
 
function F(n,s):   if n is equal to 1:    if s is between 1 and 6:    return 1    else:    return 0    return F(n-1,s-6) + F(n-1,s-5) + F(n-1,s-4) + F(n-1,s-3) + F(n-1,s-2) + F(n-1,s-1) 
  

Note, however, that if you write this program and try to run it, it will give you the right answer, but it will take forever to calculate. You have to use a technique called dynamic programming (or memoization) to make sure you're not calculating the same values over and over again.  If you do that, the calculation takes like a millisecond to do.
 
Now, the answer to the problem is then simply the sum of F(10,s) where s is all teh prime values below sixty, divided by the total number of possible ways the dice can come up, which is 6 to the power of 10. That is, it's equal to (F(10,11) + F(10,13) + F(10,17) + ... + F(10, 53)  + F(10, 59)) / (6^10).  
 
Taada! Easy as pie. Never use monte carlo simulation if you don't have to, this runs MUCH MUCH faster and gives you the exact answer. Isn't computer science a wonderful thing?
Avatar image for hockeymask27
hockeymask27

3704

Forum Posts

794

Wiki Points

0

Followers

Reviews: 2

User Lists: 0

#21  Edited By hockeymask27

I got a 75% in stats last semester and already forgot it all good jib guys??? Like my Stat teacher says there is no wrong answer when it comes to stats ..just some are closer to 100% right then others.

Avatar image for example1013
Example1013

4854

Forum Posts

0

Wiki Points

0

Followers

Reviews: 0

User Lists: 0

#22  Edited By Example1013

This isn't a hard problem to even do out yourself with a calculator. All it requires is basic knowledge of probablility and a 100-level statistics course.

Now, as for the amount of time it takes, well, that's a different story. To do this all by yourself would be a bit of legwork.

The computer math is easier and much faster, though. In fact, this kind of thing is how computers got their name, because this is what they were originally for.

Avatar image for slaker117
Slaker117

4873

Forum Posts

3305

Wiki Points

0

Followers

Reviews: 1

User Lists: 11

#23  Edited By Slaker117

@gkhan: Actually, if you look at my code you'll see that I am getting the exact fractions using a less elegant method, it's just that the percentages have been rounded. I'm going through all the combinations using nested for loops and keeping track of the results in a array, not using random generation as Burzmali suggested. Your method is a nicer and more advanced way to do things, but not necessary.

Or at least I think I'm right. I've been mostly taught informally, so if there is something improper with my way I would love to hear an explanation.

Avatar image for crusader8463
crusader8463

14850

Forum Posts

4290

Wiki Points

0

Followers

Reviews: 7

User Lists: 5

#24  Edited By crusader8463

No, no, no. You guys got it all wrong. 1 + 1 = 3! Not two. It's a common mistake.

Avatar image for moistjohn
MoistJohn

279

Forum Posts

516

Wiki Points

0

Followers

Reviews: 3

User Lists: 5

#25  Edited By MoistJohn

@Slaker117 Your solution is basic but it works. the problem with it is two things:

a. It's not good programming. If I would ask to do the same for 11-die-prime, you would have to add code and recompile. But you can solve this pretty easily with indexing and arrays.

b. It's bad design. Try to figure out how long your program runs (a stop watch is fine) and try to understand how long it would take it to calculate the odds for 100-die-prime. This is where dynamic programming got you beat. While your program will perform at least 6^100 operations (hitting every possible combination of dice), dynamic programming will only do about 60,000x5=300,000 operations, and with some more work on the code, could probably do less. (The WHY 60,000x5 I'll leave for you to understand, or ask...)

If this whoe thread is interesting for you, take a probability course and a CS algorithms course. Dynamic Programming is usually taught there.

Avatar image for moistjohn
MoistJohn

279

Forum Posts

516

Wiki Points

0

Followers

Reviews: 3

User Lists: 5

#26  Edited By MoistJohn

@crusader8463

This is the mathematician in me, but you wrote 1+1=factorial(3)=6. And that's just wrong.

Avatar image for gkhan
gkhan

1192

Forum Posts

2

Wiki Points

0

Followers

Reviews: 0

User Lists: 4

#27  Edited By gkhan
@Slaker117: I see, I didn't check your calculations, I just assumed you used the random simulation method. Silly me :).  
  
Your method is fine if all you care about is the correct answer, but if I understand you right it's a much slower method. The way I understand your method is that you just go through all the combinations of all the dices, and that takes a long time, since there's about 60.5 million of them for ten dice (6^10). Mine only needs to fill in an array that's about 600 items big (number of dice*maximum number, or 10*60). I also assume it takes up a lot of very messy code :). Again though, I'm not sure if I understood your method correctly.  A computer can handle 60.5 million combinations, but what if you're trying to figure out the same thing with 100 dice? Or 10000? I don't think your program could handle that. 
 
So no, nothing improper with it at all really if you get the right answer. But there are "better" ways of doing it. 
Avatar image for slaker117
Slaker117

4873

Forum Posts

3305

Wiki Points

0

Followers

Reviews: 1

User Lists: 11

#28  Edited By Slaker117

@Marshmellow_Peep: Oh, trust me, I realized my solution was crap before I started to write it. I normally obsess about making things as dynamic as possible but this time I was just trying to re-familiarize myself with java and pump something out quickly. I just wanted to know that it was at least accurate. Thanks for the advice though!

Avatar image for example1013
Example1013

4854

Forum Posts

0

Wiki Points

0

Followers

Reviews: 0

User Lists: 0

#29  Edited By Example1013

@Marshmellow_Peep said:

@Slaker117 Your solution is basic but it works. the problem with it is two things: a. It's not good programming. If I would ask to do the same for 11-die-prime, you would have to add code and recompile. But you can solve this pretty easily with indexing and arrays. b. It's bad design. Try to figure out how long your program runs (a stop watch is fine) and try to understand how long it would take it to calculate the odds for 100-die-prime. This is where dynamic programming got you beat. While your program will perform at least 10^10 operarions (hitting every possible combination of dice), dynamic programming will only do about 60,000x5=300,000 operations (and i'll leave the Why for you to understand) If this whoe thread is interesting for you, take a probability course and a CS algorithms course. Dynamic Programming is usually taught there.

Yeah I was about to say, his program is incredibly inefficient. I can't say for sure as I don't know Java, but it looks like he's calculating a brand new array for each time the count increases. It looks like he's also using a recursive program, so every calculation is stored until they all resolve, which is much much much larger than this needs to be even before we go into the number of calculations being done.

Avatar image for slaker117
Slaker117

4873

Forum Posts

3305

Wiki Points

0

Followers

Reviews: 1

User Lists: 11

#30  Edited By Slaker117

@gkhan: @example1013: Yeah, refer to my above post and thanks for the input. Like I said, my training is mostly informal but I plan on taking classes to get some proper learning done.

And I think the important thing to remember here is that Dave can't read numbers. :P

Avatar image for gkhan
gkhan

1192

Forum Posts

2

Wiki Points

0

Followers

Reviews: 0

User Lists: 4

#31  Edited By gkhan
@Slaker117: Hey, you're way beyond most people in this thread, be proud of that! Hell, Whiskey Media has a bunch of engineers working for them, and none of them were able to figure it out ;)
Avatar image for tim_the_corsair
tim_the_corsair

3053

Forum Posts

0

Wiki Points

0

Followers

Reviews: 0

User Lists: 2

#32  Edited By tim_the_corsair

What's a prime number?

Avatar image for toxin066
Toxin066

3589

Forum Posts

118

Wiki Points

0

Followers

Reviews: 0

User Lists: 5

#33  Edited By Toxin066

@snide: Does the method of rolling matter? I've found that by using a cup (Yahtzee style), my drunk friends and I are a lot more capable of rolling ten dice at once than trying to roll them all by hand.

Avatar image for example1013
Example1013

4854

Forum Posts

0

Wiki Points

0

Followers

Reviews: 0

User Lists: 0

#34  Edited By Example1013

@Slaker117: Oh holy shit I just realized what a clusterfuck that code was lol. I didn't realize that those were all inside each other. Wow. You must have given your computer a decent workout on that one.

Avatar image for moistjohn
MoistJohn

279

Forum Posts

516

Wiki Points

0

Followers

Reviews: 3

User Lists: 5

#35  Edited By MoistJohn

@Toxin066 said:

@snide: Does the method of rolling matter? I've found that by using a cup (Yahtzee style), my drunk friends and I are a lot more capable of rolling ten dice at once than trying to roll them all by hand.

I think using a cup is perfectly legal. Just remember to drink the beer out first. No one likes wet dice. No one.

Avatar image for slaker117
Slaker117

4873

Forum Posts

3305

Wiki Points

0

Followers

Reviews: 1

User Lists: 11

#36  Edited By Slaker117

@example1013: Hey man, I warned you.

I'm actually surprised at how smoothly it handles in. The machine I'm on is like five or six years old and chugs when operating two windows at once, but the program terminates in like a quarter of a second without any fussing. 60 million calculations it can deal with, but not opening a browser at any sort of reasonable rate.

Avatar image for example1013
Example1013

4854

Forum Posts

0

Wiki Points

0

Followers

Reviews: 0

User Lists: 0

#37  Edited By Example1013

@Slaker117: You should put in some nonsense that will create an infinite loop and see how long it takes to crash the computer, though. Hopefully your editor/compiler has a limit to the memory it can use, otherwise you'd be fucked, but it's still an interesting test.

Avatar image for danieljw
DanielJW

4933

Forum Posts

8618

Wiki Points

0

Followers

Reviews: 2

User Lists: 8

#38  Edited By DanielJW

Next to nothing about this thread makes sense to me, yet I'm enamoured.

Avatar image for slaker117
Slaker117

4873

Forum Posts

3305

Wiki Points

0

Followers

Reviews: 1

User Lists: 11

#39  Edited By Slaker117

@example1013: Tried that the first night I learned about loops. The compiler has built in safeties, unfortunately.

Avatar image for xpgamer7
xpgamer7

2488

Forum Posts

148

Wiki Points

0

Followers

Reviews: 12

User Lists: 5

#41  Edited By xpgamer7

You guys are insane.

Avatar image for gkhan
gkhan

1192

Forum Posts

2

Wiki Points

0

Followers

Reviews: 0

User Lists: 4

#43  Edited By gkhan
@ChristianConservativeVinny said:

@snide said:

@Slaker117: I get that you've calculated the percentage per number but what would be the chance to throw one of the 13 primes? Also, no math whiz, but shouldn't those percentages add up to 100? A quick scan has them over 100% if added.

I'd also imagine that you'd have a pure bell curve between 10 and 60. Why do the ends have spikes (12,13,57,58)?

FWIW this quote demonstrates gaps in math and CS knowledge that should be grounds for firing you as a web designer, unless your job is strictly visual and you never touch a line of code. Now I'm wondering if there are really obvious ways to make the site faster.  
 
People who write glass code shouldn't throw stones. You're using the same method that I described earlier, but the code you've written is really, really bad. It spends endless amounts of time recalculating values it has already calculated, driving the running time up to 6^n. As has been written about fifty times already, you need to use dynamic programming. Specifically, in this case, it's very easy to use memoization to just save the previous results of the calculation. A small change to your code looks like this: 
 
The array previousResults obviously need to be initialized earlier and you have to make sure it's big enough to fit all the values. This is not the only way to do it, the best way would probably be and doing it in pure dynamic programming and go bottom-up instead of top-down. That gets rid of the recursion and saves a bunch of memory, but we don't need it right now. I did it this way because it's easy and it's reasonably clear what's going on.  
  
This small change I made to your code brings down the running time massively. Instead of having to deal with a horrendous complexity of O(6^n), we get the very managable O(n^2) (I leave it as an excercise to the reader to figure out why). Now you're code doesn't choke on just fifteen dice, you can literally make the calculation for thousands of dice (it wont give the right answer though, because the integers will overflow. for that many dice you'd need to convert it to using BigInteger, or calculate it mod something).  
 
Next time you critizise someone elses coding, make sure your own ducks are in a row.
Avatar image for green_incarnate
Green_Incarnate

1789

Forum Posts

124

Wiki Points

0

Followers

Reviews: 0

User Lists: 7

#45  Edited By Green_Incarnate

@example1013 said:

@Slaker117: Oh holy shit I just realized what a clusterfuck that code was lol. I didn't realize that those were all inside each other. Wow. You must have given your computer a decent workout on that one.

Brute forcing at its finest.

Avatar image for deactivated-59a31562f0e29
deactivated-59a31562f0e29

1212

Forum Posts

0

Wiki Points

0

Followers

Reviews: 0

User Lists: 0

And after all that maths, the hardest part of the game is still trying to add all the numbers on the dice up correctly when you're a bit drunk.

Avatar image for theunsavedhero
TheUnsavedHero

1325

Forum Posts

8

Wiki Points

0

Followers

Reviews: 1

User Lists: 3

#47  Edited By TheUnsavedHero

Goddamn. I think I'm gonna have to buy 10 dice and have a get together with friends later involving drinks, rowdiness, and mass amounts of one dolla bills that would make strippers flock.

Avatar image for mrklorox
MrKlorox

11220

Forum Posts

1071

Wiki Points

0

Followers

Reviews: 0

User Lists: 0

#48  Edited By MrKlorox

Someone needs to develop a phone app that can count the dots on the dice for you when wasted.

Avatar image for buzz_clik
buzz_clik

7590

Forum Posts

4259

Wiki Points

0

Followers

Reviews: 0

User Lists: 9

#49  Edited By buzz_clik

Seriously, I say this without any hint of sarcasm: this thread is fucking fascinating.

Avatar image for moistjohn
MoistJohn

279

Forum Posts

516

Wiki Points

0

Followers

Reviews: 3

User Lists: 5

#50  Edited By MoistJohn

@MrKlorox said:

Someone needs to develop a phone app that can count the dots on the dice for you when wasted.

hmmm.... that's a good idea. It doesn't sounds hard at all even. Use the camera to view the dice, some image processing to get the number on each die, sum and Bam !

I might give it a shot.