Link back to syllabus

Click here to start assignment

Like all assignments, you will complete this assignment via GitHub. See the submission instructions for how to get the starter code and how to submit this assignment.

  1. Evens first (10 pts)

    Write a program (in evens.c) that asks the user for up to ten numbers. The user indicates that they are done entering numbers by entering a 0. Print out all the even numbers, then all the odd numbers.

    For example, here is a sample session, with user input in bold:

    Enter some numbers:
    5
    2
    3
    4
    10
    1
    0
    2
    4
    10
    5
    3
    1

  2. Triple-Up (20 pts)

    Write a program (in triple.c) that asks the user for up to ten numbers. The user indicates that they are done entering numbers by entering a 0. Determine whether or not there is a run of three consecutive numbers in the list. If there is, print out “run found” and then print out all the numbers the user entered except for the run of three consecutive numbers. If there is no such run, print out “no run”.

    If there are multiple such runs or a run of more than three numbers, consider only the first three numbers forming a run.

    For example, here are two sample sessions, with user input in bold:

    Enter some numbers:
    5
    2
    3
    4
    10
    1
    0
    run found
    5
    10
    1

    Enter some numbers:
    5
    2
    8
    4
    10
    1
    0
    no run

  3. 15 (70 pts)

    Write a program (in fifteen.c) that allows a user to play the “Fifteen puzzle”. (For example, see this app.) Your program does not need to solve the puzzle; it just lets the user play.

    Your puzzle will start out in this state:

     1 10 15  4
    13  6  3  8
     2  9 12  7
    14  5    11

    (This starting position, as found here, is also a magic square with all rows, columns, and the two major diagonals adding up to 30.)

    Your program will print out the square, ask the user what tile they would like to move, and then move the tile, repeating until the puzzle is solved. When the puzzle is solved, it reports so and quits.

    Here is the start of an example session:

      1 10 15  4
     13  6  3  8
      2  9 12  7
     14  5    11
    
    Enter the tile you would like to move: 12
    
      1 10 15  4
     13  6  3  8
      2  9     7
     14  5 12 11
    
    Enter the tile you would like to move: 7
    
      1 10 15  4
     13  6  3  8
      2  9  7   
     14  5 12 11
    
    Enter the tile you would like to move: 4
    I can't move that tile.
    
      1 10 15  4
     13  6  3  8
      2  9  7   
     14  5 12 11
    
    Enter the tile you would like to move: 18
    Invalid tile.
    
      1 10 15  4
     13  6  3  8
      2  9  7   
     14  5 12 11
    
    Enter the tile you would like to move: 11
    
      1 10 15  4
     13  6  3  8
      2  9  7 11
     14  5 12   
    
    Enter the tile you would like to move:

    You do not need to provide the user a way to quit, expecting them to use Ctrl+C to kill the program.

    With the starting puzzle as above, the following sequence of moves will solve it:

    12 9 2 13 6 3 15 10 3 2 5 14 13 5 9 15 10 4 8 7 11 12 15 10 7 8 4 3 2 6 5 9 10 11 12

    You may paste that line into an empty file and then feed it to your program (using < on the command line) to check your algorithm for detecting when the puzzle is solved.

    We will be testing your work using input like the string of numbers above, so please do not change your interface such that inputting just a bunch of numbers causes misbehavior. (For example, no checks for confirmation, no listing of options and asking the user to enter letter A, B, C, or D, etc. It is OK to embellish on the output, though.)

    When printing your puzzle board, it should be aligned like you see above. printf formatting codes work really well for this.

  4. Reflections

    Edit refl.txt (short for “reflections”) to answer the questions therein.

When you’re all done, submit on GitHub by creating a Pull Request according to these instructions.