Wednesday 20 June 2007

Getting Keith Backwards

I stumbled over an interesting number sequence the other day - Keith numbers (named for mathematician Mike Keith) are found as follows: starting with a number, separate the digits, then add them to form another number; continuing to sum the last n numbers in the sequence (where n is the number of digits in the original number), if the original number appears in the sequence, it is a Keith number.

For example, starting with 14, we get 1+4 = 5, 4+5=9, etc. to form the sequence 1, 4, 5, 9, 14 - since the original (14) appears in the sequence, 14 is a Keith number.

It turns out that Keith numbers are very rare (Wikipedia's article states that there are only 71 Keith numbers below 1019).

I wondered about similar number sequences, in particular numbers that produce the original number with its digits reversed. Wolfram's MathWorld site has an article on Keith numbers that also mentions these Reversed Keith numbers, but prefers the ugly term revrepfigits (and also calls Keith numbers repfigits, from 'repetitive fibonnaci-like digits').

Before I read the Wolfram MathWorld article, I had written a small Python program to find Reverse-Keith numbers (which I had decided should be called Feek numbers), and generated all the numbers up to 10 000 000.

This turns out to be a nice little programming exercise, requiring one to think about how to manage both integer reversal and splitting an integer into its separate digits prior to building the resulting number sequence. If someone wants an interesting exercise for their students, I think this is worth a look.

No comments: