Perhaps the most important concept to understand in order to see how all this works is the concept of permutations. A permutation, is a possible arrangement of a series. The number of permutations in a series is the number of all possible arrangements of a given set. So for example, in the set (1,2) there are 2 permutations (1,2) and (2,1). This is represented by the symbol n!, so 2! = 2. If the set has three elements (a,b,c) there are 6 possible permutations, so 3! = 6. The number of permutations increases exponentially:

0! = 0
1! = 1
2! = 2
3! = 6
4! = 24
5! = 120
6! = 720
7! = 5,040
8! = 40,320
9! = 362,880
10! = 3,628,800
11! = 39,916,800
12! = 479,001,600
13! = 6,227,020,800

48! = 12,413,915,592,536,072,670,862,289,047,373,375,038,521,486,354,677,760,000,000,000

Originally, when I set out to do this project I wanted to calculate all possible permutations for all 48 continental capitals of the United States, but this number quickly showed that having all possible permutations of this would be quite difficult. I could have found the quickest route using something like The Travelling Salesman Problem, but finding the quickest route wasn’t really the point of all this. Instead, I wanted to see if I could, through knowing all possible combinations figure out the quickest way myself. In a way, gamify the experience. It is because of this that I limited all possibilities to a maximum of 9 items in a set. This is equal to 9! =   362,880, which divided but 2 (to account for the fact that there it includes the reverse of each one) is 181,440.

The formula for finding this is “n × (n − 1) × (n − 2) … × (n − k + 1)”". In python, I calculated the possibilities the following way (i being the number of elements in the arrangement):

To generate an list of all possible permutations, given a a set of elements, the function used is the following: