# Program 02: Culberson
# Second Example in the notes
# draws a spiral with length based on initial pile

# pick all the beepers in current location
define get_all {
    while (next_to_a_beeper) {
        pick_beeper
    }
}

define make_side {
    while (has_beeper(0)) {
        move_beeper(0,1)
        create_beeper
        move
    }
}

# restores beepers from bag 1 to bag 0
# and then reduces by one
define restore_bag {
    while (has_beeper(1)) {
        move_beeper(1,0)
    }
    # reduce the number by one
    put_beeper
    destroy_beeper
}

define main {
    get_all
    while (has_beeper(0)){
        make_side
	# restore and reduce for next side.
        restore_bag
        turn_left
    }
        
}
