# Some mathematical problems

Discussion in 'Competitive Discussion' started by Great Sage, Sep 28, 2012.

1. ### Great Sage

Joined:
Jul 31, 2006
Messages:
6,661
Pokemon is at its heart a game of mathematics and statistics, and as such offers many problems of surprising mathematical complexity. I have gathered three such problems, each of which is hefty enough that I will guarantee a badge and possibly more to anyone who solves even one correctly and writes it up. I will accept and publish onsite any papers offering rigorously derived exact solutions; approximative solutions will be reviewed on a case-by-case basis. If you find that you are only able to solve part of a problem, please do submit that paper anyway. There are no reservations, and there is no rush; even if a problem has been solved, I will accept as equal any solution that uses a substantively different method, or that is sufficiently simpler and more elegant than a previously accepted solution. I may occasionally add further problems as they occur to me. So have at it, and remember to thoroughly understand all relevant game mechanics before tackling a problem. If any part of any problem appears unclear, please point it out to me, and I will change it.

Problem 1.
Suppose that there is a Pokemon with the ability Moody on the field, and is kept on the field for an arbitrary number of turns. This Pokemon initially has no stat boosts or drops, and experiences no stat boosts or drops except by the effect of Moody.

a) At the end of each turn, Moody will activate and change the Pokemon's stat distribution. For example, at the end of turn 1, the Pokemon will have +2 in one stat, -1 in another, and 0 in the five other stats. Calculate the probability distributions for an arbitrary stat's boost level (since no stat is unique, only one stat needs to be considered) at the end of turns 1 through 50. For example, the probability distribution for turn 1 is 1/7 for the -1 boost level, 1/7 for the +2 boost level, 5/7 for the 0 boost level, and 0 for any other boost level.

b) Calculate the probability distributions for Stored Power's base power corresponding to the Pokemon's boost distribution at the end of turns 1 through 50.

Problem 2. The first and second generations of Pokemon did not have EVs; instead, they had something similar, called stat experience. Since this is a less familiar topic, people considering this problem are strongly urged to read about the mechanics of stat experience before approaching it.

a) The first part of this problem is a project that requires research on the first and second generation games. Suppose that six Pokemon participate in a battle against a Chansey. Do each of the Pokemon gain 1 stat experience point in Attack, or 0 stat experience points in Attack?

b) Determine the minimum amount of Attack stat experience that may be earned while maximizing stat experience in every other stat in the following cases:
i) A generation 1 Pokemon in a generation 1 game that cannot be traded to be trained in a generation 2 game
ii) An arbitrary generation 1 Pokemon, with no special restrictions
iii) A generation 2 Pokemon (obviously, cannot be traded to a generation 1 game)
In all cases, do not consider any Pokemon that can only be battled by exploiting a glitch. Note that because of how the effects of stat experience are quantized, a stat is maximized once it reaches 63504 units of stat experience. For the same reason, instances like 14400 stat experience and 15375 stat experience are considered equivalent, because their effect is the same.

c) Repeat part b for each of the other stats, namely HP, Defense, Speed, and Special (note that Special Attack and Special Defense are conflated).

Problem 3. Consider a randomly generated EV spread that obeys the rules governing EV spreads.

a) Taking into account the quantization of EV spreads (18 EVs and 16 EVs are equivalent, for example), calculate the number of distinct EV spreads possible in the following conditions.
i) The EV spread totals to 510 EVs.
ii) The EV spread may total to any positive integer not greater than 510 EVs.

b)Calculate the probability distribution for EVs for a particular stat (that is, determine the probability that a given stat will have 0 EVs, 1 EV, 2 EVs, up through 255 EVs) in the following conditions:
i) The EV spread totals to 510 EVs.
ii) The EV spread may total to any positive integer not greater than 510 EVs.

Note: Problem 3 derives substantially from a conversation I had with Antar about distributions of EV spreads in Challenge Cup.
Grey Knight likes this.
2. ### brehB)

Joined:
Feb 6, 2010
Messages:
3,006
On problem 2 (b.iii and b.ii):

For b)i:

Because of Chansey's stats, all you need is a mon that gives the best defense per attack (the rest is not relevant; even compared to a base 10 Attack Pokemon, Chansey has effective stats of 500/10/10/70/100). This Pokemon happens to be, ironically, Magikarp. Running a program similar to the one above but with different equations results in an output of 668a*2 and 117b, meaning that you need to fight 1336 Chansey and 117 Magikarp to complete your training. The end stat spread is 71860 7850 37910 37930 65140, with Defense taking the longest to approach.

This solution is similarly trivialized if stat exp. is floored and the sole problem becomes the sheer amount of time that it will take to encounter those Chansey (granted, it's over a 25% chance to encounter them in RB anyway). I'd assume fishing isn't the most speedy (granted, reliable) method of encountering Magikarp either, lol.

c)

HP:
Diglett is far and away the most efficient mon for HP; it has 20/110/50/90/190 stats after a simple double, meaning that it's really efficient outside of Defense. In RB, Onix is used; in GSC, Shuckle is used. Yet again, the solution is trivialized with floor.

Def:
Chansey is used, but needs more Attack. In RB, Meowth is used (unfortunately, Jynx can't be); in GSC, Smoochum is used. The solution is nearly trivialized by floor, but not entirely. With floor, Abra is used in RB and Igglybuff is used in GSC (for the sake of quicker stat gain).

I'll edit in Special (which is a clusterfuck) and Speed.
3. ### alkinesthetase<@dtc> every day with alk is a bad dayMentor

Joined:
Nov 8, 2010
Messages:
817
aww man i feel like it's a contest now and it's pretty much guaranteed that someone on smogon is both smarter and faster than i am. pretty sure the moody problem can be handled by an iterative probability system like a markov chain; should be elementary to calculate. this should be a great introduction to the concept. i'll try to do it in matlab, which should be able to handle exponentiation of matrices like a boss.

disclaimer: i'm actually not a statistician or a probability expert. i'm not even in pure math - i'm studying compsci at uni lol. but i learned this technique a while ago and it fits problem 1a like a glove.

assemble the transition matrix which is the chance for the arbitrary stat to proceed from stage m to stage n after a single iteration of the probability system (ie after one turn). for any stage m there is a 1/7 chance to move to stage m+2, 1/7 chance to move to stage m-1, 5/7 chance to remain at stage m. this gives rise to the following probability matrix (excel is SO much easier to do this in than code tags, sorry)

EDIT: GS has pointed out that this matrix had a mistake, so i have corrected it in a later post below

the row is the stage you start with, and the column is the stage that you can end up on. as an example, suppose we start at stage +3 (row 11 of the excel worksheet, but it would be row 10 of the actual matrix). looking at the row confirms what we would expect: we have a 1/7th chance to drop to +2 , 1/7th chance to go up to +5, or 5/7th chance to remain at +3. the chance of us going to ANY other stage is zero, for this turn.

then we multiply this matrix by the starting condition, which is a series of probabilities in a row vector where each cell of the vector is your probability of starting at that state. since you start at stage +0, you have a 100% chance to be at stage +0 at the start of the system (ie turn 0), and 0% chance everywhere else. thus our row vector has a 1.0 in the middle at column 7 (100% chance) and zero everywhere else.

now suppose T is the transition matrix, S is the start condition vector. S*(T^n) is a row vector containing the probabilities of each stage, after n turns of boostage. it should be fairly easy to see why this works: the system is time homogeneous (meaning that the transition matrix probabilities do not change, decay or grow after successive iterations). each time we do S*T, we get a new row vector, which is the starting condition for the NEXT turn, so we multiply that by T to get S*T*T, etc etc. each time the probabilities change for our new starting condition, and we can keep multiplying by T over and over until we get the number of iterations desired.

i will edit once i have the calculations, and i will glady write this in a more professional way if desired (i'd love it if this was published onsite and i will polish it up to whatever standard is needed so just lmk, but i'm not exactly a professional mathematician so i won't be writing papers anywhere near the quality of x-act), but anyway i learned this probability technique a long time ago and thought it was cool, so might as well contribute

EDIT: awwwright, our row vector is:
Code:
```8674825117050085/1152921504606846976,
7743151012810585/1152921504606846976,
3627563425338947/288230376151711744,
2312592620047591/144115188075855872,
3344030100494847/144115188075855872,
69412157321817/2251799813685248,
6052897625580961/144115188075855872,
1024673109570561/18014398509481984,
1430451748402361/18014398509481984,
8260983910292807/72057594037927936,
3114511042474259/18014398509481984,
4880822812909225/18014398509481984,
2996452925599639/18014398509481984```
believe it or not, these 13 numbers add up to 1, so in decimal terms, they are:
Code:
```-6: 0.00752421139027002
-5: 0.00671611291997806
-4: 0.0125856388690606
-3: 0.0160468348334691
-2: 0.0232038700788060
-1: 0.0308251900990340
+0: 0.0420004144351183
+1: 0.0568807839479746
+2: 0.0794060233345806
+3: 0.114644181790813
+4: 0.172890093490211
+5: 0.270940093300377
+6: 0.166336551510307```
interesting how heavily it gravitates towards the top, eh? 27% chance of being at a +5 in our arbitrary stat, after some 50 turns. this does kind of make sense, that the probabilities would collect around +5. moody boosts a stat faster than it shrinks it so naturally stats would grow aggressively, but if you get to +6, you have nowhere to go but down, so the longer you remain at +6, the more times you'll have to roll for losing a stat. yet if you drop to +4 you suddenly regain the ability to go back up to +6 so your odds of staying at +4 are reduced.

the cool thing about this technique is that it is very scalable. suppose our victim got nailed by memento before coming in and getting moody boosts; what are the adjusted probabilities for its attack stats? easy, we can change the starting condition vector to reflect that the stats start somewhere else. we can also extend the system to 100 or even 1000 turns; computation would get rather intense but the math is still all correct and holds up no matter how far you stretch the numbers.

anyway for maximum data awesomeness, i will make an excel worksheet containing all the possible distributions from turn 0 (100% chance of being at +0) to turn 50. just lemme wrangle out some matlab data type shit first
EDIT: here is the delicious excel worksheet i promised: [see below]

i will now get to work on computing stored power distributions based on the stage boosts in the matrices i have. i take it we're now concerned with all six stats, right? that might be beyond my mathematical capability because now we have to consider the possibility that
a) a stat is boosted that does not affect stored power (accuracy, evasion)
b) a stat is lowered after it is raised (lowering stats that are not raised has no effect on stored power, but reducing the extent of a boost will)
c) acknowledging that no stat is raised or lowered in a vacuum (ie for one to go up, another must go down)
i don't know if i know the probability techniques needed to analyze that system. i will give it my best shot though; this probability data is available for anyone else who does know (although i imagine that if you know how to solve this system, you'd have an easy as shit time finding the probabilities across one stat yourself =P)

