The NYTimes posted a fun, educational game to illustrate gerrymandering. The game deals with an imaginary state called Hexapolis - a map of which looks something like so:
The map consists of 135 hexagonal precincts with equal population 1. Each precinct belongs to one of two parties; there are 60 yellow precincts and 75 purple. In addition, 41 of the precincts belong to a minority with some legal protection; those precincts are indicated with a bold border on its inner hexagon.
To play the game, you must partition the map into 9 districts of 15 precincts each. By law, two of your districts must be more than 50% minority. Note that
Thus, we might expect a fair map to consist of 4 predominantly yellow districts and 5 predominantly purple. On the other hand, we’d say that the partition is skewed purple if there are more than 5 purple districts, and we’d say that the partition is skewed yellow if there are more than 4 purple districts.
The objective of the game is to see how far you can skew the partition in one direction or the other. You can earn bonus points by keeping your districts relatively compact. The objective of this notebook is to set the game up so that programmers can try their hand at writing gerrymandering software on Observable.
According to information you get from the NY Times after playing, it’s possible to partition Hexapolis so that all districts lean purple. They also indicate it’s possible to partition Hexapolis so that 7 districts lean yellow, but not 8.
This paper on the ArXive describes some gerrymandering algorithms at a fairly high level. Using the techniques they call Flood Fill to set up some initial districts followed by a Flip Step Walk to improve them, I found it pretty easy to 8 purple districts and 6 yellow. I’ve not achieved the maxima just yet, though.
All of the above is pretty much exactly the following notebook (of course, the notebook has code, though):