iniciar-programa
define-nueva-instruccion norte como mientras no-orientado-al-norte hacer gira-izquierda;
define-nueva-instruccion sur como mientras no-orientado-al-sur hacer gira-izquierda;
define-nueva-instruccion oeste como mientras no-orientado-al-oeste hacer gira-izquierda;
define-nueva-instruccion este como mientras no-orientado-al-este hacer gira-izquierda;
define-nueva-instruccion contar como
    inicio
        mientras frente-libre hacer avanza;
        oeste;
        mientras frente-libre hacer
            inicio
                si no-junto-a-zumbador y frente-libre entonces avanzA;
                si junto-a-zumbador entonces
                    inicio
                        coge-zumbador;
                        si junto-a-zumbador entonces
                            inicio
                                deja-zumbador;
                                si frente-libre entonces avanza;
                            fin;
                    fin;
            fin;
         si frente-bloqueado entonces
             inicio
                 oeste;
                 mientras frente-libre hacer avanza;
                 mientras algun-zumbador-en-la-mochila hacer deja-zumbador;
             fin;
    fin;
define-nueva-instruccion RecogeYDeja como
    inicio
        mientras junto-a-zumbador hacer
            inicio
                mientras junto-a-zumbador hacer coge-zumbador;
                sur;
                mientras frente-libre hacer avanza;
                oeste;
                mientras frente-libre hacer avanza;
                sur;
                mientras frente-libre hacer avanza;
                este;
                avanza;
                mientras algun-zumbador-en-la-mochila hacer
                    inicio
                        deja-zumbador;
                        si algun-zumbador-en-la-mochila entonces avanza;
                    fin;
                si ningun-zumbador-en-la-mochila entonces
                    inicio
                        oeste;
                        avanza;
                        mientras junto-a-zumbador hacer
                            inicio
                                coge-zumbador;
                                si frente-libre entonces avanza;
                            fin;
                        si frente-bloqueado entonces
                            inicio
                                mientras algun-zumbador-en-la-mochila hacer deja-zumbador;
                                norte;
                                avanza;
                            fin;
                    fin;
            fin;
    fin;
define-nueva-instruccion JuntarYAcomodar como
    inicio
       mientras no-junto-a-zumbador y frente-libre hacer avanza;
       si junto-a-zumbador entonces RecogeYDeja;
       si frente-bloqueado entonces
           inicio
               este;
               si frente-libre entonces
                   inicio
                       avanza;
                   fin sino
                           inicio
                               sur;
                               mientras frente-libre hacer avanza;
                               oeste;
                               mientras frente-libre hacer avanza;
                               sur;
                               avanza;
                               mientras junto-a-zumbador hacer coge-zumbador;
                               norte;
                               avanza;
                               mientras algun-zumbador-en-la-mochila hacer deja-zumbador;
                               sur;
                               avanzA;
                               este;
                               mientras frente-libre hacer contar;
                               apagate;
                           fin;
               sur;
               mientras frente-libre hacer avanza;
               norte;
           fin;
    fin;
    inicia-ejecucion
        norte;
        avanza;
        mientras frente-libre hacer JuntarYAcomodar;
        apagate;
    termina-ejecucion
finalizar-programa
