PART I

Simple functions

  • Write a function called palindrome that will take any list and decide whether or not is a palindrome. (A palindrome is something that is the same read forwards or backwards like "RACECAR").

In [ ]:

  • Write a function called prime that determines whether an integer number is prime. (Hint: you might want to use the modulo operator)

In [ ]:

  • Write a function called reverse_complement that returns the reverse complement of any DNA sequence.

In [ ]:

Battle Royale

In a distant, war-torn land, there are 10 castles. There are two warlords: you and your archenemy. Each castle has its own strategic value for a would-be conqueror. Specifically, the castles are worth 1, 2, 3, …, 9, and 10 victory points. You and your enemy each have 100 soldiers to distribute, any way you like, to fight at any of the 10 castles. Whoever sends more soldiers to a given castle conquers that castle and wins its victory points. If you each send the same number of troops, you split the points. You don’t know what distribution of forces your enemy has chosen until the battles begin. Whoever wins the most points wins the war.

Create a list called battle_plan that distributes your 100 soldiers among the 10 castles. Once I receive all your battle plans, I’ll adjudicate all the possible one-on-one matchups. Whoever wins the most wars wins the battle royale and is crowned king or queen of, er, something.

Source: fivethirtyeight


In [ ]:

Deadly Board Game

While traveling in the Kingdom of Arbitraria, you are accused of a heinous crime. Arbitraria decides who’s guilty or innocent not through a court system, but a board game. It’s played on a simple board: a track with sequential spaces numbered from 0 to 9. The zero space is marked “start,” and your token is placed on it. You are handed a fair six-sided die and three coins. You are allowed to place the coins on three different (nonzero) spaces. Once placed, the coins may not be moved.

After placing the three coins, you roll the dice and move your token forward the appropriate number of spaces. If, after moving the token, it lands on a space with a coin on it, you are freed. If not, you roll again and continue moving forward. If your token passes all three coins without landing on one, you are executed. On which three spaces should you place the coins to maximize your chances of survival?

Create a list called coin_placement that has the three spaces on which you should place the coins.

Hint: you might want to check out random.choice here and itertools.combinations here.

Source: fivethirtyeight


In [ ]:

PART II

Goals

Conceptual

  • Understand how docs are built in python for figuring out how functions and other programing elements "on-the-fly."
  • Learn that it's okay to mess around to figure out a program.

Skill

  • Be able to figure out the parts of a library you need to be successful given that library and its documentation.
  • Learn how to land a rocket in an emergency.

Rocket Landing

You are in a rocket falling from 1000 m above the surface of an alien world. You need to program the computer to fire the thrusters to land safely. Fortunately the rocket is controlled by python. Unfortunately, you don't have a software manual. You'll have to figure out how to land the rocket given only the code itself.

Objective

Modify the code below so the rocket lands safely. We'll test your approach using a fresh version of rocket.Rocket, so no hacking the rocket to win.

Hints

API:

  • Tab-complete and help() are your friends
  • Feel free to mess around and explore the code

Rocket:

  • Graphs will help a lot
  • Use different thrust levels for different altitudes
  • Make the amount of thrust depend on the velocity

In [ ]:
import rocket

R = rocket.Rocket()
while R.alive and not R.landed:

    # <- Your code here ->
    R.update()