A magazine where the digital world meets the real world.
On the web
- Home
- Browse by date
- Browse by topic
- Enter the maze
- Follow our blog
- Follow us on Twitter
- Resources for teachers
- Subscribe
In print
What is cs4fn?
- About us
- Contact us
- Partners
- Privacy and cookies
- Copyright and contributions
- Links to other fun sites
- Complete our questionnaire, give us feedback
Search:
Programming Puzzle: new naked mole-rats
by Paul Curzon, Queen Mary University of London
Only the queen of a naked mole-rat colony has pups. They live amazingly long lives and are highly resistant to cancer! Here is a programming puzzle about a fictional colony...
A one-year old queen forms a new colony with a single male. Each year they have a new litter of pups. The number of pups for this queen just so happen to follow a special pattern: 2 pups in the first year, then 3 the next, 5 the next, 8 the next, and so on. This queen dies before any of her pups or the original male.
Write an efficient program to work out the size of her colony after each year if the pattern is followed until she dies (exhausted).