CSc 2010
Lab Assignment 2
Due: 11 February, 2010
  1. A non-robot problem (Should be submitted independently). Consider numbers in the range 1000 to 9999 which do not have repeating digits. Given two such numbers, we define the number of BULLS and COWS for the pair of numbers as follows:
    BULLS = number of digits that appear in the same positions in the two numbers.
    COWS = number of digits that appear in both the numbers, but at different positions.
    
    For example, if the two numbers were 2367 and 1327, we have 2 BULLS (for the exact matches for digits 3 and 7) and 1 COW (for the remaining common digit 2 which is in different positions in the two numbers). If the numbers were 9852 and 8926, we have 0 BULLS and 3 COWS and if the numbers were 1234 and 4321, we have 0 BULLS and 4 COWS. It is quite clear that if the two numbers are the same, we have 4 BULLS and 0 COWS.

    Implement the following functions in Python:

    Submit the code under the file Bulls.py.

  2. A robot problem (Done as a team with one submission per team). Write a Python program, called RandomMoves that performs the following actions:
    1. Prompts the user for input as follows:
      Enter the number of seconds for robot to move:
      Enter the maximum number of stalls before quitting (at most 5): 
      
    2. Moves the robot forward at full speed for the time period specified by the user or until it reaches the maximum number of stalls. Each time the robot gets stuck, the program should speak one of the following messages (depending on the number of times it has stalled):
      I am stuck for the first time.
      I am stuck for the second time.
      I am stuck for the third time.
      I am stuck for the fourth time.
      I am stuck for the fifth time.
      
      After speaking the message, the robot should move backward at full speed for 0.5 seconds and then turn left or right (chosen randomly) for a random amount of time between 0 and 1 seconds. After which it continues to move forward at full speed.
    3. After the time has elapsed or the maximum number of stalls have been detected, the program displays a dialog box containing the message Continue? along with Yes and No buttons. If the user presses the Yes button, the program starts over again. If the user presses the No button, the program displays the time elapsed in seconds from the beginning along with the drop in battery voltage since the beginning.
    You must write the program with at least two functions (including main()). Here is a sample run of the program:
    Enter the number of seconds for robot to move: 15
    Enter the maximum number of stalls before quitting (at most 5): 3
    I am stuck for the first time.
    I am stuck for the second time.
    Enter the number of seconds for robot to move: 5
    Enter the maximum number of stalls before quitting (at most 5): 3
    I am stuck for the first time.
    Elapsed Time: 27.3323 seconds
    Drop in battery voltage: 0.03765 volts
    
    Email your submissions to raj@cs.gsu.edu (Bulls.py and RandomMoves.py) by midnight of the due date to receive full credit. Note: Bulls.py is an independent assignment - so, each of you will submit this independently; RandomMoves.py should be submitted one per group.

    IMPORTANT: Please include "CSc 2010 Bulls.py" and "CSc 2010 RandomMoves.py" in the SUBJECT of your email.