I've got an assignment, which sounds like this : "An archer has black and white arrows, and he can only shoot white ducks with white arrows and black ducks only with black arrows. The ducks come in groups, which grow in size like this : one, then two, then three, then five, eight, etc., so basically Fibonacci numbers. The ducks in those groups are ordered so that you won't find two ducks of the same colour near each other, and each group starts with a white duck(for example, for the group which has 5 ducks in it: white black white black white). The archer can only kill the ducks if he can kill the entire group."
Being given the number of white arrows(ka) and black arrows(kb) I must say how many groups has the archer killed and how many arrows of each type has he got left.
int ka, kb;
cin >> ka >> kb;
int total_rows{0};
for(int current_group{1}, previous_group{1}; ka+kb >= current_group; ++total_rows)
{
//see which of the arrows he shoots
for(int i=1; i <= current_group; ++i)
{
if(i%2 == 1)
--ka;
else
--kb;
}
// swap the 2 fib numbers so we can get the next one
swap(current_group, previous_group);
current_group += previous_group;
}
cout << total_rows << ' ' << ka << ' ' << kb;
If I typed, for example, 9 and 10, I should get 4,2,6. I'm getting something which has nothing to do with that...