1. A method for optimizing state assignments for a finite state machine, the method comprising: generating a random initial state assignment for each of a plurality of states of the finite state machine; determining, using processing circuitry, an initial cost associated with the random initial state assignments; identifying, using the processing circuitry, a code swap to explore as a function of a code swap probability; calculating a cost for the code swap when one or more criteria is satisfied, the one or more criteria include one or more of an indication of whether the code swap has not been explored in a current round, a solution associated with the code swap was not previously generated, a round is not repeated wherein the round is an iteration where all pairs of code swaps are considered, and a maximum predetermined number of code swaps by round is not exceeded, the maximum predetermined number of code swaps by round being a function of a number of hill climb taken in a period, the period starting when a current solution does not improve after finishing a round and ending when a best solution is found; updating, using the processing circuitry, the code swap probability as a function of the cost of the code swap and a best cost; performing the code swap, when the cost of the swap is smaller than the best cost and/or a current cost, to optimize the state assignments; outputting optimized state assignments; and implementing a physical circuit including one or more flip flops based on the optimized state assignments.