Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Preparation Using an ssh client (PuTTY or OpenSSH) or X, log in to one of our Li

ID: 3680456 • Letter: P

Question

Preparation

Using an ssh client (PuTTY or OpenSSH) or X, log in to one of our Linux servers and set your TERM type.

Give the command

to create a directory for CS333-related work, both for this assignment and future assignments.

Give the command

to set the protections on this directory so that only you can access its contents.

Give the command

to create a directory for this assignment.

Whenever you are working on this assignment on the Linux system, you should log in to Linux, then

to get into your assignment directory. Do so now.

You can run the nim program by giving the command

(Note that you can use the Tab key, after typing a few letters, to auto-complete parts of a long directory of file/command name.) Try typing in the sample input listed in the assignment page.

Next, create a file containing the sample input. You can do this in one of two ways.

In your ssh session, use a Linux editor such as emacs or pico to create the desired file.

If you have not gotten as far in CS252 as the lessons on the Linux emacs text editor, then

if you are connecting in text-mode, try pico, e.g.,

as it is simple and pretty-much self-expanatory.

if you are connecting in graphics-mode (X), try gedit, e.g.,

as it is similarly simple.

Or, on your PC, open Notepad or a similar text editor (Not Word or any other word processor.), create the desired file, and then transfer it to your Linux account. If you take this approach, remember that text files have different line endings in Windows and Linux, so the line endings will need to be converted (e.g., by using ASCII mode transfers in ftp or by running the tr command.)

Run the program, using redirection (covered in an earlier lab) to supply the file to the program’s input.

3. The Assignment

I recommend that you do write up a test specification, as outlined in class, for the program. Although you will not turn in the spec., it will help guide your selection of tests.

Prepare a suite of tests for this program. Each test will be one file, containing the characters you would type if you were playing the game interactively. For example, the game

would be recorded in a file as:

A single test file should contain the inputs you would type in to a single execution of the program (which could be multiple games, depending on your answer to the “Play again?” question).

Be sure that you remember to to hit Enter/Return at the end of the final line of input. Otherwise it will not be processed properly.

Prepare your test files using any text editor. (See the notes above about the need for conversion if you use Windows editors to create Linux text files.)

Note that you can have multiple ssh sessions open to the same machine. You may find it useful to run the editor in one window and the program in another.

Your test files must be named “testname.in”, i.e., they must end in “.in” (and remember that Linux file names are case sensitive, so “.IN” and other variants do not count.

You can check your test files by running them through the program executable, e.g.,

Important: A test is valid only if it is possible for a program to pass or fail the test. That means that an “illegal” input, something that the program is not required to actually handle, is not a valid test. Any such tests that are submitted will be discarded.

To prepare your files for submission, package them into a zip file named “tests.zip”. The command to do this in Linux will be

You can check the contents of your zip file with the command

Explanation / Answer

I could not get exactly what you wanted. Here is this code based on my understanding. Please ask if you have any doubts:

#!/bin/bash
# This script will test if you have given a leap year or not.

echo -n "How many piles? (1-7) "

read piles
echo ""

echo -n "Enter $piles integers(0...100) indicating the starting number of stones in each pile: "

read pileArr
echo ""

pileTmp=$piles
i=1

while [ $piles -gt 0 ]
do
echo -n " $i "
let piles--
let i++
done
echo ""
i=1
while [ $pileTmp -gt 0 ]
do
echo -n " $pileArr[$i] "
let pileTmp--
let i++
done
echo ""

while [ (($pileArr[0] -gt 0)) || (($pileArr[1] -gt 0)) ]
do
echo -n "Which pile would you like to pick from? "
read pileIn
echo ""

echo -n "How many stones would you like to remove? "
read stoneIn
echo ""
done

echo "you win"