# ProgrammingIV Calc, EV calc

#### Sevans

http://www.mediafire.com/?v9bbrp1jek191wb

This works as an offline IV calculator.
Features include
-An IV calculator that can work with one pokemon for multiple levels.(good to check a low-leveled pokémon's IVs)
-A Stat calculator to see how much EVs/IVs change stuff.
-An EV calculator
-A type chart with all type COMBOS
-A team synergy page.

So I looked at Serebii's IV formula, and it's wrong. I wanted to get an IV calculator with the right formula in it.

This is the right formula (there is a minimum and maximum.)
HP IV Min=Ceiling(((Stat-10-Level)*(100/Level))-2*Base-EP)
HP IV Max=Floor((Stat-10+0.99999...-Level)*(100/Level)-2*Base-EP)

Other IV Min=Ceiling((Ceiling(Stat/Nature)-5)*(100/Level)-2*Base-EP)
Other IV Max=Floor((Ceiling((Stat+0.99999...)/Nature)-5)*(100/Level)-2*Base-EP)

Where
Floor means round down to the next integer,
Ceiling means round up to the next integer,
Stat is the value of the stat you want to find the IV for,
Nature is either .9 or 1 or 1.1,
Level is the level (1 to 100)
Base is the base stat
and EP= Floor(EV/4) where EV= effort value in that stat (from 0 to 255)

I'm new to the programming world, but I can work with excel. And I'm good at math.

Also new to smogon ...

(If I need to change this post to be acceptable could a mod please let me know before deleting it?)

#### NixHex

##### Doing just fine, here at the top of the world
I'm actually writing a DV/Stat Exp. calculator for RBY/GSC and I found that the best way to do it is to run it through a for loop instead of finding the inverse equation. Here's the pseudo code for IVs in Gen III and beyond:

HPIVs=[];
for HPIV=0:31
if floor((2*BaseHP + HPIV + floor(EV/4) + 100)*Level/100 + 10)==HP_Stat
HPIVs.append(HPIV)
end

AtkIVs=[];
for AtkIV=0:31
if floor((2*BaseAtk + AtkIV + floor(EV/4))*Level/100 + 5)==Atk_Stat
AtkIVs.append(AtkIV)
end

Of course every other stat besides HP follows the same equation as Attack. What this does is loops through every possible IV and if it satisfies the equality for whatever raw stat the user inputs, then add the current IV value into a set.

#### Sevans

OK then. I would have done that...

If I had any knowledge of actual programming codes.

Because I had in fact thought of just testing each value individually, but I just didn't know how to do it efficiently.

I had knowledge in algebra, so I used that. But still, if I had that code before...

The same goes for the EV equation.
Still, thanks for the suggestion.

#### NixHex

##### Doing just fine, here at the top of the world
Right, if you want to find the EVs, you would have to know the IVs ahead of time (whereas before you had to know the EVs). Unfortunately, unlike IVs, EVs have a bit more complexity since the stat points calculated from EVs is int(EVs/4), which means 7 EVs would be "equivalent" to 4 EVs. This makes calculation more uncertain, and calculating EVs would only be an approximation. It would go something like this:

AtkEPs=[]
for AtkEP=0:63
if floor((2*BaseAtk + AtkIV + AtkEP)*Level/100 + 5)==Atk_Stat
AtkEPs.append(AtkEP)
end

Which gives you the amount of Effort Points. This is more informative than EVs since multiple values of EVs equal the same amount of points granted when the stat is calculated, like I mentioned above.

Next, you tell the user that the minimum and maximum by doing this:

AtkEVMin=min(AtkEPs)*4
AtkEVMax=max(AtkEPs)*4 + 3

Let's say you have a Jirachi (100/100/100/100/100/100) at level 100 and you already know it has 30 SpA IVs (HP Fire), and the raw stat you input is 290. Running it through the loop I gave you above will give you:
SpAEPs = [55]
Luckily there's enough info here (since it's at level 100) so there's only one value. Moving on, you have:
SpAEVMin = 4*min(SpAEPs) = 4*55 = 220
SpAEVMax = 4*max(SpAEPs) + 3 = 4*55+3 = 223

That tells you the true range, since the user may have given their Jirachi 223, which is inefficient, but it's still a possibility. You'll have to do a check at the end to make sure that the sum of the minimum EVs don't exceed 510.

if (HPEVmin+AtkEVMin + ... + SpeEVMin) > 510
print('invalid EV range')

#### Sevans

Okay then.

...I solved for EV too...

I have an EV calculator in that excel document.

The EV calculator is more to be used to see how much EVs you need to reach a stat, but I suppose it could be used on an in-game pokémon that you know the IVs of.