What programming language you start with really all depends on where you want to go with programming/coding. The great thing about this field is that there are an absolute abundance of smaller fields that you can go into, all using programming in their own unique ways. For web applications, a good start would be with HTML and later moving your way through CSS, JavaScript, JQuery, PHP, SQL, and any of the JavaScript libraries. Ruby is also a popular choice, so I would recommend checking that out too. For more scientific fields or areas with more machine learning and A.I., Python is generally a great place to start as it is widely used in that field of study. C++ is also a very useful language to know for that, but it can be a little more challenging for beginners. For game and application design, languages such as C#, C, Swift, Kotlin, and Java are most often used for that.
Description
Rabbits are known for their fast breeding, but how soon will they dominate the earth?
Starting with a small population of male and female rabbits we have to figure out how long it will take for them to outnumber humans 2:1.
Every month a fertile female will have 14 offspring (5 males and 9 females).
A female rabbit is fertile when it has reached the age of 4 months, they never stop being fertile.
Rabbits die at the age of 8 years (96 months).
Input description
You will be given a list of numbers as following:
Male_rabbits Female_rabbits Rabbits_needed_alive
The initial rabbits will always be 2 months old and fertile females will always produce 14 offspring (5 male, 9 female)
Every month that passes things should be done in this order:
Fertile female reproduce (so 7 year & 11 months old will reproduce)
rabbits age (except newborn) (and rabbits reaching 8 years will die, the 7 year & 11 months old will die)
fx:
2 4 1000000000
Output description
You output how many months it took for world domination
Example
Looking just at the female population
we start with 1 female with the given starting age of 2 months
the index is their age (0-index is 0 months old)
[ 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0] Month 0
[ 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0] Month 1
[ 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0] Month 2
[ 9, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0] Month 3
[ 9, 9, 0, 0, 0, 0, 1, 0, 0, 0, 0] Month 4
[ 9, 9, 9, 0, 0, 0, 0, 1, 0, 0, 0] Month 5
[ 9, 9, 9, 9, 0, 0, 0, 0, 1, 0, 0] Month 6
[ 9, 9, 9, 9, 9, 0, 0, 0, 0, 1, 0] Month 7
[90, 9, 9, 9, 9, 9, 0, 0, 0, 0, 1] Month 8
For Inspiration
The rabbit problem
Challenge input(s)
2 4 1000000000
.
2 4 15000000000
Challenge output(s)
32
.
36
Bonus
Tell how many dead rabbits there are when they dominate earth.
Solution
Python3.6
bun_m, bun_f = [[0 for x in range(96)] for i in range(2)]
bun_m[2], bun_f[2] = 2, 4
count = 0
while sum(bun_f) + sum(bun_m) < 1_000_000_000:
new_b = sum(bun_f[4:])
bun_f = [9*new_b] + bun_f[:-1]
bun_m = [5*new_b] + bun_m[:-1]
count += 1
print(count)
Rabbits are known for their fast breeding, but how soon will they dominate the earth?
Starting with a small population of male and female rabbits we have to figure out how long it will take for them to outnumber humans 2:1.
Every month a fertile female will have 14 offspring (5 males and 9 females).
A female rabbit is fertile when it has reached the age of 4 months, they never stop being fertile.
Rabbits die at the age of 8 years (96 months).
Input description
You will be given a list of numbers as following:
Male_rabbits Female_rabbits Rabbits_needed_alive
The initial rabbits will always be 2 months old and fertile females will always produce 14 offspring (5 male, 9 female)
Every month that passes things should be done in this order:
Fertile female reproduce (so 7 year & 11 months old will reproduce)
rabbits age (except newborn) (and rabbits reaching 8 years will die, the 7 year & 11 months old will die)
fx:
2 4 1000000000
Output description
You output how many months it took for world domination
Example
Looking just at the female population
we start with 1 female with the given starting age of 2 months
the index is their age (0-index is 0 months old)
[ 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0] Month 0
[ 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0] Month 1
[ 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0] Month 2
[ 9, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0] Month 3
[ 9, 9, 0, 0, 0, 0, 1, 0, 0, 0, 0] Month 4
[ 9, 9, 9, 0, 0, 0, 0, 1, 0, 0, 0] Month 5
[ 9, 9, 9, 9, 0, 0, 0, 0, 1, 0, 0] Month 6
[ 9, 9, 9, 9, 9, 0, 0, 0, 0, 1, 0] Month 7
[90, 9, 9, 9, 9, 9, 0, 0, 0, 0, 1] Month 8
For Inspiration
The rabbit problem
Challenge input(s)
2 4 1000000000
.
2 4 15000000000
Challenge output(s)
32
.
36
Bonus
Tell how many dead rabbits there are when they dominate earth.
Solution
Python3.6
bun_m, bun_f = [[0 for x in range(96)] for i in range(2)]
bun_m[2], bun_f[2] = 2, 4
count = 0
while sum(bun_f) + sum(bun_m) < 1_000_000_000:
new_b = sum(bun_f[4:])
bun_f = [9*new_b] + bun_f[:-1]
bun_m = [5*new_b] + bun_m[:-1]
count += 1
print(count)
Comments
Post a Comment