**Erlang Assignment
1: Number Personalities**

Fall 2010, David Matuszek

- To get you started programming in Erlang
- To get you familiar with the more important list functions.

For each of the numbers in a given range, determine some characteristics of those numbers. Print out the numbers, one per line, along with a list of its characteristics (on the same line).

Your output should look approximately like this:

1 [happy,triangular,square,antifirst]

2 [prime,smug,antifirst]

3 [prime,triangular]

4 [square,antifirst] ...

Write the following functions, along with any helper functions you may need.

`is_prime(N)`

`is_happy(N)`

`is_prime(N)`

(already listed above)`is_triangular(N)`

`is_square(N)`

`is_smug(N)`

`is_abundant(N)`

`is_antifirst(N)`

`explore_numbers(Lo, Hi)`

-- Produce output like the above, for numbers`Lo`

to`Hi`

, inclusive.

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.

Repeatedly apply the following procedure to a number:

- Square each of the digits of the number.
- Add the squares together.

If by doing this you eventually get to` 1`

, then the number is **happy**.

For example, if you start with` 19`

:

`1`

^{2}+ 9^{2}= 1 + 81 = 82`8`

^{2}+ 2^{2}= 64 + 4 = 68`6`

^{2}+ 8^{2}= 36 + 64 = 100`1`

and the number is happy.^{2}+ 0^{2}+ 0^{2}= 1 + 0 + 0 = 1

If instead you get into an infinite loop, the number is **unhappy**. So
if your program runs forever, the number is unhappy. This isn't a very useful
test, however. Fortunately, every unhappy number will eventually get into this
cycle:

`4, 16, 37, 58, 89, 145, 42, 20, 4, ...`

so if you get any one of these numbers, say` 4`

, then you can stop
and conclude that the number is unhappy.

A** triangular number** is a number of the form

,
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`

....

A |

A number is **smug** if it is the sum of two square numbers. The first few
smug numbers are `2`

(1+1), `5`

(1+4), `8`

(4+4), `10`

(1+9), `13`

(4+9), etc.

A number is **abundant** if the sum of its proper divisors (including 1, but excluding the number itself) is greater than the number. The first few abundant numbers are `12`

(1+2+3+4+6=14), `18`

(1+2+3+6+9=21), `20`

(1+2+4+5+10=24), and `24`

(1+2+3+4+6+8+12=36).

A number is **antifirst** if it has more divisors than any preceding (positive) number. The first few antifirst numbers are` 1 `

(the only divisor is 1),` 2 `

(two divisors, 1 and 2),` 4 `

(1, 2, 4),` 6 `

(1, 2, 3, 6),` 12 `

(1, 2, 3, 4, 6, 12), and` 24 `

(1, 2, 3, 4, 6, 8, 12, 24) .

Turn in your` numpers.erl `

file by **midnight, Thursday Sept. 30 **. As only one file is required, there is no need to zip it.