EDIT: in the vein of scalability, i decided to start computing for ridiculously large number of turns to see what happened. i am surprised to say that the system begins to stabilize at the probability distribution of:
Code:
```-6: 0.00215053763440122
-5: 0.00215053763440122
-4: 0.00430107526880244
-3: 0.00645161290320366
-2: 0.0107526881720061
-1: 0.0172043010752098
+0: 0.0279569892472159
+1: 0.0451612903224256
+2: 0.0731182795696414
+3: 0.118279569892067
+4: 0.191397849461708
+5: 0.309677419353775
+6: 0.191397849461708
```
i started noticing the stabilization when i jumped from 100 turns to 1000 turns and then from 1000 to 1 hundred thousand. there was like no observable change to four significant digits between 1k and 100k turns, so experimentally speaking, this leads me to believe that the system approaches this probability distribution as the turn count approaches infinity. i went up to a million and matlab started attaching a +0.00i to the end because the differences were so small that it must have been bleeding off precision error into the complex component of the numbers. i changed the start condition vector and computed again to 10000 turns; the system was the same as the one above. thus the system begins to approach that distribution regardless of starting condition, if you leave it long enough.

in the interest of further exploring the behavior of the system as n->infinity, i have created a second excel sheet to replace the first one, going out to 500 turns instead of a measly 50. excel shows me the numbers to roughly six-place precision. the lowest change i saw was from cell G391 to G392, so after turn 390, the change from turn to turn is so small that it's lost in the imprecision of the numbers displayed. after turn 390 the probability distribution is effectively constant. here is the sheet: [see my post further below]

EDIT: sigh. looks like the only way i know of to emulate the stochastic process across all six stats is to compute a markov chain with a state for every possible arrangement of stat boosts. with 7 boostable stats that can each occupy 13 stages, i think this is 91 (7*13) cases but it might be a much bigger number if i'm being dumb.... this is not gonna be fun

EDIT: yeah the number is more like 13^7=over 62 million cases, i don't think i've got any clever tricks for 1b.
4. ### poccil

Joined:
Jun 18, 2007
Messages:
402

The answer seems to be 246,774,528 different combinations.

The answer seems to be 6,137,312,896 different combinations.

I wrote the following program to find it out. Please tell me if I did something wrong.

Code:
```using System;

class Program {
public static void Main(){
long count=0;
long count2=0;
for(var i=0;i<=63;i++){
for(var j=0;j<=63;j++){
for(var k=0;k<=63;k++){
var curtot=i*4+j*4+(k<<2);
for(var m=0;m<=63;m++){
var curtot2=curtot+(m<<2);
for(var n=0;n<=63;n++){
var total=curtot2+(n<<2);
if(total<=508 && total+252>=508){
count2++;
}
if(total+252<=508){
count+=64;continue;
}
var remain=(508-total)/4;
if(remain<0)break;
count+=remain+1;
if(total>508)break;
}
if(curtot2>508)break;
}
if(curtot>508)break;
}
}}
Console.WriteLine(count2);
Console.WriteLine(count);
}}
```
I choose to answer question 3(b)(i) differently, to assume further that each EV can only be a multiple of 4, as only those EVs are useful in stat calculation. The probability distribution is as follows:
Code:
```0: 7884240 3.19491645426225%
4: 7755280 3.14265822443393%
8: 7624176 3.08953118532558%
12: 7491120 3.03561314075333%
16: 7356300 2.98098027362046%
20: 7219900 2.92570714591743%
24: 7082100 2.86986669872184%
28: 6943076 2.81353025219848%
32: 6803000 2.75676750559928%
36: 6662040 2.69964653726336%
40: 6520360 2.64223380461698%
44: 6378120 2.58459414417358%
48: 6235476 2.52679077153376%
52: 6092580 2.46888528138528%
56: 5949580 2.41093764750307%
60: 5806620 2.35300622274921%
64: 5663840 2.29514773907297%
68: 5521376 2.23741730751077%
72: 5379360 2.17986841818618%
76: 5237920 2.12255294030995%
80: 5097180 2.06552112218%
84: 4957260 2.0088215911814%
88: 4818276 1.9525013537864%
92: 4680340 1.89660579555439%
96: 4543560 1.84117868113195%
100: 4408040 1.78626215425281%
104: 4273880 1.73189673773786%
108: 4141176 1.67812133349517%
112: 4010020 1.62497322251995%
116: 3880500 1.57248806489461%
120: 3752700 1.52069989978868%
124: 3626700 1.4696411454589%
128: 3502576 1.41934259924914%
132: 3380400 1.36983343759045%
136: 3260240 1.32114121600103%
140: 3142160 1.27329186908626%
144: 3026220 1.22630971053868%
148: 2912476 1.18021743313799%
152: 2800980 1.13503610875106%
156: 2691780 1.09078518833192%
160: 2584920 1.04748250192175%
164: 2480440 1.00514425864893%
168: 2378376 0.963785046728972%
172: 2278760 0.923417833464562%
176: 2181620 0.884053965245554%
180: 2086980 0.845703167548962%
184: 1994860 0.808373544938966%
188: 1905276 0.772071581066908%
192: 1818240 0.736802138671298%
196: 1733760 0.702568459577805%
200: 1651840 0.669372164699268%
204: 1572480 0.637213254035684%
208: 1495676 0.606090106674219%
212: 1421420 0.5759994807892%
216: 1349700 0.546936513642121%
220: 1280500 0.518894721581637%
224: 1213800 0.49186600004357%
228: 1149576 0.465840623550904%
232: 1087800 0.440807245713788%
236: 1028440 0.416752899229535%
240: 971460 0.393662995882622%
244: 916820 0.371521326544691%
248: 864476 0.350310061174547%
252: 814380 0.33000974881816%
```
5. ### Great Sage

Joined:
Jul 31, 2006
Messages:
6,661
alkinesthetase: as far as I know, Moody can choose to boost a stat from +5 to +6, so row 13 of your matrix will have to be adjusted.

poccil: You cannot make that simplifying assumption for 3bi. By restricting an EV spread to having EVs that are multiples of 4, you disregard the existence of EV spreads like 83/83/83/83/83/95, which is functionally equivalent to 80/80/80/80/80/92; as I understand it, your calculation would not take into account EV spreads that are functionally equivalent to 4-multiple EV spreads totaling fewer than 508 EVs.
6. ### alkinesthetase<@dtc> every day with alk is a bad dayMentor

Joined:
Nov 8, 2010
Messages:
817
hmm i see, gimme a sec to upload some corrected data

EDIT: ite, looking good. i corrected the row for +5 boost, so that the chance of remaining at +5 was reduced to 5/7, and the chance to go to +6 was increased to 1/7. the result, after 50 turns, is the distribution below:
Code:
```0.0075006
0.0066714
0.012465
0.015758
0.022536
0.02936
0.038932
0.050735
0.067583
0.092715
0.13351
0.20218
0.32005```
as you can see, still biased towards the top. however +5 now has a chance to transition into +6, meaning that the chance of attaining +6 increases dramatically (because now it can be reached from +4 or +5 as opposed to only +4), where as the +5 distribution drops accordingly.

scrolling through my excel sheet, i found that the probability distribution stabilized at the 472nd turn out of 500. 472/500 is really not very meaningful - it's quite close to the end of the set that i tested, so there's a real possibility that it keeps changing shortly after 500. in other words, this adjusted transition matrix probably takes a bit longer to reach a steady state than before. i did some anecdotal checks on the thousandth and ten thousandth turns and it seemed to be stabilizing, pretty damn close to the 500th turn really (difference is in like the 6th or 7th decimal place, so you have to wonder if it really matters)

worksheet from 0 to 500 is here with corrections implemented. here is my matlab matrix file containing the start condition, transition and 0-500 output matrices, and here is the script file i used to construct it (the script is pretty crappy, yes i am not too good with matlab). those files should come in handy for anyone else who wants to play with this probability system and happens to have a matlab license of their own. there's basically no way to do this without a computer algebra system anyway (exponentiating matrices of this size to the fiftieth power is beyond any free system afaik - you could write it yourself?) and the .mat format is widely accepted for matrix-formatted data.

i still have nothing for 1b, by the way. it would require simulating a stochastic process of seven variables (based on my limited knowledge of probability theory), because attempting to markov chain it requires a system of 13^7 states - ridiculous for any regular computer. i might get the chance to ask my profs about it on monday and see if they can direct me to some useful tools, but for now someone else will have to pick that part up. if anyone has any ideas or hints please reply/VM me, i love this theoretical math stuff so i'd be glad to look into it and apply it to this problem

finally, if this part of the solution is satisfactory, i'd be glad to write it up in some kind of formal pdf that presents it a bit more professionally than an all-lowercase forum post, but i'd prefer to do so after receiving any further corrections

Joined:
Apr 14, 2009
Messages:
3,073
1b: use 1a.

All that needs to be checked is if a 'positive' stat is selected to be lowered.

