What does this code do:

import stanford.karel.SuperKarel;
public class Homework extends SuperKarel {

 /\* You fill the code here \*/
 private int xLength = 1;
 private int yLength = 1;
 private int moves = 0;

 // Counter Height and width of world
 private void countLength(String direction)
 {
 // Find world horizontal length
 while(frontIsClear())
 {
 if (direction == "hor") xLength++; else yLength++;
 moveAndCount();
 }
 }

 // Print Move Counter + Move karel
 private void moveAndCount()
 {
 move();
 moves++;
 System.out.print("\r" + "Number of moves: " + moves);
 }

 // Keep moving until you hit a wall + able to put beepers
 private void moveInfinitely(boolean putBeeper)
 {
 while(frontIsClear())
 {
 moveAndCount();

 // If you should put beepers while moving
 if(putBeeper)
 putBeeper();
 }
 }

 // Recursive function to do vertical then horizontal division (the least lines of code found)
 private void divideWorld(String direction)
 {
 // Border cannot be created if world vertical length less than 3
 if((direction == "ver" ? xLength : yLength) < 3)
 {
 // If vertical division failed, let's try horizontal split before returning to caller
 if(direction == "ver")
 {
 divideWorld("hor");
 return;
 }

 return;
 }

 // Extra steps to take if we're dividing world horizontally
 if(direction == "hor")
 {
 // Boolean to check if karel is bottom of world or top
 boolean karelIsOnTop = false;

 // Move karel to far left of world depending on current direction
 if(facingNorth())
 {
 karelIsOnTop = true;
 turnLeft();
 }
 else
 {
 turnLeft();
 turnLeft();
 turnLeft();
 }

 // Move to far left
 moveInfinitely(false);

 // Turn karel to direction of middle of the world
 if(karelIsOnTop)
 {
 turnLeft();
 }
 else
 {
 turnLeft();
 turnLeft();
 turnLeft();
 }
 }

 // Move karel to middle of world
 int moveKarelMiddle = (direction == "ver" ? xLength : yLength) / 2;

 // If dividing vertically based on karel's current context, we need to turn left
 if(direction == "ver") turnLeft();

 for(int i = 0; i < moveKarelMiddle; i++)
 {
 moveAndCount();
 }

 // Check if world vertical/horizontal length odd or even before dividing
 if((direction == "ver" ? xLength : yLength) % 2 == 0)
 {
 // Turn karel to correct direction for split
 turnLeft();

 // If length is even, then we create a width border of 2
 putBeeper();

 // Move forward while placing beepers
 moveInfinitely(true);

 // Move karel to the right once to draw 2nd border
 turnLeft();
 moveAndCount();
 putBeeper();
 turnLeft();

 // Move upwards while placing beepers
 moveInfinitely(true);
 }
 else
 {
 // Turn karel based on direction they came from
 if(facingNorth() && direction == "hor")
 {
 turnLeft();
 turnLeft();
 turnLeft();
 }
 else
 {
 turnLeft();
 }

 // If length is odd, then we create a width border of 1
 putBeeper();

 // Move downwards while placing beepers
 moveInfinitely(true);
 }

 // Call function again but for horizontal division, if done that, return to caller function
 if(direction == "ver")
 divideWorld("hor");
 if(direction == "hor")
 return;
 }

 public void run()
 {
 // Clear coordinates when trying new worlds
 yLength = 1;
 xLength = 1;
 moves = 0;

 // Set beepers to 1000 as requested
 setBeepersInBag(1000);

 // Find world horizontal length
 countLength("hor");
 // Find world vertical length
 turnLeft();
 countLength("ver");

 divideWorld("ver");
 }
}
user