8.1 24
On this page:
8.1.1 Stage 1

8.1 24

This assignment is loosely based on the game of 24, but we will define our own rules here, so please pay attention what is below, rather than following what is on the Web.

To give you a feel for software development efforts, you will do this project in stages. At each stage you will be given slightly different and changing requirements, and must turn in a solution that matches that stage. The link to the next stage will be provided when you complete the previous stage. To help you with planning, there are six stages in all, all of roughly the same or lower complexity than the first stage—though your mileage may vary, so it pays to start early.

Critical notes:
  • You should treat this assignment like an exam. Therefore, you:

    • cannot talk to another student about it until you are both done. In particular, you cannot discuss what the next stage is, etc.

    • should do this work without consulting course staff except for critical issues (broken links, possible assignment typo, etc.), and the one exception noted in a later stage.

    • should not try to peek ahead to the next stages through any means; doing so would be a violation of the Academic Code.

  • Unlike in previous assignments, you will be given only one chance to submit at each stage (like a company making a code release of a new version). So please submit with care.

  • In the forms you will need to enter numbers. Please don’t use commas, etc. Use one of Pyret’s notations (if you need, you can use decimal or fractional): whatever you write should be machine-readable by Pyret (paste it back into Pyret to make sure it is accepted, before submitting).

  • You may use any features or libraries you have used on prior homeworks.

  • Use the same filename, 24-code.arr, for your program file at every stage.

8.1.1 Stage 1

We will begin with a simplified version of the 24 Game, in which you have:
  • Numbers: 1 to 5. You have four cards of each number (corresponding to the four suits).

  • Operations: addition and multiplication. You have three cards of each operation.

A configuration consists of seven cards, starting with a number and thereafter alternating operation and number. Each suit occupies a fixed position throughout this game. Thus, a configuration may look like 1 + 1 + 1 + 1.

The value of a configuration is the number we get by evaluating it, ignoring precedence rules and instead using right associativity. For instance,

1 + 2 * 3 + 4

would effectively be parenthesized as

1 + (2 * (3 + 4))

which evaluates to 1 + (2 * 7) = 1 + 14 = 15.

Problem: Determine how many different configurations have the value 24. Implement a function with the signatureThe 24-5-2 stands for “that combine to form 24 choosing from 5 different numbers and 2 different operators”.

how-many-24-5-2 :: () -> Number

that when applied to no inputs computes the number of these configurations.

Submit