Saturday, October 20, 2018

Interlude: Pokemon Hexagons

Happy Celebration of Mind Day! In the spirit of Martin Gardner, let's do some mathematics that's as approachable and intuitive as possible.

Let's take a little break from the Rose problems and talk about Pokemon. Love the games to this day, especially all the self-imposed challenges you can do. So, I was very excited to see graphics of Pokémon stat spreads as hexagons in an article recently, and of course it immediately got me thinking of a math problem.

For those of you who don’t know much about Pokémon, all species of Pokémon have “base stats”, which are measures of their competency in various areas. Each Pokémon has a stat for HP (Hit Points), Attack, Defense, Special Attack, Special Defense, and Speed. Base stats don’t seem to necessarily have an upper limit, but the highest existing base stat is Blissey’s 255 Base HP. There are a lot of other factors that determine a Pokémon’s actual stats, but we’re only concerned about their base stats for this problem.

The question that immediately came to my mind was, which Pokémon has the stat hexagon with the most area? Which Pokémon have a lot of area despite poor stats?


Here’s some example Pokémon hexagons. The first three are Abra, Kadabra, and Alakazam – an evolutionary line of Pokémon focused on Speed and Special Attack. Below them are Rhyhorn and Rhydon, an evolutionary line focused on HP, Attack, and Defense. And on the right we see Mew and Mewtwo, the legendary Pokémon from Generation I.

The order of the stats around the hexagon are important: Rhydon has a sizeable chunk of area because its HP, Attack, and Defense are all high and they’re right next to each other. (The order was decided by the article, and I kept the same it to answer my original question.) Obviously Pokémon with higher stats, like fully evolved Pokémon and legendaries, will have hexagons of larger area. But how should we distribute stats to get the most possible area?

It was at this point that I made a guess. I don’t know many of the newer Pokémon nearly well enough to make a great guess, but my intuition told me that something with very unbalanced stats would be the best shot at getting a high area. I went with Rhyperior, Rhydon's evolution, as the non-Mega non-legendary Pokémon with the most area, because it has gargantuan Attack, Defense, and HP, but next to nothing in the other three stats.

Now that I have a guess, let’s get to solving the problem. Let’s start by expressing it mathematically: you have six nonnegative radial lengths defining a hexagon. You also have a limitation that the sum of these lengths must equal a given constant. What radial lengths can you choose to optimize the area of the final hexagon?

This particular kind of hexagon is easy to find the area of, luckily. You can break it into triangles along the radial lines, and add up the areas of the six triangles for the area of the hexagon. Even more conveniently, we can use the 1/2(ab sin(C)) equation for a triangle’s area, which spits out a very convenient formula for us to maximize: (1/2)(sin 60)(ab + bc + cd + de + ef + fa). We can ignore the constant, because 2x will always be greater than 2y if x > y, so that leaves us with (ab + bc + cd + de + ef + fa), or the sum of adjacent products of base stats. Attack x Defense, Defense x HP, HP x Special Attack, and so on.

Now, how do we maximize this? Let’s try some test cases. I’ll use 600 as the base stat total, both because it’s conveniently divisible by six and because it is the actual base stat total of several Pokémon.

Case 1: Straight 100s across the board. The area of the hexagon (before the constant) is 60,000.

Case 2: 150, 50, 150, 50, 150, 50. The area is only 45,000.

Case 3: 50, 50, 50, 150, 150, 150. The area is 65,000. We’re getting warmer!

Case 4: 0, 0, 0, 200, 200, 200. The area shoots up to 80,000!

Case 5: 0, 0, 0, 0, 300, 300. The area maxes out at 90,000!

Case 6: 0, 0, 0, 0, 200, 400. We’re back to 80,000, which means we have our answer.

It turns out that a Pokémon with only Attack and Defense would have a greater hexagon area than any other distribution of its stat total! The way to maximize the sum of adjacent products of a list of six is to make two of the numbers as large as possible, and equal! Does this work with an arbitrarily large or small set? What if you used products of three numbers, like (abc + bcd + cde + ...)? Most importantly, it means my intuition was right, kinda!

