Skip to content

Latest commit

 

History

History
131 lines (100 loc) · 2.67 KB

File metadata and controls

131 lines (100 loc) · 2.67 KB

Week 1

Jigsaw Karel

Description: Jigsaw Karel solves a maze, places the last beeper in the correct spot, and returns to the starting position.
Code:

def main():
    """
    Karel organizes her world by putting a misplaced beeper perfectly back into its place within a puzzle of organized beepers.
    Karel then returns back to her original corner, pridefully admiring her accomplishment. 
    """
    move_to_beeper()
    place_beeper_correctly()
    return_to_start()
    
def move_to_beeper():
    """Moves Karel to the location of the beeper."""
    move()
    move()

def place_beeper_correctly():
    """Karel picks up the beeper and places it in the correct spot in the puzzle."""
    pick_beeper()
    move()
    turn_left()
    move()
    move()
    put_beeper()

def return_to_start():
    """Karel returns to the starting position."""
    turn_around()
    move()
    move()
    turn_right()
    move()
    move()
    move()
    turn_around()

def turn_around():
    """Turns Karel around by 180 degrees."""
    turn_left()
    turn_left()

def turn_right():
    """Turns Karel to the right."""
    turn_left()
    turn_left()
    turn_left()

if __name__ == '__main__':
    main()

Result:

ezgif com-video-to-gif-converter (1)


2023 Karel

Description: Karel places 20 and 23 beepers to create the year 2023 while ending facing East to the right of the 23 beepers.

Code:

def main():
    for i in range(20):
        put_beeper()
    move()
    for i in range(23): 
        put_beeper()
    move()
        
if __name__ == '__main__':
    main()

Result:

ezgif com-video-to-gif-converter (2)


Stone Mason Karel

Description:Stone Mason Karel rebuilds a series of columns along a path.
Code:

def rebuild_columns():
    while front_is_clear():
        repair_column()
        move_to_next_column()
    # Additional code logic here

def repair_column():
    turn_left()
    while front_is_clear():
        put_beeper()
        move()
    turn_around()
    move_to_wall()
    turn_left()

def move_to_next_column():
    for i in range(4):
        if front_is_clear():
            move()

def turn_right():
    for i in range(3):
        turn_left()

def turn_around():
    turn_left()
    turn_left()

def move_to_wall():
    while front_is_clear():
        move()

Result:

ezgif-7-225fb41a8b