Skip to content

Instantly share code, notes, and snippets.

@bsima
Created November 23, 2014 01:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bsima/36891c9f2768e216fd55 to your computer and use it in GitHub Desktop.
Save bsima/36891c9f2768e216fd55 to your computer and use it in GitHub Desktop.

Compinvesti-prog-quiz

ref: http://wiki.quantsoftware.org/index.php?title=Compinvesti-prog-quiz

General Programming

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.
  1. 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).
  2. 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.
  3. 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.

Unix

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.
computer>

What should you do? - chmod a+x soccer; ./soccer

  1. What is the difference between the programs "more" and "less?"
    • more is like cat, it just outputs the file contents to stdout. less lets you navigate the file contents.
  2. How can you find which programs are running on your computer, and how much CPU they are using?
  3. vi or emacs?
    • emacs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment