### Search

 Search WWW Search DelphiForFun.org

As of October, 2016, Embarcadero is offering a free release of Delphi (Delphi 10.1 Berlin Starter Edition ).     There are a few restrictions, but it is a welcome step toward making more programmers aware of the joys of Delphi.  They do say "Offer may be withdrawn at any time", so don't delay if you want to check it out.  Please use the feedback link to let me know if the link stops working.

Support DFF - Shop

If you shop at Amazon anyway,  consider using this link.

We receive a few cents from each purchase.  Thanks

### Support DFF - Donate

If you benefit from the website,  in terms of knowledge, entertainment value, or something otherwise useful, consider making a donation via PayPal  to help defray the costs.  (No PayPal account necessary to donate via credit card.)  Transaction is secure.

Mensa® Daily Puzzlers

For over 15 years Mensa Page-A-Day calendars have provided several puzzles a year for my programming pleasure.  Coding "solvers" is most fun, but many programs also allow user solving, convenient for "fill in the blanks" type.  Below are Amazon  links to the two most recent years.

(Hint: If you can wait, current year calendars are usually on sale in January.)

### Contact

 Search DelphiForFun.org only

### Problem Description

A certain village was overrun with mice. In fact there were so many that they decided to bring in some cats to get rid of the mice. By a strange coincidence, each cat killed the same number of mice and each cat killed more mice than there were cats.  Altogether they killed 10,001 mice. How many cats were there?

Source: Math and Logic Puzzles for PC Enthusiasts, J. J. Clessa, Dover Books.

### Background & Techniques

We need to find two numbers whose product is 10,001.  Hopefully there is only one such pair or else we have more than one correct answer.

We'll just loop through all possible divisors of 10,001 from 3 up to the square root of 10,001 looking for ones the divide 10,001 exactly - these are the factors of 10,001.   We'll assume that the desired answer is not that one cat killed 10,001 mice.  And 2 only divides even numbers, so we can start with 3.  We can stop at sqrt(10001)  -  (sqrt is Delphi's square root function) because if any factor is  larger than this, another factor must be smaller.

### Suggestions for further exploration

Generalize the problem by taking the total of cats and mice as an input.

10,001 has only 2 factors, both prime numbers.  Prime numbers are integers that have no integer divisors except 1 and themselves.

This process of factoring numbers is important for lots of integer arithmetic problems.   Modern encryption methods depend on the fact that very large numbers are difficult to factor, even by computer.    Somebody, Euclid I think, proved that every integer can be factored into a product of primes in exactly one way (ignoring rearranging the factors).   This is called the Fundamental Theorem of Arithmetic.   There are lot's of neat things to do with primes and factoring as we'll see in the Prime Factors program where we'll be generating lots of primes.   Check out   Dr Math and  The Prime Page sites for more interesting information.    Try a  search on "primes factoring" for many more pages.