A formula for the permanent of a matrix perm(a_(i j)) = (-1)^n sum_(s⊆{1, ..., n}) (-1)^( left bracketing bar s right bracketing bar ) product_(i = 1)^n sum_(j element s) a_(i j), where the sum is over all subsets of {1, ..., n}, and left bracketing bar s right bracketing bar is the number of elements in s. The formula can be optimized by picking the subsets so that only a single element is changed at a time (which is precisely a Gray code), reducing the number of additions from n^2 to n. It turns out that the number of disks moved after the kth step in the tower of Hanoi is the same as the element which needs to be added or deleted in the kth addend of the Ryser formula.