Space Invaders

Earth is being invaded by martians. Here's a description of the Martian fleet:

  1. The Martians have some spaceships.
  2. Each spaceship is either a mother ship or a drone.
  3. A mother ship has a name, which is a String, a crew, which is a list of Martians, and a possibly-empty set of daughter ships, each of which is a spaceship.
  4. A drone has no attributes.
  5. When we say the fleet of a spaceship, we mean her daughter ships and all their fleets.
  6. A Martian has a name, which is a string, and some other attributes, which are unspecified.

Write data definitions for the information in this problem.

Write the contract and function definition only for each of the following tasks. If you use any help functions, write a contract and purpose statement for each help function you introduce.

  1. Given a spaceship, how many Martians named "Mork" are in the crew of either the spaceship or its fleet?
  2. Given a spaceship, return another spaceship just like the original, except that all of its daughters that are drones have been removed.
  3. Given a spaceship, return another spaceship just like the original, except that all of its daughters who have a crewmember named "Mork" have been removed. When a daughter is removed from the fleet, so are all its daughters and their fleets.
  4. Given a spaceship, return another spaceship just like the original, except that every ship in its fleet who has a crewmember named "Mork" has been removed. When a ship is removed from the fleet, so are all its daughters and their fleets.
  5. Given a spaceship, return another ship just like the original, except that all of its daughters who have a crewmember named "Mork" have been removed. When a daughter is removed from the fleet, each of its daughters (a grand-daughter of the given spaceship) are promoted to become a daughter of the given spaceship, even if it has a Mork in its crew.
  6. Given a fleet of spaceships, return another fleet just like the original, except that every ship in the fleet who has a crewmember named "Mork" have been removed. When a ship is removed from the fleet, its daughters are promoted to become a daughter of the nearest ancestor that does not have a "Mork" in its crew.

Last modified: Sat Oct 7 10:52:41 Eastern Daylight Time 2017