CIT 591 Assignment 2: Figurate Numbers
Fall 2014, David Matuszek

# Purposes of this assignment

• To familiarize you with functions
• To get you started pair programming

# General idea of the assignment

In this assignment you will write a number of functions for testing characteristics of positive integers, plus one special function named `main`. Each function other than `main` will take any single positive integer as an argument, test whether it has some property, and return a value of either `True` or `False`..

Put your program on a file named `figurate_numbers.py`. Get a copy of the file figurate_numbers_test.py. (As you read this, the file may be missing or incomplete; if so, it will be ready soon.)

# Details

## The `main()` function

In the `main` function, define a variable `limit = 100` and test each of the numbers` 1 `through` limit`, inclusive. Do not use the number 100 elsewhere; use the variable `limit` instead. This makes the program easier to change if you later want some limit other than 100.

The `main` function will call each of the other functions, for each of the numbers 1 through `limit`, to determine the properties of those numbers. It will then print out each number, one per line, along with a list of its properties (on the same line).

Your output should look approximately like this:

```    1 composite, triangular, tetrahedral, square,  square pyramidal, pentagonal, not prime oblong, not pointy
2 prime, not triangular, not tetrahedral, not square,  not square pyramidal, not pentagonal, not prime oblong, not pointy
3 prime, triangular, not tetrahedral, not square,  not square pyramidal, not pentagonal, not prime oblong, not pointy
4 composite, not triangular, tetrahedral, square,  not square pyramidal, not pentagonal, not prime oblong, not pointy
5 prime, not triangular, not tetrahedral, not square,  square pyramidal, pentagonal, not prime oblong, pointy
. . .```

The `main` function doesn't return a value. Each of the other functions is a predicate, that is, a function that returns `True` or `False`.

## The `is_prime(n)` function

A positive number is prime if its only positive divisors are itself and one. For example,` 7 `is prime because it is evenly divisible by` 1 `and` 7`, but not by any number in between (in particular, it is not evenly divisible by` 2`,` 3`,` 4`,``` 5```, or` 6`).

A positive number is composite if it is not prime. For example,``` 10 ```is composite because it is evenly divisible by` 2 `and``` 5```;` 12 `is composite because it is evenly divisible by``` 2```,` 3`,` 4`, and` 6`. As a special case,``` 1 ```is considered to be composite.

This function should return `True` if its argument is a prime number, and `False` otherwise. Similar statements hold for the other functions.

## The `is_triangular(n)` function

A triangular number is a number of the form `1 + 2 + 3 + ... + n`, for some positive` n`. These numbers are called triangular because, if you have that many objects, you can arrange them in an equilateral triangle (see figure).

The first few triangular numbers are `1, 3, 6, 10, 15`....

## The `is_tetrahedral(n)` function

To build tetrahedral numbers, 1, 4, 10, 20, 35, 56, etc., we successively stack triangular numbers, 1, 3, 6, 10, 15, ..., one at
a time.

## The `is_square(n)` function

A square number is a number of the form `1 + 3 + 5 + 7 + ... + n`, for some odd positive` n`. (The figure should help you understand why this definition is the same as the usual definition of square numbers.)

## The `is_square_pyramidal(n)` function

To build square pyramidal numbers, 1, 5, 14, 30, 55, 91, etc., we successively stack the square numbers, 1, 4, 9, 16, 25,36, etc., one at a time.

## The `is_pentagonal(n)` function

Pentagonal numbers can be generated by triangular ones, as seen here to the left, yielding the general formula
Pn= 1 + 4 + 7+... + (3n-2) = Tn+2Tn-1= ½n(n +1) + n(n - 1) = ½n (3n - 1).

## The `is_prime_oblong(n)` function

(My invention, not a standard mathematical term). Prime oblong numbers are those that have exactly two different prime divisors. Thus, 10 (2 * 5) is prime oblong, 12 is not (too many divisors), 25 is not (two equal prime divisors).

## The `is_pointy(n)` function

A number is pointy (again, my invention, not a standard mathematical term) if it is the sum of two different triangular tetrahedral numbers. The first few pointy numbers are `5` (1+4), `11` (1+10), `14` (4+10), `21` (1+9), `24` (4+20), `30` (10+20), etc.

# Coda

At the end of your Python program (after all your function definitions), insert the following lines:

``````if __name__ == "__main__":
main()``````

Here's what this does. If you are in the IDLE window containing your program, and you click `F5` (or choose `Run -> Run module`) from the menu, IDLE will automatically run your main function. If you are in the IDLE window containing your test cases (supplied) and click `F5` or use the menu equivalent, it will run the tests and tell you the results.

# References

The figures and descriptions of tetrahedral, square pyramidal, and pentagonal numbers are from Mathematics: From the Birth of Numbers by Jan Gullberg.

# Due date

This is a pair programming project. Only one of you, either you or your team member, should turn in the assignment. Make sure both your names are in comments at the top of the file.

Turn in your assignment by 6am, Friday September 12 . Turn in only the Python file you wrote; don't turn in the supplied test file. As only one file is required, there is no need to zip it.