From Quantwiki
Jump to: navigation, search


Here's a self test you can take to see if you have strong programming skills. For each of these questions, feel free to use your programming language of choice. The questions are progressively more challenging:

  1. Write a program to generate 100 random integers between 1 and 100. It should generate exactly the same numbers each time you run it. Bonus: If you wonder whether the distribution should be normal or uniform, give yourself extra points.
  2. Write a program to sort a list of numbers provided on standard input (for instance, the numbers you generated above). You are NOT allowed to call external routines to do the sorting for you. After sorting the numbers, print them out. Focus on a simple method (not an efficient method).
  3. Write a program that can read in a list of words and convert each word into an integer, and a separate program that convert integers into words. The program should work with words up to 10 characters in length. It should generate integers in the range 0 to N^10, where N is the number of characters in the alphabet you are using. If N=26, then your maximum value would be 26^10 = 141167095653376.
  4. Write a program to discover the answer to this puzzle:"Let's say men and women are paid equally (from the same uniform distribution). If women date randomly and marry the first man with a higher salary, what fraction of the population will get married?"

You should be able to complete #1 in less than ten minutes, #2 in less than 20 minutes, and #3 in less than 45 minutes. Even if it takes you longer than this, it is OK, but you should plan extra time for the course.

If you cannot complete these questions you should not take the course.


Here are some separate questions regarding Unix expertise. If the course you are taking requires Unix, you should be able to answer these questions quickly.

  1. Suppose you have opened a terminal window on a Unix machine and you are attempting to run the program named "soccer." You see the following on your screen:
    computer> cd Desktop/Downloads/asciisoccer
    computer> ls
    CONTEST_RULES	index.html	libwestcommon.a	soccer.c	teams
    NEW		libeast.a	makefile	soccer.h	temp.txt
    cleanteams	libeastcommon.a	players.h	soccer.o
    contest		libwest.a	soccer		suggestions
    computer> soccer
    soccer: Command not found.

    What should you do?

  2. What is the difference between the programs "more" and "less?"
  3. How can you find which programs are running on your computer, and how much CPU they are using?
  4. vi or emacs?

Convert words to numbers and back

You are to implement two programs in Python: and should have the following functionality:

  • Objective: convert english words to numbers.
  • Assume all text is in lower case
  • Support words up to 10 characters in length.
  • Support English text (i.e., no need to support non-ASCII characters).
  • Process one word at a time and convert it to a whole number.
  • Output the numbers to a text file should have the following functionality:

  • Read in a file like numbers.txt one line at a time and output words.txt -- a file with one word per line.

The output to numbers.txt might look like this:


Note that the above list of numbers is NOT intended to be correct. The numbers your code calculates will depend on the method you use. Finally the output from might look like this: