Sign in
Log inSign up

How would you write the following algorithm?

Default profile photo
Anonymous
·Mar 4, 2018

Calculating something like the bacterial reproduction is very easy, e.g., "Under ideal conditions, the number of bacteria doubles every 30 minutes", but my requirement is different.

An animal gives birth to her first offspring at the age of 7 years, after that it gives birth every year up to the age of 30. How many of its offspring will be alive after 100 years if (ideally) all of the offspring are females.

(Someone mentioned in the comments that I should mention the age at which an animal dies and suggested the age of 40. Let's think every animal dies at the age of 40).

I tried to do it, but failed. Looks like some nested loop with if-else will be involved, but my brain isn't working on it right now.

Hassle-free blogging platform that developers and teams love.
  • Docs by Hashnode
    New
  • Blogs
  • AI Markdown Editor
  • GraphQL APIs
  • Open source Starter-kit

© Hashnode 2024 — LinearBytes Inc.

Privacy PolicyTermsCode of Conduct