def period(dance):
    """Number of dance iterations until programs return to starting positions.
    """
    seen_positions = {str(dance)}
    cycles = 0

    while True:
        dance.perform()
        cycles += 1
        positions = str(dance)

        if positions in seen_positions:
            break

        seen_positions.add(positions)

    return cycles