+ 7
🐄🌾🏠 Challenge: Cow Farm
Each year every 2 cows in your farm has 1 calf. At first, you have x number of cows, but you need to have y. How many years does it take to breed them? Example: You have 6 cows: x = 6 You need to have 12 cows: y = 12 Year 0 (initial): You have 6 cows. Year 1: 6 cows bred and had 3 calves. Now you have 9 cows. Year 2: 8 cows bred (1 cow didn't breed because it didn't have a partner) and had 4 calves. Now you have 13 cows. Answer = 2 years All languages are welcomed 😊
11 Respuestas
+ 13
Using inline assembly:
https://code.sololearn.com/cfEFPO9z7Wcw/?ref=app
+ 5
Pseudo code ok?
If so:
Int yearsBreeding (int cur, int goal){
if ((cur>=2) AND (goal>cur)){
int numYears=0;
while (cur < goal){
cur = cur + (cur/2);
numYears++;
}
return numYears;
}else{
return -1;
}
}
+ 5
https://code.sololearn.com/W9DBIcCfrcPy/#js
Good luck everyone!
+ 3
@H Chiang
Nice 👏
+ 3
@qwerty
Nice! I have never seen SoloLear challenges solved in assembly before. I didn't even know it was possible. Good work! 👏
+ 2
@Luk
Good job :)
+ 2
https://code.sololearn.com/cGvC2kEI43Ga/?ref=app
Here's an object oriented solution! :D
+ 2
@MrCoder Nice 👍
I don't understand object oriented programming too well :)
+ 1
@Augustinas Lukauskas Thank you, You'll understand it soon :D
+ 1
@Ng Ju Ping
👍👍👍