The process described in "Chromosome to cycle1" is in fact invertible, as described by the following pseudocode.

CycleToChromosome(N)
    for j ← 1 to |N| / 2
        if n2j - 1 < n2j
            cj ← n2j / 2
        else
            cj ← −n2j − 1 / 2
    return C

Assignment

Add a method to_chromosome to the class Cycle that takes no arguments. The method must implement CycleToChromosome on cycles that correspond to chromosomes and return the corresponding chromosome (an object of the class Chromosome).

Example

>>> Cycle(1, 2, 4, 3, 6, 5, 7, 8).to_chromosome()
Chromosome(1, -2, -3, 4)