On this page:
Overview
Setup
Tasks
Before Submitting
Submitting

Homework 13🔗

Last updated: Tue, 6 May 2025 09:14:51 -0400

Out: Tue May 06 2025, 11am EST

Due: Tue May 13 2025, 11am EST

Overview🔗

In this assignment, you will get to use the "450lang" "high-level language" that you created!

This hw will be graded accordingly:

  • correctness (autograder) (16 pts)

  • design recipe (24 pts)

  • testing (22 pts)

  • style (8 pts)

  • README (2 pt)

Total: 72 points

Setup🔗

Create a new repository for this assignment by going to the CS450 Spring 2025 GitHub Organization and clicking "New".

Note: The CS450 Spring 2025 GitHub Organization must be the owner of the repository. Do not create the repository in your own account.

On the "Create a new repository" screen:
  • Name the repository hw<X>-<LASTNAME>-<FIRSTNAME> where <X> is the current homework number.

    For example, I would name my hw13 repository hw13-Chang-Stephen.

  • Mark the repository as Private.

  • Check "Add a README file".

  • Select the Racket template for the .gitignore.

  • Choose whatever you wish for the license.

When done click "Create repository".

NEW!

Installing 450Lang

In this assignment, we will use our "450 lang" programming language, so we must install it first.

The easiest way to do so is from DrRacket, go to File -> Package Manager, and then install the 450lang package. This will allow you to use the language by writing #lang 450lang at the top of a file.

(If you installed it before this hw, make sure to update the package, also via DrRacket Pacakge Manager, to get the latest changes.)

Tasks🔗

Reading

Pre-programming Notes

Programming

In this assignment, you must use the "450lang" programming language. See the specification for the programming language. In addition to the features from previous assignments, there are additional features that have been added such as lists and other primitives.

Specifically, you must solve a version of the "n-queens" puzzle, similar to the one described in Chapter 29.2 of the textbook, by writing the following recursive functions. Make sure to follow the Design Recipe, especially for Accumulators and Generative Recursion when needed.

The textbook and links above explain this well-known problem, but briefly, the n-queens problem seeks to arrange "n" chess queens on an n by n chess board such that no queen "threatens" any other. Following standard chess rules, a queen "threatens" another if
  • they are in the same row

  • they are in the same column

  • they are on the same diagonal

Data Definitions

Functions

Define the following common list functions, which will help you compute a solution to the n-queens problem.
  • all? : takes a predicate and list and evaluates to true if the predicate is true for all list elements

  • any? : takes a predicate and list and evaluates to true if the predicate is true for at least one list element

  • has? : takes some value and a list and evaluates to true if the first argument is in the list, according to ~= equality.

  • has-dup? : takes a list and evaluates to true if there are any duplicates in the list, according to ~= equality.

In addition, define and use the following helper functions to help write the subsequent functions below:
  • safe? : consumes two Queens and evaluates to true if they do not threaten each other.

  • safe-to-add? : consumes a Queen and a list of Queens and evaluates to true if the given Queen does not threaten any of the Queens in the given list, and vice versa.

  • all-safe? : takes a list of Queens and evaluates to true if no queen in the list threatens any other Queen in the list

The next function, nqueens, computes a list of Queens that represents a solution to the n-queens problem. Be sure to follow the appropriate accumulator and/or generative recursive recipes.
  • nqueens : consumes a number n and computes a solution to the n-queens problem, or "false" if there is no solution

The following function verifies that a potential solution is a valid solution to the n-queens problem:
  • valid-solution? : takes a number n and a list of Queens and evaluates to true if the given list is a valid solution for the n-queens problem. A solution is valid if:
    • the given list has length equal to n

    • the given list has no duplicate elements

    • no Queen in the list threatens any other Queen in the list

Before Submitting🔗

Testing (and Autograders)

Before submitting, note:
  • Do not submit until all code has been thoroughly tested (by you), which means writing a "sufficient" number of Test cases.

  • A GradeScope "Autograder" may or may not be released before the due date but either way, an Autograder is not a software development/testing tool, so do not use it as one. Code must be tested independent of any Autograder and questions about Autograders will be ignored (e.g., posts asking "why is the Autograder giving an error?" are not allowed)

  • If you do submit before the deadline and get an Autograder error, this is bonus information that indicates the submitted code is not complete and/or not correct. But it’s up to you to figure out what "correct" means and how to fix to the program.

  • Of course, the course staff is here and eager to help, but cannot do so without context information. The best way to supply this information is to INCLUDE EXAMPLES WITH ALL QUESTIONS, along with what the "expected" result should be! The posted examples should be the minimal amount of code needed to communicate the problem. This will receive the clearest possible answer.

  • The Autograder test suite is subject to change. This means that the visible grade seen during submission is not the final grade.

Style

All code should follow proper Racket Style.

Also, the repository itself must follow proper style. Specifically, it must have appropriate commit messages. See How to Write a Git Commit Message if you are unsure how to write a commit message.

Files

A submission must have the following files in the repository root:

Submitting🔗

When you are done, submit your work to Gradescope hw13. You must use the "GitHub" Submission Method and select your hw<X>-<LASTNAME>-<FIRSTNAME> repository.

Note that this is the only acceptable way to submit homework in this course. (Do not manually upload files and do not email files to the course staff. Homework submitted via any unapproved methods will not be graded.)