<jupyter_start><jupyter_text>Recursive Hanoi Towers A number of disks is stacked in decreasing order from the bottom to the top of one rod, i.e. the largest disk at the bottom and the smallest one on top. The disks build a conical tower.    The aim of the game is to move the tower of disks from one rod to another rod. The following rules have to be obeyed:1. Only one disk may be moved at a time.2. Only the most upper disk from one of the rods can be moved in a move.3. It can be put on another rod, if this rod is empty or if the most upper disk of this rod is larger than the one which is moved.<jupyter_code>def print_move(start, target):
    """
    This function prints the details of a disk movement whenever there is one.
    """    
    print(f"move {str(start)} -> {str(target)}.")
    

def towers(disk_count, start, target, spare):
    """
    This function moves all but the last(the one at the bottom) disks to the spare peg, 
    moves the remaining one to the target peg and then moves again the ones at the spare peg 
    to the target peg, assuming that it is known to move an hanoi tower of one less disk. 
    Even if, it is not known, the function can go to the simplest hanoi tower which is 1 
    and goes up from there, recursively.
    """    
    if disk_count == 1:
        print_move(start, target)        
    else:        
        towers(disk_count-1, start, spare, target) # moves all but the biggest to the spare
        towers(1, start, target, spare)            # moves biggest to the target
        towers(disk_count-1, spare, target, start) # moves the ones at the spare to the target
towers(7, "start", "target", "spare")<jupyter_output>move start -> target.
move start -> spare.
move target -> spare.
move start -> target.
move spare -> start.
move spare -> target.
move start -> target.
move start -> spare.
move target -> spare.
move target -> start.
move spare -> start.
move target -> spare.
move start -> target.
move start -> spare.
move target -> spare.
move start -> target.
move spare -> start.
move spare -> target.
move start -> target.
move spare -> start.
move target -> spare.
move target -> start.
move spare -> start.
move spare -> target.
move start -> target.
move start -> spare.
move target -> spare.
move start -> target.
move spare -> start.
move spare -> target.
move start -> target.
move start -> spare.
move target -> spare.
move target -> start.
move spare -> start.
move target -> spare.
move start -> target.
move start -> spare.
move target -> spare.
move target -> start.
move spare -> start.
move spare -> target.
move start -> target.
move spare -> start.
move target -> spare.
move target -> start.
mov[...]
{'fraction_non_alphanumeric': 0.09324878776575904, 'fraction_numerical': 0.0033569563595673255, 'mean_word_length': 2.8314285714285714, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '537583', 'license': 'MIT', 'n_tokens_mistral': 762, 'n_tokens_neox': 741, 'n_words': 400, 'path': 'mk012-recursive_hanoi_towers.ipynb', 'repo_name': 'karakose77/intro-to-cs-and-programming-in-python-exercises', 'size': '2681'}