For that, we need to know the probability for m stats to be 'positive' on turn n. (where 'positive' means a positive amount of stat boosts if that wasn't clear)

You have the probability for a stat to be at +x stat boosts on turn n. The sum of those probabilities where x is pure is the probability for that stat to be 'positive' on turn n. If we're looking at 50 turns, we arrive at 50 probabilities, p1 through p50.

... Now I'm not so sure. If we simply calculate the distributions with Binomial(i,p(i)) for each turn i, we'll get impossible results (such as the probability for m=0 during any turn i>0 isn't 0, which is false). If we choose to ignore m=0 for i>0, and m=1 for i>3, does it work out? I don't think it does. I'm dumb. Like with what I did below, assuming a stat was already picked, the probability of it being positive is p(i), so that's all we need. Now to see if this is still a problem...

Mmm, actually, no, regardless of that, we need to check one more thing: if the stat being raised is at +5. That seems simple enough, though - the possibility of the stat having +5 on turn i is taken directly from 1a.

Now that I've actually thought this through, even after the above, you need to split it into a few parts; if a positive stat was lowered, that probably changes a bunch of things for the next turn. Probably. Ugh.

EDIT: There's a very good chance that none of this works. Whatever.
8. ### ganj4lFNobody is safe from the power of science!

Joined:
Jun 11, 2011
Messages:
747
@alkinesthetase: ha, great work man! I attended a course on Markov Chains last semester (I'm studying computer engineering), and just wanted to point out that you don't need to simulate the chain's behavior for high number of turns to see what it does when the number of turns tend to be infinite; you can get the exact limiting distribution by solving a system of equations, like described here:

In your case, you should solve this:

and you'll probably find something very close to your distribution for some million turns. I would solve it myself, but I'm kinda lazy and don't have Matlab available at the moment, it shouldn't be difficult to solve with it anyway...

EDIT: wow, the image is kinda huge, sorry about that.
9. ### SlimMan

Joined:
Aug 28, 2010
Messages:
1,475
Cool. I'm gonna try my hand a #2 later, I think.

But I'm curious about something, GS. These problems look hella tough for sure, but what makes them worth a badge? I mean, knowing high-level mathematics is a useful thing, but I don't understand how it benefits Smogon or otherwise earns one. Is it the "very intelligent person" badge, or a pre-existing one? This thread just gives me a vibe like it was done on a whim.

That aside, I better get to work on this! :P
10. ### poccil

Joined:
Jun 18, 2007
Messages:
402
I can now properly give a solution to Problem 3(b):

Problem 3(b)(i):
Code:
```0: 1972723776 0.821904909925356%
1: 1964335040 0.818409872561105%
2: 1955913920 0.814901342903139%
3: 1947461180 0.811379639260265%
4: 1938977580 0.807845078274753%
5: 1930463876 0.804297974922331%
6: 1921920820 0.800738642512193%
7: 1913349160 0.797167392686991%
8: 1904749640 0.793584535422842%
9: 1896123000 0.789990379029323%
10: 1887469976 0.786385230149472%
11: 1878791300 0.78276939375979%
12: 1870087700 0.77914317317024%
13: 1861359900 0.775506870024245%
14: 1852608620 0.771860784298693%
15: 1843834576 0.76820521430393%
16: 1835038480 0.764540456683766%
17: 1826221040 0.760866806415472%
18: 1817382960 0.757184556809781%
19: 1808524940 0.753493999510888%
20: 1799647676 0.749795424496449%
21: 1790751860 0.746089120077582%
22: 1781838180 0.742375372898867%
23: 1772907320 0.738654467938346%
24: 1763959960 0.734926688507522%
25: 1754996776 0.731192316251361%
26: 1746018440 0.727451631148289%
27: 1737025620 0.723704911510194%
28: 1728018980 0.719952433982428%
29: 1718999180 0.716194473543802%
30: 1709966876 0.712431303506591%
31: 1700922720 0.708663195516528%
32: 1691867360 0.704890419552814%
33: 1682801440 0.701113243928105%
34: 1673725600 0.697331935288523%
35: 1664640476 0.693546758613651%
36: 1655546700 0.689757977216533%
37: 1646444900 0.685965852743675%
38: 1637335700 0.682170645175045%
39: 1628219720 0.678372612824072%
40: 1619097576 0.674572012337648%
41: 1609969880 0.670769098696125%
42: 1600837240 0.666964125213319%
43: 1591700260 0.663157343536507%
44: 1582559540 0.659349003646425%
45: 1573415676 0.655539353857275%
46: 1564269260 0.651728640816718%
47: 1555120880 0.647917109505878%
48: 1545971120 0.64410500323934%
49: 1536820560 0.64029256366515%
50: 1527669776 0.636480030764819%
51: 1518519340 0.632667642853315%
52: 1509369820 0.628855636579073%
53: 1500221780 0.625044246923984%
54: 1491075780 0.621233707203406%
55: 1481932376 0.617424249066155%
56: 1472792120 0.613616102494511%
57: 1463655560 0.609809495804215%
58: 1454523240 0.60600465564447%
59: 1445395700 0.602201806997939%
60: 1436273476 0.59840117318075%
61: 1427157100 0.59460297584249%
62: 1418047100 0.590807434966208%
63: 1408944000 0.587014768868417%
64: 1399848320 0.58322519419909%
65: 1390760576 0.57943892594166%
66: 1381681280 0.575656177413026%
67: 1372610940 0.571877160263546%
68: 1363550060 0.568102084477039%
69: 1354499140 0.564331158370787%
70: 1345458676 0.560564588595534%
71: 1336429160 0.556802580135487%
72: 1327411080 0.55304533630831%
73: 1318404920 0.549293058765135%
74: 1309411160 0.545545947490551%
75: 1300430276 0.54180420080261%
76: 1291462740 0.538068015352827%
77: 1282509020 0.534337586126177%
78: 1273569580 0.530613106441099%
79: 1264644880 0.526894767949491%
80: 1255735376 0.523182760636715%
81: 1246841520 0.519477272821593%
82: 1237963760 0.51577849115641%
83: 1229102540 0.512086600626913%
84: 1220258300 0.508401784552309%
85: 1211431476 0.504724224585268%
86: 1202622500 0.501054100711922%
87: 1193831800 0.497391591251864%
88: 1185059800 0.49373687285815%
89: 1176306920 0.490090120517295%
90: 1167573576 0.486451507549279%
91: 1158860180 0.482821205607542%
92: 1150167140 0.479199384678986%
93: 1141494860 0.475586213083974%
94: 1132843740 0.471981857476332%
95: 1124214176 0.468386482843348%
96: 1115606560 0.46480025250577%
97: 1107021280 0.46122332811781%
98: 1098458720 0.457655869667139%
99: 1089919260 0.454098035474892%
100: 1081403276 0.450549982195665%
101: 1072911140 0.447011864817516%
102: 1064443220 0.443483836661964%
103: 1055999880 0.43996604938399%
104: 1047581480 0.436458652972038%
105: 1039188376 0.432961795748011%
106: 1030820920 0.429475624367277%
107: 1022479460 0.426000283818664%
108: 1014164340 0.422535917424462%
109: 1005875900 0.419082666840422%
110: 997614476 0.415640672055758%
111: 989380400 0.412210071393144%
112: 981174000 0.408791001508719%
113: 972995600 0.40538359739208%
114: 964845520 0.401987992366288%
115: 956724076 0.398604318087866%
116: 948631580 0.395232704546796%
117: 940568340 0.391873280066526%
118: 932534660 0.388526171303961%
119: 924530840 0.385191503249472%
120: 916557176 0.381869399226889%
121: 908613960 0.378559980893504%
122: 900701480 0.375263368240073%
123: 892820020 0.371979679590811%
124: 884969860 0.368709031603396%
125: 877151276 0.365451539268968%
126: 869364540 0.362207315912128%
127: 861609920 0.35897647319094%
128: 853887680 0.355759121096927%
129: 846198080 0.352555367955077%
130: 838541376 0.349365320423838%
131: 830917820 0.346189083495121%
132: 823327660 0.343026760494296%
133: 815771140 0.339878453080197%
134: 808248500 0.33674426124512%
135: 800759976 0.333624283314823%
136: 793305800 0.330518615948522%
137: 785886200 0.3274273541389%
138: 778501400 0.324350591212099%
139: 771151620 0.321288418827722%
140: 763837076 0.318240926978835%
141: 756557980 0.315208203991966%
142: 749314540 0.312190336527104%
143: 742106960 0.309187409577701%
144: 734935440 0.306199506470668%
145: 727800176 0.30322670886638%
146: 720701360 0.300269096758675%
147: 713639180 0.297326748474848%
148: 706613820 0.294399740675662%
149: 699625460 0.291488148355336%
150: 692674276 0.288592044841554%
151: 685760440 0.285711501795461%
152: 678884120 0.282846589211664%
153: 672045480 0.279997375418231%
154: 665244680 0.277163927076693%
155: 658481876 0.274346309182041%
156: 651757220 0.271544585062729%
157: 645070860 0.268758816380673%
158: 638422940 0.26598906313125%
159: 631813600 0.263235383643298%
160: 625242976 0.260497834579118%
161: 618711200 0.257776470934474%
162: 612218400 0.255071346038588%
163: 605764700 0.252382511554147%
164: 599350220 0.249710017477299%
165: 592975076 0.247053912137652%
166: 586639380 0.244414242198279%
167: 580343240 0.241791052655711%
168: 574086760 0.239184386839944%
169: 567870040 0.236594286414434%
170: 561693176 0.2340207913761%
171: 555556260 0.23146394005532%
172: 549459380 0.228923769115936%
173: 543402620 0.226400313555253%
174: 537386060 0.223893606704035%
175: 531409776 0.221403680226508%
176: 525473840 0.218930564120362%
177: 519578320 0.216474286716747%
178: 513723280 0.214034874680275%
179: 507908780 0.211612353009019%
180: 502134876 0.209206745034516%
181: 496401620 0.206818072421763%
182: 490709060 0.204446355169218%
183: 485057240 0.202091611608802%
184: 479446200 0.199753858405899%
185: 473875976 0.197433110559352%
186: 468346600 0.195129381401467%
187: 462858100 0.192842682598013%
188: 457410500 0.190573024148218%
189: 452003820 0.188320414384775%
190: 446638076 0.186084859973835%
191: 441313280 0.183866365915014%
192: 436029440 0.181664935541388%
193: 430786560 0.179480570519496%
194: 425584640 0.177313270849337%
195: 420423676 0.175163034864374%
196: 415303660 0.173029859231529%
197: 410224580 0.170913738951189%
198: 405186420 0.168814667357199%
199: 400189160 0.166732636116869%
200: 395232776 0.164667635230969%
201: 390317240 0.162619653033732%
202: 385442520 0.160588676192851%
203: 380608580 0.158574689709482%
204: 375815380 0.156577676918243%
205: 371062876 0.154597619487212%
206: 366351020 0.152634497417931%
207: 361679760 0.150688289045402%
208: 357049040 0.14875897103809%
209: 352458800 0.146846518397921%
210: 347908976 0.144950904460282%
211: 343399500 0.143072100894024%
212: 338930300 0.141210077701458%
213: 334501300 0.139364803218357%
214: 330112420 0.137536244113956%
215: 325763576 0.135724365390952%
216: 321454680 0.133929130385502%
217: 317185640 0.132150500767228%
218: 312956360 0.13038843653921%
219: 308766740 0.128642896037994%
220: 304616676 0.126913835933583%
221: 300506060 0.125201211229445%
222: 296434780 0.123504975262509%
223: 292402720 0.121825079703165%
224: 288409760 0.120161474555267%
225: 284455776 0.118514108156127%
226: 280540640 0.116882927176522%
227: 276664220 0.11526787662069%
228: 272826380 0.113668899826329%
229: 269026980 0.112085938464601%
230: 265265876 0.110518932540128%
231: 261542920 0.108967820390996%
232: 257857960 0.10743253868875%
233: 254210840 0.105913022438398%
234: 250601400 0.104409204978411%
235: 247029476 0.102921017980719%
236: 243494900 0.101448391450717%
237: 239997500 0.0999912537272581%
238: 236537100 0.0985495314826606%
239: 233113520 0.0971231497227024%
240: 229726576 0.0957120317866238%
241: 226376080 0.0943160993471269%
242: 223061840 0.0929352724103754%
243: 219783660 0.0915694693159947%
244: 216541340 0.0902186067370721%
245: 213334676 0.0888825996801567%
246: 210163460 0.0875613614852591%
247: 207027480 0.0862548038258518%
248: 203926520 0.084962836708869%
249: 200860360 0.0836853684747067%
250: 197828776 0.0824223057972225%
251: 194831540 0.081173553683736%
252: 191868420 0.0799390154750284%
253: 188939180 0.0787185928453425%
254: 186043580 0.0775121858023831%
255: 183181376 0.0763196926873166%
```
Problem 3(b)(ii):

Code:
```0: 249360742848 1.0826141109353%
1: 247388019072 1.0740494163788%
2: 245423684032 1.06552114200562%
3: 243467770112 1.05702942841276%
4: 241520308932 1.0485744128803%
5: 239581331352 1.0401562293887%
6: 237650867476 1.03177500863624%
7: 235728946656 1.0234308780563%
8: 233815597496 1.01512396183483%
9: 231910847856 1.00685438092763%
10: 230014724856 0.998622253077733%
11: 228127254880 0.990427692832819%
12: 226248463580 0.982270811562529%
13: 224378375880 0.974151717475852%
14: 222517015980 0.966070515638491%
15: 220664407360 0.958027307990225%
16: 218820572784 0.950022193362278%
17: 216985534304 0.942055267494688%
18: 215159313264 0.934126623053666%
19: 213341930304 0.926236349648968%
20: 211533405364 0.918384533851259%
21: 209733757688 0.910571259209479%
22: 207943005828 0.902796606268213%
23: 206161167648 0.89506065258505%
24: 204388260328 0.887363472747955%
25: 202624300368 0.879705138392635%
26: 200869303592 0.872085718219903%
27: 199123285152 0.864505278013044%
28: 197386259532 0.856963880655183%
29: 195658240552 0.849461586146651%
30: 193939241372 0.84199845162235%
31: 192229274496 0.834574531369121%
32: 190528351776 0.827189876843108%
33: 188836484416 0.819844536687126%
34: 187153682976 0.812538556748027%
35: 185479957376 0.805271980094066%
36: 183815316900 0.798044847032267%
37: 182159770200 0.790857195125788%
38: 180513325300 0.783709059211291%
39: 178875989600 0.776600471416304%
40: 177247769880 0.769531461176591%
41: 175628672304 0.762502055253513%
42: 174018702424 0.755512277751401%
43: 172417865184 0.748562150134918%
44: 170826164924 0.741651691246424%
45: 169243605384 0.734780917323346%
46: 167670189708 0.727949842015543%
47: 166105920448 0.721158476402671%
48: 164550799568 0.714406829011548%
49: 163004828448 0.707694905833525%
50: 161468007888 0.701022710341849%
51: 159940338112 0.694390243509028%
52: 158421818772 0.6877975038242%
53: 156912448952 0.681244487310498%
54: 155412227172 0.674731187542417%
55: 153921151392 0.668257595663177%
56: 152439219016 0.661823700402096%
57: 150966426896 0.655429488091948%
58: 149502771336 0.649074942686335%
59: 148048248096 0.642760045777052%
60: 146602852396 0.636484776611452%
61: 145166578920 0.630249112109813%
62: 143739421820 0.624053026882704%
63: 142321374720 0.617896493248351%
64: 140912430720 0.611779481250005%
65: 139512582400 0.605701958673306%
66: 138121821824 0.599663891063651%
67: 136740140544 0.593665241743558%
68: 135367529604 0.587705971830033%
69: 134003979544 0.58178604025194%
70: 132649480404 0.575905403767361%
71: 131304021728 0.570064016980966%
72: 129967592568 0.564261832361379%
73: 128640181488 0.558498800258544%
74: 127321776568 0.55277486892109%
75: 126012365408 0.547089984513698%
76: 124711935132 0.541444091134469%
77: 123420472392 0.535837130832288%
78: 122137963372 0.53026904362419%
79: 120864393792 0.524739767512727%
80: 119599748912 0.519249238503337%
81: 118344013536 0.513797390621704%
82: 117097172016 0.50838415593113%
83: 115859208256 0.503009464549899%
84: 114630105716 0.497673244668643%
85: 113409847416 0.492375422567707%
86: 112198415940 0.487115922634519%
87: 110995793440 0.481894667380953%
88: 109801961640 0.476711577460695%
89: 108616901840 0.471566571686614%
90: 107440594920 0.466459567048121%
91: 106273021344 0.46139047872854%
92: 105114161164 0.456359220122474%
93: 103963994024 0.45136570285317%
94: 102822499164 0.446409836789884%
95: 101689655424 0.441491530065251%
96: 100565441248 0.436610689092649%
97: 99449834688 0.431767218583563%
98: 98342813408 0.426961021564956%
99: 97244354688 0.422191999396632%
100: 96154435428 0.417460051788602%
101: 95073032152 0.412765076818452%
102: 94000121012 0.408106970948709%
103: 92935677792 0.403485629044207%
104: 91879677912 0.39890094438945%
105: 90832096432 0.394352808705984%
106: 89792908056 0.38984111216976%
107: 88762087136 0.3853657434285%
108: 87739607676 0.380926589619064%
109: 86725443336 0.376523536384816%
110: 85719567436 0.37215646789299%
111: 84721952960 0.367825266852058%
112: 83732572560 0.363529814529093%
113: 82751398560 0.359269990767137%
114: 81778402960 0.355045674002569%
115: 80813557440 0.350856741282468%
116: 79856833364 0.346703068281981%
117: 78908201784 0.342584529321689%
118: 77967633444 0.338500997384973%
119: 77035098784 0.334452344135381%
120: 76110567944 0.330438439933992%
121: 75194010768 0.326459153856787%
122: 74285396808 0.322514353712009%
123: 73384695328 0.318603906057533%
124: 72491875308 0.314727676218233%
125: 71606905448 0.310885528303344%
126: 70729754172 0.307077325223835%
127: 69860389632 0.303302928709767%
128: 68998779712 0.299562199327667%
129: 68144892032 0.295854996497889%
130: 67298693952 0.292181178511981%
131: 66460152576 0.288540602550054%
132: 65629234756 0.284933124698145%
133: 64805907096 0.281358599965587%
134: 63990135956 0.277816882302369%
135: 63181887456 0.27430782461651%
136: 62381127480 0.270831278791419%
137: 61587821680 0.267387095703264%
138: 60801935480 0.263975125238338%
139: 60023434080 0.260595216310426%
140: 59252282460 0.257247216878167%
141: 58488445384 0.253930973962428%
142: 57731887404 0.250646333663662%
143: 56982572864 0.24739314117928%
144: 56240465904 0.244171240821015%
145: 55505530464 0.240980476032287%
146: 54777730288 0.237820689405572%
147: 54057028928 0.234691722699767%
148: 53343389748 0.231593416857555%
149: 52636775928 0.228525612022773%
150: 51937150468 0.225488147557778%
151: 51244476192 0.222480862060812%
152: 50558715752 0.219503593383369%
153: 49879831632 0.216556178647562%
154: 49207786152 0.213638454263489%
155: 48542541472 0.210750255946596%
156: 47884059596 0.20789141873505%
157: 47232302376 0.205061777007097%
158: 46587231516 0.202261164498436%
159: 45948808576 0.199489414319579%
160: 45316994976 0.196746358973222%
161: 44691752000 0.194031830371607%
162: 44073040800 0.191345659853893%
163: 43460822400 0.188687678203516%
164: 42855057700 0.186057715665563%
165: 42255707480 0.18345560196413%
166: 41662732404 0.180881166319696%
167: 41076093024 0.178334237466482%
168: 40495749784 0.175814643669824%
169: 39921663024 0.173322212743533%
170: 39353792984 0.170856772067267%
171: 38792099808 0.168418148603892%
172: 38236543548 0.166006168916853%
173: 37687084168 0.163620659187535%
174: 37143681548 0.161261445232636%
175: 36606295488 0.158928352521524%
176: 36074885712 0.156621206193615%
177: 35549411872 0.154339831075727%
178: 35029833552 0.152084051699457%
179: 34516110272 0.149853692318538%
180: 34008201492 0.147648576926212%
181: 33506066616 0.145468529272593%
182: 33009664996 0.143313372882035%
183: 32518955936 0.141182931070496%
184: 32033898696 0.139077026962906%
185: 31554452496 0.136995483510532%
186: 31080576520 0.134938123508347%
187: 30612229920 0.13290476961239%
188: 30149371820 0.130895244357141%
189: 29691961320 0.12890937017288%
190: 29239957500 0.126946969403057%
191: 28793319424 0.125007864321655%
192: 28352006144 0.123091877150562%
193: 27915976704 0.121198830076929%
194: 27485190144 0.119328545270545%
195: 27059605504 0.117480844901196%
196: 26639181828 0.115655551156036%
197: 26223878168 0.113852486256951%
198: 25813653588 0.112071472477925%
199: 25408467168 0.110312332162407%
200: 25008278008 0.108574887740679%
201: 24613045232 0.106858961747217%
202: 24222727992 0.105164376838065%
203: 23837285472 0.103490955808192%
204: 23456676892 0.101838521608867%
205: 23080861512 0.10020689736502%
206: 22709798636 0.0985959063926092%
207: 22343447616 0.0970053722159874%
208: 21981767856 0.0954351185852691%
209: 21624718816 0.0938849694936957%
210: 21272260016 0.0923547491950021%
211: 20924351040 0.090844282220783%
212: 20580951540 0.0893533933978589%
213: 20242021240 0.0878819078656426%
214: 19907519940 0.0864296510935053%
215: 19577407520 0.0849964488981427%
216: 19251643944 0.0835821274609415%
217: 18930189264 0.0821865133453454%
218: 18613003624 0.0808094335142215%
219: 18300047264 0.0794507153472265%
220: 17991280524 0.0781101866581728%
221: 17686663848 0.0767876757123948%
222: 17386157788 0.0754830112441153%
223: 17089723008 0.0741960224738114%
224: 16797320288 0.0729265391255812%
225: 16508910528 0.0716743914445094%
226: 16224454752 0.0704394102140341%
227: 15943914112 0.0692214267733128%
228: 15667249892 0.0680202730345887%
229: 15394423512 0.0668357815005566%
230: 15125396532 0.0656677852817298%
231: 14860130656 0.0645161181138057%
232: 14598587736 0.0633806143750322%
233: 14340729776 0.0622611091035744%
234: 14086518936 0.0611574380148799%
235: 13835917536 0.0600694375190459%
236: 13588888060 0.0589969447381852%
237: 13345393160 0.057939797523792%
238: 13105395660 0.0568978344741087%
239: 12868858560 0.0558708949514918%
240: 12635745040 0.0548588190997783%
241: 12406018464 0.0538614478616518%
242: 12179642384 0.0528786229960088%
243: 11956580544 0.051910187095325%
244: 11736796884 0.0509559836030213%
245: 11520255544 0.0500158568308303%
246: 11306920868 0.0490896519761624%
247: 11096757408 0.0481772151394721%
248: 10889729928 0.047278393341624%
249: 10685803408 0.0463930345412594%
250: 10484943048 0.0455209876521622%
251: 10287114272 0.0446621025606256%
252: 10092282732 0.0438162301428175%
253: 9900414312 0.0429832222821476%
254: 9711475132 0.0421629318866332%
255: 9525431552 0.0413552129062655%
```
I wrote this code to find the solution.
Code:
```using System;

class Program {
public static void Main(){
long count1=0;
long count2=0;
long[] count3=new long[256];
long[] count4=new long[256];
bool[] havefastcount=new bool[511];
long[] fastcount4=new long[511];
long[] fastcount3=new long[511];
for(var i=0;i<=255;i++){
for(var j=0;j<=255;j++){
for(var k=0;k<=255;k++){
var curtot=i+j+k;
if(curtot>510)break;
if(!havefastcount[curtot]){
for(var m=0;m<=255;m++){
for(var n=0;n<=255;n++){
var total=curtot+m+n;
if(total<=510 && total+255>=510){
fastcount4[curtot]++;
}
if(total+255<=510){
fastcount3[curtot]+=256;continue;
}
var remain=(510-total);
if(remain<0)break;
fastcount3[curtot]+=remain+1;
if(total>510)break;
}
}
havefastcount[curtot]=true;
}
count4[i]+=fastcount4[curtot];
count3[i]+=fastcount3[curtot];
count2+=fastcount4[curtot];
count1+=fastcount3[curtot];
}
}}
for(var i=0;i<=255;i++){
Console.WriteLine("{0}: {1} {2}%",i,count4[i],((double)count4[i]/(double)count2)*100.0);
}
Console.WriteLine("-----");
for(var i=0;i<=255;i++){
Console.WriteLine("{0}: {1} {2}%",i,count3[i],((double)count3[i]/(double)count1)*100.0);
}
Console.WriteLine(count2);
Console.WriteLine(count1);
}}
```
I also fail to see the practical use of at least some of these problems.
11. ### alkinesthetase<@dtc> every day with alk is a bad dayMentor

Joined:
Nov 8, 2010
Messages:
817
@ganj4lf: sweet, i knew there was a way to find the steady state somewhere out there. i might compute that once i finish my physics assignment (here i am playing with higher-year probability theory, and my first year physics course is reviewing grade 10 material... just goes to show you kids, pokemon teaches you shit)

EDIT: looking good. we can think of the steady state vector as the row P such that P=P*T, which means P is a left eigenvector of trans with eigenvalue of 1. playing around with matlab's eig function gives only one left eigenvector of the transition matrix for which all values are positive. (as matlab help notes, the default is right eigens, so you get the left eigens of a real-space matrix by taking the eig of the transpose). the vector adds up to approx 2.055, but normalizing said vector so that it sums to 1 (by dividing it by its sum, 2.055ish) gives the steady state, which is roughly what we see in my excel worksheet. here is the normalized eigenvector, ie the precise steady state:
Code:
```    0.0016
0.0016
0.0033
0.0049
0.0082
0.0131
0.0213
0.0345
0.0558
0.0903
0.1461
0.2365
0.3826```
thus as the number of turns approaches infinity, the probability distribution approaches this distribution here, regardless of the starting condition S. the distribution at turn 50, as i listed above, is actually surprisingly close to this.

as one more fun diversion, i checked each row of my excel worksheet to see what stage had the highest probability. the results were insane. from turns 1-7, the highest probability was +0. from turns 8 to 14, the highest probability was +1. and from turn 15 onward, +6 was ALWAYS the highest probability. yeah. crazy.

yeah =P trust me b_t, i thought about it; with my limited knowledge of probability analysis, nothing comes to mind. consider the first turn of moody across all 7 stats (acc, evasion, atk/def/satk/sdef/spe). it's guaranteed after this turn that the power of stored power will be 20*(2+1)=60. on the next turn however, you have the possibility that a new stat will be raised to 2, or that the stat already at 2 will be reduced and a different stat will be raised. thus you have some chance of going to 4 total boosts, another chance of going to 3.

after each successive iteration the probability pool expands. both the stat you pick and how much you boost it by now matter. you actually have to track the specific number of boosts because there is the remote chance that a single stat might just get dropped repeatedly from +6 to 0. etc etc. hence why i thought of it as a stochastic process of seven variables, but i know no techniques to solve such a system as of this moment

the real heart of the problem is that my distribution numbers for one stat cannot be scaled up directly to 7 stats. this would ignore the fact that each iteration of moody constitutes two state changes that must always both take place: one stat goes up, one stat goes down. if we simply combine the distribution of a single stat into itself seven times, we may be including cases where two stats go up in a single turn, or two stats go down. those cases take up some fragment of the probability space, but are actually illegal. i'm saying it in a kinda shitty and kinda fluffy manner, but i'm not confident that the data can be extrapolated like that.

@poccil: the EV distribution question is for generating spreads in challenge cup, primarily. i recall there was an article on antar's blog, pokemetrics, about it. i imagine the moody question is to demonstrate the statistical relevance of moody and why it really is capable of breaking down a game in the long run. and the stat experience question looks to me like an opportunity to explore some under-represented mechanics of past generations, which are probably understood less solidly than those of the modern era.
12. ### NoJohns

Joined:
Sep 11, 2010
Messages:
98
3(a)(i)

Done Mathematically:

n = 6 (Number of Stats)
r = 127 (508 / 4)
ev_max = 63 (252 / 4)
k = 64 (127 - ev_max)

Order does not matter. Repetition is allowed.

(n + r - 1)!/(r!(n - 1)!) - k(k+1)(k+2)(k+3)(k+4) / 20

(6 + 127 - 1)!/(127!(6 - 1)!) - 64(65)(66)(67)(68) / 20

309,319,296 - 62,544,768

= 246,774,528, which is what poccil got for his computed answer.

I'm not exactly sure why the sequence k(k+1)(k+2)(k+3)(k+4) / 20 pops up in my answer, but when I tested the remaining EV's for r = 64, r = 65, etc, the sequence S(n) = 6, 36, 126, 336, kept popping up, and I just used simple induction to find the formula.

Hope this is a good starting point for anyone who wants to tackle #3.

EDIT:

3(a)(ii):

3(a)(ii) was pretty elementary; just find the sum of the EV spreads using the formula I used above, making sure to discount the EV errors discounted by the EV maxes for each stat:

sum r = 0 to 63 (6 + r - 1)!/(r!(6 - 1)!) + sum r = 64 to 127 ((6 + r - 1)!/(r!(6 - 1)!) - (r - 63)(r - 63 + 1)(r - 63 + 2)(r - 63 +3)(r - 63 + 4) / 20)

Plunk that into a computer and it comes to exactly 6,137,312,896, again matching poccil's calculated answer. I'll tidy this up if I get the chance.
13. ### Great Sage

Joined:
Jul 31, 2006
Messages:
6,661
poccil, these problems are not intended to be practical. I would be the first to acknowledge that they have negligible utility in Pokemon battles. I am posing these problems because I think they are interesting, and I think some other people would find them interesting too.
14. ### AntarThat's Dr. Antar to youOfficial Data Miner

Joined:
Feb 17, 2010
Messages:
2,412
I solved Problem 3 months ago.

Just sayin'.

Edit: and yes, my results agree with poccil's, although one should note, of course, that his results are expressed in percentages, rather than probabilities.

Edit 2: my code, written in Python:

Code:
```n=[]
for i in range(0,6):
n.append([0]*511)

for x in range(0,511):
if (x<256):
n[0][x]=1

for i in range(1,6):
for x in range(0,511):
for y in range(0,256):
if x-y<0:
break
n[i][x]=n[i][x]+n[i-1][x-y]

for s in range(1,256):
print s,float(n[4][510-s])/float(n[5][510])```
15. ### alkinesthetase<@dtc> every day with alk is a bad dayMentor

Joined:
Nov 8, 2010
Messages:
817
alright smogon, one more thing before i go so that i can really flaunt my results:

this graph depicts the complete probability distribution i have computed from turns 0 to 200. as you can see, the distribution is approaching constant by as early as the 120th turn. stages are stacked from top to bottom - the top most color (dark purple at the top) is +6, the bottom most color (that periwinkle sliver that is hardly visible) is -6. the "regular blue" in the middle is +0. the chart is in the excel sheet as linked above. i redid the graph in grayscale because colors suck, but the contrast reduction makes it tough to distinguish the really skinny regions in the -4 to -6 area.

i had a lot of fun working on this part of the problem, but unless there are any mistakes, that's probably all there for me to say on 1a. i will be back if i find anything for 1b!
16. ### ganj4lFNobody is safe from the power of science!

Joined:
Jun 11, 2011
Messages:
747
Okay, since I couldn't figure out a relatively simple analytical solution for 1b (as alkinesthetase said, using a Markov Chain would require a huge amount of states, which would be very difficult to handle), I wrote a little piece of C code that simulates the evolution of stat boosts on the Moody pokemon, and obtains an approximate probability distribution for Stored Power's power from turn 1 to turn 50. I know, this probably has very little theoretical relevance, but I guess it's still good to have a (pretty accurate, tbh) idea about the evolution of Stored Power's BP.

I then proceeded to launch my simulator with a huge number of iterations (I used 100 millions iterations, that should be enough to have statistical reliable data). The code actually prints out two kinds of output; the first one is just the average power of Stored Power in a given turn (which wasn't actually required, but it's nice to have a rough idea of how the BP evolves). It also prints out a 50*42 matrix, that contains the estimate probability distribution required. In particular, entry (i, j) of the matrix contains a value calculated as follows: # of times Stored Power's BP was 20+(20*j) at turn i / # of iterations, which is an estimate of the real probability distribution.

So, the data I obtained follows:

Code:
```Turn	Avg Stat Boosts	Stored Power Avg BP
1:	2.00		60.00
2:	3.71		94.29
3:	5.20		124.08
4:	6.53		150.58
5:	7.73		174.70
6:	8.86		197.12
7:	9.92		218.31
8:	10.93		238.56
9:	11.90		258.06
10:	12.85		276.92
11:	13.76		295.21
12:	14.65		312.98
13:	15.51		330.29
14:	16.36		347.15
15:	17.18		363.61
16:	17.98		379.68
17:	18.77		395.40
18:	19.54		410.77
19:	20.29		425.82
20:	21.03		440.57
21:	21.75		455.03
22:	22.46		469.22
23:	23.16		483.15
24:	23.84		496.83
25:	24.51		510.27
26:	25.17		523.49
27:	25.82		536.49
28:	26.46		549.28
29:	27.09		561.87
30:	27.71		574.26
31:	28.32		586.46
32:	28.92		598.47
33:	29.51		610.29
34:	30.10		621.92
35:	30.67		633.36
36:	31.23		644.62
37:	31.78		655.67
38:	32.33		666.53
39:	32.86		677.20
40:	33.38		687.68
41:	33.90		697.97
42:	34.40		708.06
43:	34.90		717.94
44:	35.38		727.60
45:	35.85		736.99
46:	36.30		746.10
47:	36.74		754.87
48:	37.16		763.25
49:	37.56		771.21
50:	37.93		778.69```
(EDIT: meh, the tabulations look bad either on Windows or Linux depending on how many of them I use in the first seven rows...well not a big deal, I guess)

This is a listing of the average BP of Stored Power at each turn. The column "Average Stat Boosts" actually contains the average number of positive stat boosts, which is what we need to evaluate Stored Power's BP. As expected, the average BP rises faster at first, then it slows down since Moody starts to lower boosted stats more often and thus slows the growth. A simple graph is shown below, for the reader's convenience.

(obviously, the X-axis is the turn, and the Y-axis value represents the average Stored Power's BP on that turn).

Code:
```0.000000 0.000000 1.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
0.000000 0.000000 0.023829 0.238079 0.738093 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
0.000000 0.000000 0.000000 0.024377 0.161541 0.399581 0.414501 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
0.000000 0.000000 0.000000 0.000000 0.023517 0.139388 0.307951 0.343116 0.186028 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
0.000000 0.000000 0.000000 0.000000 0.000000 0.025891 0.129833 0.268389 0.305005 0.201140 0.069742 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
0.000000 0.000000 0.000000 0.000000 0.000000 0.000001 0.030322 0.128495 0.246747 0.279326 0.201872 0.090680 0.022557 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000025 0.036529 0.131626 0.234532 0.261003 0.195586 0.100850 0.033509 0.006340 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000142 0.044546 0.137240 0.227955 0.246469 0.188235 0.103159 0.040344 0.010338 0.001572 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000003 0.000521 0.054342 0.144569 0.224299 0.235423 0.179423 0.101945 0.043144 0.013293 0.002702 0.000336 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000014 0.001454 0.065897 0.153190 0.222448 0.226018 0.170240 0.098063 0.043838 0.014575 0.003627 0.000580 0.000057 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000054 0.003292 0.079278 0.163002 0.221609 0.216921 0.160611 0.092833 0.042583 0.014965 0.003960 0.000779 0.000105 0.000010 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000001 0.000161 0.006454 0.094700 0.173549 0.220758 0.207618 0.150628 0.086644 0.040314 0.014112 0.004036 0.000876 0.000133 0.000014 0.000001 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000005 0.000406 0.011549 0.112240 0.183982 0.219466 0.197926 0.140237 0.079734 0.036742 0.012886 0.003808 0.000863 0.000142 0.000015 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000016 0.000977 0.019262 0.131527 0.193805 0.217043 0.187780 0.129437 0.071744 0.032878 0.011279 0.003348 0.000770 0.000122 0.000010 0.000001 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000058 0.002176 0.030210 0.152176 0.202277 0.213467 0.176799 0.117312 0.063950 0.028658 0.009417 0.002782 0.000613 0.000091 0.000012 0.000001 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000003 0.000188 0.004476 0.044917 0.173351 0.209339 0.208045 0.163904 0.105292 0.056064 0.024264 0.007517 0.002108 0.000444 0.000078 0.000010 0.000001 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000015 0.000516 0.008504 0.063695 0.194409 0.214168 0.199632 0.150225 0.093305 0.048290 0.019764 0.005593 0.001477 0.000341 0.000058 0.000007 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000001 0.000054 0.001255 0.015089 0.086828 0.214084 0.215261 0.188995 0.135989 0.081498 0.040503 0.015210 0.003893 0.001067 0.000233 0.000036 0.000004 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000005 0.000162 0.002783 0.025261 0.113760 0.230487 0.212705 0.176495 0.121361 0.069772 0.032511 0.011119 0.002718 0.000704 0.000137 0.000018 0.000001 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000018 0.000436 0.005720 0.040036 0.143012 0.242536 0.206673 0.162313 0.106258 0.057669 0.025124 0.007976 0.001751 0.000408 0.000065 0.000004 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000002 0.000060 0.001091 0.010951 0.059835 0.172941 0.249337 0.197411 0.146337 0.090217 0.046208 0.019049 0.005360 0.001000 0.000186 0.000016 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000007 0.000188 0.002536 0.019467 0.084673 0.201616 0.250646 0.184538 0.127859 0.074509 0.036477 0.013689 0.003293 0.000456 0.000047 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000001 0.000029 0.000524 0.005342 0.032285 0.114265 0.227095 0.245291 0.167050 0.108881 0.060585 0.027656 0.009158 0.001726 0.000111 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000004 0.000101 0.001304 0.010349 0.050497 0.147447 0.246493 0.232166 0.146907 0.091032 0.047714 0.019809 0.005498 0.000680 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000001 0.000018 0.000293 0.002925 0.018730 0.074951 0.181578 0.256560 0.212513 0.126523 0.073948 0.035882 0.013019 0.002812 0.000246 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000003 0.000062 0.000759 0.006099 0.031957 0.105351 0.212412 0.256067 0.189394 0.105968 0.057696 0.025063 0.007632 0.001419 0.000119 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000001 0.000012 0.000181 0.001807 0.011972 0.051221 0.139297 0.236506 0.246717 0.163613 0.085375 0.042140 0.015955 0.004398 0.000755 0.000050 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000003 0.000042 0.000495 0.004073 0.021894 0.076558 0.174004 0.252272 0.228767 0.135957 0.064671 0.028404 0.009960 0.002535 0.000348 0.000018 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000009 0.000130 0.001287 0.008480 0.036909 0.107291 0.206921 0.257556 0.203059 0.106611 0.045492 0.018736 0.006106 0.001278 0.000132 0.000004 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000002 0.000032 0.000387 0.003058 0.016078 0.057825 0.142378 0.234608 0.250419 0.170013 0.078033 0.031248 0.012042 0.003311 0.000532 0.000034 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000007 0.000111 0.001038 0.006483 0.028107 0.085494 0.179578 0.252180 0.228947 0.133258 0.055389 0.020848 0.006929 0.001475 0.000152 0.000004 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000002 0.000031 0.000337 0.002471 0.012572 0.046156 0.119850 0.213956 0.254001 0.195877 0.100402 0.037993 0.012578 0.003301 0.000456 0.000018 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000008 0.000106 0.000892 0.005282 0.022896 0.071788 0.158189 0.237735 0.238946 0.160329 0.072489 0.023850 0.006339 0.001096 0.000056 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000002 0.000033 0.000309 0.002105 0.010626 0.039483 0.104838 0.193643 0.246011 0.214256 0.125113 0.048405 0.012809 0.002228 0.000140 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000001 0.000010 0.000105 0.000800 0.004675 0.020267 0.063677 0.141097 0.219973 0.242020 0.182785 0.090784 0.028438 0.005069 0.000298 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000003 0.000034 0.000296 0.001962 0.009863 0.036063 0.093971 0.175346 0.237146 0.226313 0.145357 0.059161 0.013401 0.001084 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000001 0.000011 0.000106 0.000797 0.004586 0.019331 0.058236 0.127284 0.206629 0.242885 0.197674 0.104861 0.032666 0.004692 0.000242 0.000000 0.000000 0.000000 0.000000 0.000000
0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000004 0.000038 0.000315 0.002062 0.009903 0.034026 0.085708 0.163370 0.231540 0.232720 0.157274 0.065843 0.015210 0.001891 0.000097 0.000000 0.000000 0.000000 0.000000
0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000001 0.000013 0.000122 0.000903 0.004892 0.018953 0.054206 0.119375 0.199963 0.242946 0.203391 0.110240 0.036543 0.007586 0.000835 0.000032 0.000000 0.000000 0.000000
0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000005 0.000046 0.000385 0.002352 0.010158 0.032561 0.081697 0.159169 0.229524 0.232384 0.157276 0.069642 0.020808 0.003677 0.000307 0.000008 0.000000 0.000000
0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000002 0.000018 0.000164 0.001102 0.005270 0.018731 0.052962 0.118392 0.199585 0.239641 0.196633 0.110632 0.044199 0.011085 0.001499 0.000084 0.000001 0.000000
0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000006 0.000069 0.000506 0.002666 0.010389 0.032776 0.083277 0.162012 0.227011 0.220436 0.152044 0.077431 0.025915 0.004991 0.000456 0.000013 0.000000
0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000003 0.000028 0.000233 0.001316 0.005585 0.019513 0.055826 0.124206 0.200433 0.225940 0.185712 0.116649 0.049937 0.012847 0.001694 0.000080 0.000000
0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000001 0.000012 0.000103 0.000644 0.002935 0.011235 0.035968 0.090766 0.166797 0.214912 0.206034 0.155493 0.082593 0.027345 0.004832 0.000329 0.000000
0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000005 0.000046 0.000306 0.001510 0.006297 0.022394 0.063764 0.132129 0.192014 0.210840 0.187475 0.120725 0.050023 0.011426 0.001046 0.000000
0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000002 0.000021 0.000143 0.000759 0.003441 0.013567 0.043276 0.100548 0.162717 0.201586 0.207721 0.159392 0.080819 0.023243 0.002765 0.000000
0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000001 0.000009 0.000067 0.000375 0.001835 0.008017 0.028606 0.073895 0.131927 0.181962 0.214258 0.192963 0.117959 0.041839 0.006287 0.000000
0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000004 0.000031 0.000181 0.000964 0.004636 0.018460 0.052758 0.103052 0.156480 0.207781 0.217066 0.157811 0.068101 0.012674 0.000000
0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000002 0.000014 0.000087 0.000498 0.002638 0.011657 0.036810 0.077995 0.128956 0.191204 0.229097 0.196120 0.101800 0.023122 0.000000
0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000001 0.000006 0.000043 0.000254 0.001480 0.007250 0.025130 0.057483 0.102545 0.168090 0.228803 0.228558 0.141469 0.038888 0.000000 ```
And this is the (kinda huge and unreadable) matrix that approximates the probability distribution required. Entries have been described above, so I'm not repeating myself; however, I'll provide something more useful for you readers, a graphical representation of this big bunch of numbers!

I resized the image a bit to not clutter too much the thread, but it's a little less clear of the high resolution version I have on my PC (also, I'm still not a gnuplot guru, so the graphic could be improved a lot I guess); hopefully, it's still good enough to give you an idea of the system's behaviour. As you can see, there's a big spike near the origin since Stored Power's BP after 1 turn of Moody is always 60. The data keep becoming less spiky when the number of turns increases, and actually follows roughly the graph of the Average Stored Power's BP (which, in fact, is not surprising at all since the latter could be inferred from the matrix even without being explicitly calculated...).

Oh, if someone wants to re-run the computations, I'm providing the source code of my little sim:

The code is pretty straightforward and it's commented a bit so you shouldn't have problems reading it, if you want/need to. To run it, you'll need mtwist.h and mtwist.c since I used a Mersenne twister as RNG (I don't trust rand() or other low-quality sources of randomness when I'm going to generate that huge amount of random numbers); you can easily retrieve those files here. Also, when you run it, you better redirect stdout to a file since it's hard to handle all those numbers on a terminal. A typical call the the program is something like this:

\$ ./a.out 1000 50 >out.txt

which sets the number of iterations to 1000 and simulates 50 turns of Moody boosting; the obvious redirection operator puts the output on out.txt.

Code:
```#include <stdio.h>
#include <stdlib.h>
#include "mtwist.h"

int main(int argc, char **argv){

int iterations = atoi(argv[1]);
int turns = atoi (argv[2]);

long int avg[turns+1];

int distr[turns+1][43]; 		//distr[x][y] = turn x, y total positive stat boosts
//they can range from zero to 7*6=42

int stats[7];

int i, j, k;
int a, b;
int boosts;

mt_seed();

//initialize average array
for (i=0;i<turns+1;i++) avg[i]=0;

//initialize distr array
for (i=0;i<turns+1;i++){
for (j=0;j<43;j++) distr[i][j]=0;
}

//loop for #iterations
for (i=0;i<iterations;i++){

//let's see how fast it computes...
if ((i%(1000000))==0) {fprintf(stderr, "Beginning iteration %d\n", i);}

//set array of stat boosts to zero
for (k=0;k<7;k++) stats[k]=0;

//loop for #turns
for (j=1;j<=turns;j++){
boosts=0;

//generate random numbers in range 0-6 into a and b
a=mt_lrand()%7;

while (stats[a]==6) {a=(mt_lrand()%7);}

b=(mt_lrand()%7);

while (a==b || stats[b]==-6) {b=(mt_lrand()%7);}

//update stats
stats[a]+=2;
stats[b]--;
if (stats[a]>6) stats[a]=6;

//find # of positive stat boosts
for(k=0;k<7;k++) {if(stats[k]>0) boosts+=stats[k];}

//update avg for current "turn"
avg[j]+=boosts;

//update boosts distribution...
distr[j][boosts]++;

}
}

//print avg
printf("Turn\tAvg Stat Boosts\tStored Power Avg BP\n");
double divisor = (double)iterations;
for (j=1;j<=turns;j++){
printf("%d:\t%.2f\t\t%.2f\n", j, avg[j]/divisor, 20+(avg[j]/divisor)*20);

}

//print distr
for (j=1;j<=turns;j++){
//printf("%d: ", j);
for (k=0;k<=42;k++){
double val = distr[j][k]/divisor;
printf("%.6f ", val);
}
printf("\n");
}

}
```

This is pretty much all. Again, the theoretical relevance of this work is negligible, but it outlines pretty well the rough behavior of the Moody pokemon left boosting for 50 turns; if someone has a better idea for an analytical solution, I'll be glad to read it!

EDIT: There's an inaccuracy in my code, I just realized that "Moody will not lower a stat at -6, nor will it raise a stat at +6."; I'll fix that tomorrow and edit the data and the images accordingly.

EDIT2: Code corrected and replaced old, wrong data with new one, obtained in the same way. After consindering the fact that Moody cannot modify already "capped" stats, the effect of it when the turn count goes roughly over 25 is much more scary: being unable to raise stats that are already at +6 means that something useful will be chosen for the increase, and thus the average BP of Stored Power raises much more quickly, actually almost approaching the maximum possible BP around turn 50. The opposite effect is basically negligible, since it's very unlikely for a stat to reach -6.
17. ### Kidogo

Joined:
Feb 11, 2012
Messages:
464
Problem 3ai:
I'm may be wrong, but when I calculated this I ended up getting a significantly bigger number. The value both poccil and nojohns got appeared for me, but I think that's only one piece of the problem. I solved it using combinatorics, but the tricky thing is that the actual number of stat points in the result can be either 123, 124, 125, 126, or 127, since the extra 18 EVs beyond 492, which is 123 stat points, could count for nothing or for 4 points. Thus, the process used above just needs to be repeated for these 5 values and summed, which gives an answer of 1,163,547,904.

3aii:
Given no restriction on the sum of the EVs, this problem becomes very similar to he previous except that we're adding the number of combinations 127 times (508/4). Since the number of combos for any given number of stat points n greater than 63 is equal to (n+5)!/n!5! - 6*(n-59)!/(n-64)!5! and equal to simply (n+5)!/n!5! for n less than or equal to 63, I wrote a calculator program to sum these. The answer I got was 2,818,954,784. I think I must have entered something wrong though, since that number seems way too small.
EDIT: OK, think I fixed the program. The answer I'm getting now is 6,137,312,895, which seems much more reasonable.

I'll probably give problem 3b a shot later.
18. ### ganj4lFNobody is safe from the power of science!

Joined:
Jun 11, 2011
Messages:
747
Uploaded corrected data to my simulation; hopefully everything is right now.
19. ### smftrdr

Joined:
Oct 4, 2012
Messages:
1
Okay, so I registered just to answer 1a because I was upset that a math problem was attempted to be solved with simulations after the Markov Chain was defined lol

So here's the proof of the limits.

Redefine Pi_k => Pi_j by j = k+7 for simplicity.
Let F(k) be the Fibonacci Sequence (F(0) = 0, F(1) = 1, F(k) = F(k-1) + F(k-2) for k >=2).

Note: Sum {F(k)} k = 1... n = F(n+2) -1

Then Pi_j = F(j) /[F(15) -1]

Proof: From the Markov process we quickly see Pi_1 = Pi_2 and Pi_13 = Pi_12 + Pi_11. From simple algebra, we see that Pi_j = F(j) * Pi_1.

Now we know SUM {Pi_j} j = 1 ... 13 = 1 by definition. Which gives us the following equalities:

1 = SUM {Pi_j} j = 1 ... 13 by Definition
= SUM {F(j) * Pi_1 } j = 1 ... 13 by Substitution
= Pi_1 *SUM {F(j)} j = 1 ... 13 since Pi_1 is constant
= Pi_1 * [F(15) - 1] by our note previously.

Thus we get Pi_1 = 1 / [F(15) - 1].
Thus we conclude Pi_j = F(j) / [F(15) - 1]. QED
20. ### alkinesthetase<@dtc> every day with alk is a bad dayMentor

Joined:
Nov 8, 2010
Messages:
817
i'm not sure what part of 1a you're trying to solve, but 1a was not solved by simulation - i used a markov chain, exactly as i detailed, which is an entirely theoretical process. ganj4lf solved 1b by simulation, because the required markov chain would have 13^7 states which is nearly 63million x 63million transition matrix. if you have a tool that can handle systems of that size, let us know
21. ### ganj4lFNobody is safe from the power of science!

Joined:
Jun 11, 2011
Messages:
747
I think I have found a flaw on your approach via Markov Chain to 1a, alkinesthetase (yay I wrote your nick right without copypasting!). By solving the problem like you did, you're implying that the transition probability matrix is constant and does not depend by anything, in particular the behaviour of the others stats. While this may seem correct at first, it reveals a quite important flaw after some more careful considerations. In particular, consider the following example. Let's say you are observing the "Attack" stat of our hypotetical poke, and said stat as accumulated a total boost of +4 at turn, say, 25 (not relevant at all, but let's fix one for the sake of exemplification). Your approach implies that, regardless of everyhing else, the chance for the "Attack" stat to remain unchanged is 5/7, the chance for it to become +3 is 1/7 and to raise to +6, 1/7 too. Now, let's take an extreme case to make the point obvious, and imagine that the other stats of our observed poke are boosted as follows, at turn 25: "Defense"="SpAttack"="SpDefense"="Speed"="Evasion"="Accuracy"=+6, so every other stat is maxed. Now, in this setting, Moody is GUARANTEED to pick "Attack" and raise it to +6. This means that the transition probability matrix is NOT independent from the amount of boosts the stats not observed have accumulated, and again brings us back to the huge-amount-of-states MC approach, since we have to "keep in memory" the amount of boosts that are accumulated by the unobserved stats.

If it's needed, I can easily modify my simulator to check if your analytical calculated array is reasonably near (or not, like I'm predicting now) to the simulated one, to see if my argument is correct or not, but I'd like to have your feedback first!
22. ### david stoneFast-moving, smart, sexy and alarming.

Joined:
Aug 3, 2005
Messages:
5,152
sun_beak likes this.
23. ### alkinesthetase<@dtc> every day with alk is a bad dayMentor

Joined:
Nov 8, 2010
Messages:
817
ganj4lf: your point is correct, if other stats have reached a maxed state, then the chance of this stat being raised will increase. however as i understood it, 1a was for a single stat in vacuum, so that problem would be set aside. regardless, there is no easy way to analyze it theoretically, since we end up back in the 13^7 states problem again - essentially, none of the boosts are independent, so if we want to distribute one stat correctly, we must do them all. when i get back to waterloo on tuesday i'm finally going to have a chance to ask my number theory prof about the problem (i couldn't do it last week, had a midterm that day) so we might actually be able to get an analytical solution.

i would love to see if your simulation reflects the probability distribution i calculated though, or if it's close. it would be very interesting to see how much the maxed stats problem influences the system at say 50 turns in. my distribution suggests a STRONG lean towards getting to high stages very very fast, so the impact may indeed be nontrivial
24. ### ganj4lFNobody is safe from the power of science!

Joined:
Jun 11, 2011
Messages:
747
Okay, I ran the simulation, and the results are...dramatically different from yours. As I predicted, the "Moody will not lower a stat at -6, nor will it raise a stat at +6." has a huge impact on it, since it generates a sort of positive feedback: more stats at +6 means more probability to increase the remaining stats that means more stats at +6, etc...

This is the code I used:
Code:
```#include <stdio.h>
#include <stdlib.h>
#include "mtwist.h"

int main(int argc, char **argv){

int iterations = atoi(argv[1]);
int turns = atoi (argv[2]);

int distr[13]; 		//distr[x] = 1(#boosts = x-6)
//considering stats[0] as the stat of choice

int stats[7];

int i, j, k;
int a, b;

mt_seed();

//initialize distr array
for (i=0;i<13;i++){
distr[i]=0;
}

//loop for #iterations
for (i=0;i<iterations;i++){

//let's see how fast it computes...
if ((i%(1000000))==0) {fprintf(stderr, "Beginning iteration %d\n", i);}

//set array of stat boosts to zero
for (k=0;k<7;k++) stats[k]=0;

//loop for #turns
for (j=1;j<=turns;j++){

//generate random numbers in range 0-6 into a and b
a=mt_lrand()%7;

while (stats[a]==6) {a=(mt_lrand()%7);}

b=(mt_lrand()%7);

while (a==b || stats[b]==-6) {b=(mt_lrand()%7);}

//update stats
stats[a]+=2;
stats[b]--;
if (stats[a]>6) stats[a]=6;

}

//update distr
distr[stats[0]+6]++;

}
double divisor = (double)iterations;

//print distr
for (j=0;j<13;j++){

printf("%d : %f\n", j-6, distr[j]/divisor);

}

}```

And these are the results. I actually ran the simulation three times to "triple check" somewhat the array, since it was heavily different from your. The differences amongst the runs are very negligible. The number of iteration is, as above, 100 millions.

Code:
```First run:
-6 : 0.000005
-5 : 0.000013
-4 : 0.000053
-3 : 0.000155
-2 : 0.000440
-1 : 0.001059
0 : 0.002419
1 : 0.005168
2 : 0.011249
3 : 0.026908
4 : 0.076046
5 : 0.252092
6 : 0.624393

Second run:
-6 : 0.000004
-5 : 0.000013
-4 : 0.000052
-3 : 0.000157
-2 : 0.000439
-1 : 0.001057
0 : 0.002429
1 : 0.005184
2 : 0.011259
3 : 0.026927
4 : 0.076047
5 : 0.252010
6 : 0.624423

Third run:
-6 : 0.000004
-5 : 0.000013
-4 : 0.000053
-3 : 0.000158
-2 : 0.000439
-1 : 0.001065
0 : 0.002420
1 : 0.005188
2 : 0.011263
3 : 0.026915
4 : 0.076078
5 : 0.252119
6 : 0.624284
```
So, after 50 turns, there's less than 15% chance for a random stat to be at less than +5. This is indeed scary and witnesses the amount of influence the "positive feedback" effect that I just described has onto the final distribution.
25. ### yenatch

Joined:
Oct 17, 2012
Messages:
1
2: The engine rounds down. Chansey also has base 5 defense so the example doesn't quite work, but Shuckle's base 5 speed lets you get away with this.

In GSC, Exp. Share gives half exp to participants and the other half to Exp. Share holders. This can be exploited to get 0 stat exp from any monster with a base stat under 12, bringing Diglett and Magikarp into the fold for HP and Atk respectively. Since SDef isn't factored into stat exp this leaves Def and SAtk.

Def: Chansey is suitable for grinding up HP SAtk and Spd without affecting Def. From there it comes down to the best Atk:Def ratio. Comically Pichu has the highest with 40:15 (8/3). To hit 63504 Atk exp you would have to fight 1587 Pichu = 23805 Def exp.

SAtk: Shuckle maxes out HP and Def. What's left is finding the best balance between Atk and Spd wrt SAtk. Krabby has the best Atk:SAtk (105:25) and Magikarp the best Spd:SAtk (80:15). A quick estimate puts it at 563 Krabby and 442 Magikarp = 20705 SAtk exp.

In RBY, Exp. All does the same thing. Shuckle is out of the picture which makes Speed a factor again and Special without a clear victor.

HP and Atk are still 0 thanks to Diglett and Magikarp.

Def is the same but the highest Atk:Def in RBY is Mankey. 794 Mankey = 27790 Def exp.

Spc: This is a real tossup. I came up with 179 Krabby, 525 Magikarp, 144 Jigglypuff and 389 Rhyhorn = 30245 Spc exp.

Slowpoke has the highest Spc:Spd ratio (Spc is limiting) and its other stat ratios are higher. 1588 Slowpoke = 23820 Spd exp.

Pardon the lack of calculations, I more posted to confirm that exp share can be abused in this way.