obi
formerly david stone
You have 127 EVs total (due to division by 4, it's easier to think of 127 than 512 with multiples of 4 being required... Just think of it as the points at level 100 rather than the EVs themselves), with no more than 63 allowed per stat. You have 6 stats to distribute them among. How many possible combinations of EVs are there? Keep in mind that you can invest anywhere between 0 and 63 in any given stat, and between 0 and 127 total.
That's just the Pokemon problem, however, and can be solved with a brute force algorithm. Consider the general problem:
You have A tokens, which cannot be distinguished from each other. You must distribute these tokens among B containers, labeled 1, 2, 3, ..., B - 1, B. Each container can hold, at most, C tokens. Not all tokens are required to be put in a container. Create an algorithm to determine the number of ways to distribute these tokens among the containers.
It seems that there are a few ways I can think of to attempt to solve this. Most of these can probably be used together.
First, assume that only 1 container will be used. The solution to this is trivial. The answer is either the number of tokens or the container's limit, whichever is smaller. Then assume exactly 2 containers will be used. The solution to this is also simple, especially when A is greater than 2 * B. Next assume exactly 3 containers will be used, and so on. Add up all your results and you have the answer. The problem is that at 3 containers or more (especially when you are unable to fill up all containers), this solution runs into some difficulties.
Another path to solving this is to simply ignore the limit per container and find out how many possibilities there are, or to ignore the limit of the number of tokens you have, and then calculate the possibilities. After you have this number, subtract out the illegal possibilities. To use the Pokemon problem as an example, assume there is no limit on how many EVs a Pokemon can get (so basically, stat exp. in RBY and GSC). Then there are 64 options for each container (because a container can be empty). There is then an upper limit of 64^6 possibilities for combinations, or 68,719,476,736, about 69 billion.
If you want to try an even more generalized problem, consider this extension: each container can be uniquely sized. For instance, container 1 can only hold 5 tokens, but container 2 can hold 26 tokens. You can actually use this in solving the other problems. Assume you must use all tokens, but you have an extra container that is the size of the number of tokens to distribute. Then, rather than having tokens "nowhere", you have them in this container, container 0.
That's just the Pokemon problem, however, and can be solved with a brute force algorithm. Consider the general problem:
You have A tokens, which cannot be distinguished from each other. You must distribute these tokens among B containers, labeled 1, 2, 3, ..., B - 1, B. Each container can hold, at most, C tokens. Not all tokens are required to be put in a container. Create an algorithm to determine the number of ways to distribute these tokens among the containers.
It seems that there are a few ways I can think of to attempt to solve this. Most of these can probably be used together.
First, assume that only 1 container will be used. The solution to this is trivial. The answer is either the number of tokens or the container's limit, whichever is smaller. Then assume exactly 2 containers will be used. The solution to this is also simple, especially when A is greater than 2 * B. Next assume exactly 3 containers will be used, and so on. Add up all your results and you have the answer. The problem is that at 3 containers or more (especially when you are unable to fill up all containers), this solution runs into some difficulties.
Another path to solving this is to simply ignore the limit per container and find out how many possibilities there are, or to ignore the limit of the number of tokens you have, and then calculate the possibilities. After you have this number, subtract out the illegal possibilities. To use the Pokemon problem as an example, assume there is no limit on how many EVs a Pokemon can get (so basically, stat exp. in RBY and GSC). Then there are 64 options for each container (because a container can be empty). There is then an upper limit of 64^6 possibilities for combinations, or 68,719,476,736, about 69 billion.
If you want to try an even more generalized problem, consider this extension: each container can be uniquely sized. For instance, container 1 can only hold 5 tokens, but container 2 can hold 26 tokens. You can actually use this in solving the other problems. Assume you must use all tokens, but you have an extra container that is the size of the number of tokens to distribute. Then, rather than having tokens "nowhere", you have them in this container, container 0.