Homework 1

Post date: Jun 30, 2009 2:23:12 AM

• With a 10% bonus: Friday, July 3, 2009, at 11:59pm.
• Last deadline: Monday, July 6, 2009, at 11:59pm.
• No late submission will be accepted.

All students must adhere to Academic Code of Conduct. You are welcome to brainstorm ideas with your fellow students, but you are not allowed to share code.

Description

The first homework aims to familiarize you with Eclipse and programming in Java. All you need to know is array and simple control statements such as for-loops and if-statements. Please go over the instructions in Working with Eclipse first. The homework problems are included in the provided hw1.zip, attached below. Here is a quick run-down of all the functions you need to implement.

• SimpleProblems.java:
• (10 pts) public static long NumberOfArrangements(int n)
• (10 pts) public static boolean UPCVerify(int[] upc)
• (10 pts) public static long SumPerfectSquares(int k)
• (20 pts) public static int[] FibonacciArray(int n)
• Naname.java:
• (20 pts) public int[] Tally(int row, int col)
• (20 pts) public boolean Verify()
• (30 pts) public static Naname GenerateWithSeed(int[] seed)

For a total of 120 points.

While the problems in SimpleProblems.java are fairly self-explanatory, the Naname game deserves some explanation.

Naname

Naname (斜め) is a Sudoku-like puzzle game played on a 9x9 grid. Each cell on the grid is filled in with a number from 1 to 9. Like Sudoku, the numbers within each 3x3 sub-squares must be unique. However, unlike Sudoku, Naname requires that each diagonal and anti-diagonal contain unique numbers, like illustrated below.

The way the figure is color-coded, each color needs to have exactly one occurrence of 1 through 9. As you can see, the numbers filled in are actually a Naname solution. This file is included under examples/solution1.txt; another example is given as examples/solution2.txt. Several non-solutions are also provided.

Running the Verifier

A class called NanameVerifierMain is provided. Select the class and click on the Run button. You will be presented with a File Chooser dialog where you can choose the file that may or may not contain a solution. Once you click Okay, it will create a Naname object and then call your Naname.Verify() method. Based on the result you return, it will show a message box telling you whether the file contains a solution or not.

The format of the file is very simple. It just contains 9 lines, each contains 9 numbers. Non-digits are ignored, as well as lines that contain fewer than 9 digits, so you can write comments in the file without special syntax. Some example solutions as well as non-solutions are provided in the examples folder under the project.