Ten Odd Moments

Disclaimer

The opinions expressed by RudeJohn do not necessarily reflect those of the Basix Fanzine or its staff. In fact, they probably disagree with me entirely. Everyone else does. <bfg>

Introduction

Below is a short list of exercises suitable for passing the odd moment or two when you're bored silly and can't think of anything better to do. Then again, if you're that bored maybe you should be looking for a job so that you can afford to move out of your parent's basement. Think about it.

One

An automorphic number is a natural number which appears at the end of its square, e.g.,
 5 2 = 25 25 2 = 625 625 2 = 390625
Write a program to find more automorphic numbers.

Two

The Goldbach conjecture states that every even number can be represented as the sum of two prime numbers. Show that this is true for the first 1000 even numbers.

Three

A Mersenne prime is a prime number of the form
2 x - 1
where x is also prime, e.g., 2 3 - 1 = 7.
Write a program to find several more Mersenne primes.

Four

A perfect number is a natural number equal to the sum of all of its exact divisors except itself, e.g.,
28 = 1 + 2 + 4 + 7 + 14
Write a program to find at least 3 more perfect numbers.

Five

Extend the notion of automorphism to higher integral powers, e.g.,
 5 3 = 125 25 3 = 15625 625 3 = 244140625
Write an efficient program to search for n-th power automorphic numbers.

Six

Let A and B be two unequal natural numbers. If A is the sum of all of the exact divisors of B (excluding B itself), and if B is the sum of all of the exact divisors of A (excluding A itself), then A and B are amicable. For example, the sum of the exact divisors of 220 (excluding 220 itself) is equal to 284, and the sum of the exact divisors of 284 (excluding 284 itself) is equal to 220. Thus, 220 and 284 are amicable. Isn't that nice?
Write a program to find more amicable numbers. Or else.

Seven

This exercise doesn't require a program, but you may want to write one anyway. In fact, you may want to write several! <g>
Let's say that we are looking for a simple test for a random integer generator. When do you think it would be reasonable to claim that each digit should occur 10% of the time? Less than 10%? More than 10%?
If we are generating random integers in the range of say, 0 to 999, then shouldn't every number be considered as a string of digits of equal length? In other words, shouldn't the number 2 be interpreted as 002? This approach will certainly effect the frequency count for the digit zero. What do you think?

Eight

Write a program that will accept a simple arithmetical expression as a string and check it for unmatched parentheses. And send me a case of scotch.

Nine

Write a program to determine whether a simple algebraic expression is syntactically correct. This means that an expression such as X = 5 + Y / ( 3 - 3 ) is acceptable because it is syntactically correct even though it is mathematically invalid. Assume that variable names consist of a single letter, and allow + and - to be used as unary operators, e.g., X * - Y is syntactically correct but X - * Y is not. For now, restrict operations to +, -, *, and /.

Ten

Write a program that reads a simple arithmetical statement, checks it for syntactical correctness, and then evaluates that statement using the following rules of precedence:
• both unary operators share equal precedence
• both unary operators precede *
• * precedes /
• / precedes binary +
• binary + precedes binary -
The overall evaluation of an expression procedes from left to right. Parts of an expression which are delimited by parentheses are evaluated before parts of the expression which are not. If parentheses are nested, then evaluation procedes from the innermost pair to the outermost pair. When confronted with two or more sub-expressions of equal precedence, evaluation procedes from left to right. [[[ Do not depend upon your programming language-of-choice to automatically enforce any of these rules. The point of the exercise is for you to define the implementation of ( ), +, -, *, and /. ]]]
Accordingly, -5 + - -7 * - 4 / -2 + + 11 = 20.

C'ya,
RudeJohn
"I'm rude. It's a job."