------------------------------------------------------------------------------- Michael Locasto Introduction to Computer Programming in C Homework 3 Fall 2005 $Id: hw3.txt,v 1.3 2005/11/22 17:31:37 locasto Exp $ ------------------------------------------------------------------------------- Due: November 22nd, 2005 Before Class (Courseworks timestamp). 0) Checksum a file. (40 pts) Create a checksum program that can read in a file and produce a value to be used as a checksum of the file. A checksum value ensures that a file has not been changed in transit. This program is similar to the md5sum and sha1sum programs commonly distributed with the Linux platform. Your tool should be called csum and should take an argument specifying which file to process and the particular checksum algorithm to use. Command line usage: csum --file [file] --algorithm [name] csum --file [file] csum --help | -h csum --version | -v Where the algorithm name is one of: * xor (default) * parity * mod32sum This assignment challenges you to deal with command line arguments and file I/O. You should also provide a generic calc_sum() function that can perform different checksum algorithms based on the command line parameters. XOR: take each byte and XOR with the previous result PARITY: take each bit and add it to the next MOD32SUM: take each byte, mod by 32, and add it Questions: 1. Which is the best checksum algorithm? Why? Extra Credit: (20 pts) Add the md5 algorithm to your program. This means that you have to go look up the source code for md5 and see what it means to use it as a checksum. 1) Learn to play roulette. (60 pts) Roulette is a popular game of chance. Professor Candide believes that roulette is a losing game, but Professor Hulme assures him that there exist strategies that can win. Provide a rough proof that Professor Candide is correct. If you cannot, then show that Professor Hulme is correct (that is, there exists at least one winning strategy). Hint: not playing is *not* a winning strategy. Hint 2: use proof by contradiction. Hint 3: use proof by sheer math. (10 pts) Although I am not requiring a formal proof, even an informal proof requires some knowledge of how roulette is played. Write a program to play roulette. The computer acts as the house and the user acts as the gambler. (40 pts) Your program should play roulette as follows: There are 38 spots on the board. Play proceeds by having each player place their bets on the board. The house halts betting at a certain time and spins the roulette wheel, producing a random number. Winning bets are paid out and losing bets are collected by the house. Then the house signals that players are free to begin placing bets again. Players must either place their bets completely *inside* or completely *outside* (these terms will become clear when you read further). The minimum bet for your program is 5 dollars. Players can have $1 chips, $5 chips, $20 chips, or $100 chips. The maximum bet is $5000 dollars. Payouts of over 1 000 000 must be authorized by the house. The roulette board is divided into a number of categories. There are 38 numbers: 1 to 36 and 0 and 00. Numbers are either odd or even (except 0 or 00), red or black (except 0 or 00), in 1 of 3 columns, in 1 of 3 rows. Your program does not have to deal with bets that are placed between numbers or columns (on 'corners'). Bets must be completely 'inside' (i.e., on a specific number) or completely 'outside' (i.e., one of the other aggregate categories). Payouts are calculated at these odds: any hit on a single number is paid out at 35:1. Any red/black or odd/even hit is paid 1:1. Any column or row hit is paid 2:1. If the gambler does not hit, the house collects the entire bet, except for a special case. Questions: (10 pts) 0) Formulate a good strategy (a good strategy tries to keep the odds as even as possible or in the favor of the player). 1) Is it possible to have a payout of over 1 000 000? 2) What is the expected value of your winnings if you bet 5 dollars once? 3) What is the expected value of your winnings if you bet 5 dollars 10 times in a row? 4) What happens if you bet odd/even or red/black and 0 or 00 comes up?