I crunched the numbers (and made a little Excel tool for viewing any Pokémon’s hexagon, as well as its total area), and I was close, if not exactly right. The first non-legendary of the list, is Slaking, with a base stat total greater than most legendaries. Then there’s Garchomp, Metagross, Goodra– Pokémon known for being solid all around with maybe one exceptional stat. A heap of legendaries later, Rhyperior, the 15th non-mega non-beast non-legendary on the list. Feels like I’m having to invent rules to be right, but I’m still gonna round that up to a win. J

Wednesday, October 3, 2018

Rose IV: 4 and N Dimensional Staircases



Yikes, four dimensions. As if visualizing a three-dimensional space of colored and uncolored points wasn’t complicated enough. In the last post, we showed that a 3D staircase coloring works as an optimal solution for the Rose Problems we were discussing, but now we have to try and extend that to higher dimensions. Luckily, we happen to live in a four-dimensional world: three spatial dimensions and one temporal dimension, and I find visualizations in this mixed space are actually not that bad.

Let me just start with a simple example to introduce the idea of thinking in this 4D space. I’m going to call it (3+1)space, because it’s three dimensions of one type and one dimension of another, as opposed to a true 4D space, with all four dimensions of the same type.

Imagine four blocks in a row horizontally across a table. Now imagine that you pick them up and lay them on the table so they’re oriented vertically along it. Or in a stack on top of each other. It doesn’t take much mental effort to view those changes as a “rotation”. They were along one axis, or dimension, and you aligned them with another axis, but kept the object itself very much the same. Now, imagine rotating the four blocks along the axis of time. You’d see one block, and then it would be replaced with the next one, and the next one, and the last one, and then there would be nothing.


These three shapes are the same, two along a spatial dimension, and one along a temporal dimension. There’s a lot of fun you can have with this, but perhaps we’ll talk about that another time. For now, let’s return to our transformation of the 3D staircases to 4D. We’re not rotating anything (yet), but you will need that (3+1)D visualization skill to picture the next part.

Let’s say we’re in four dimensions, and our rule is “two colored points in a row is not allowed”. The two dimensional solution to that is a 2D staircase that looks like this:
  


And the 3D solution is just layers of that solution, staggered so they don’t overlap. The (3+1)D solution will just be that 3D solution, swapping which dots are colored every unit of time!



We can easily verify this, too! We know that there will never be two in a row along any of the spatial directions, because that was point of the 3D staircase proof. Now, if we focus on a single point in time, there will never be two consecutive moments when it’s colored. And the wonderful thing about our (3+1)D system is that it’s completely equivalent to a 4D system. It’s a lot easier to visualize, but any rules or discoveries here apply there, too! Therefore, the 4D staircase works!

It’s pretty easy to show that 4D staircases work for other similar rules, too. Here’s animations of the “three-in-a-row” and “four-in-a-row” rules, if you’re still skeptical. I can’t show all four dimensions because of the limitations of computer screens, but you get the picture.





I find these mesmerizing. It’s “perfect”, in a way, how the length, width, and temporal height of the rows of colored points are all the same. Try staring at one point to see the temporal height, and you'll notice that it's the same pattern as the vertical and horizontal!

And now, the jump to N dimensions. The technique I’ll be using is based on the imagining 4D as (3+1)D discussion earlier, but it has a much wider scope. I can perform an easy-to-visualize inductive proof on the number of dimensions by using the following transformation: N dimensions à N dimensions + 1 temporal dimension à N+1 dimensions.

Let me break down the technique. Let’s say we have some N dimensional space on which something works, like our staircase configuration. I may not be able to visualize this space, but I can visualize a single point, line, or plane of this space varying in time. If I can verify that the rule works, I can say that the new space has N + 1 dimensions, and do the same thing again to inductively prove that it works for any number of dimensions. This technique isn’t exactly a revelation in terms of the simple induction behind it, but it is excellent for helping me (and hopefully you) visualize what’s going on. Math is at its best when we have that intuitive understanding of what’s happening, not just a surface level knowledge of what technique to use.

And there we have it. It doesn’t matter what dimension we start in; we can show that the temporal direction in any staircase will work if the space is staggered, so we have now shown, that for any rule of the form “X colored points in a row is not allowed” on any standard N-dimensional space, we have a solution for the greatest percentage of that space you can cover. The solution is given by the Staircase coloring specific to (X, N), and the percentage of the space covered is (X – 1) / X.

That’s… a big deal. There’s a lot more to figure out here, but we’ve conclusively knocked out a lot of cases of a huge problem. More on that next time.