Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
Was the task to write algorithm to check IPv4, or to just use existing solution for that? I do not really know what is the difference between a guy who types the instruction of the kata into google search and you.
should_pass_all_fixed_and_edge_assertions
Data:
2 ,3 ,6 ,4 ,1 ,2 ,3 ,2 ,
2 ,3 ,6 ,4 ,1 ,2 ,3 ,2 ,1 ,2 ,2 ,2 ,
1 ,3 ,1 ,2 ,2 ,2 ,2 ,
1 ,3 ,1 ,2 ,2 ,2 ,
Expected: [ 2 ]
Actual: [ 2, 4 ]
on none of this data sets my program locally shows peak at index 4.
Note: I'm still learning, all criticism about readibility of my code is welcome.
///////////////
bool func(vector& vec, int* a) checks cases like:
1,2,2,2,2 - no peak
1,2,2,2,1 - peak
if(&vec[0] - (a + 1) == vec.size() - 1) - checks if we are going out of vector's scope and stops recursion in cases like 1,2,2,2,2
///////////////
CODE:
#include
#include
using namespace std;
bool func(vector& vec, int* a){
if(&vec[0] - (a + 1) == vec.size() - 1)
{
if(*a >= *(a+1))
return false;
else
return true;
}
if(*a > *(a+1))
return true;
if(*a == *(a+1))
return func(vec, a+1);
return false;
}
PeakData pick_peaks(vector v) {
PeakData result;
for(int i = 1; i < v.size() - 1; i++){
if(v[i] > v[i - 1] && func(v, &v[i]) ){
result.pos.push_back(i);
result.peaks.push_back(v[i]);
}
}
return result;
}
THANK YOU VEARY MUCH FOR HELP!! :)
The same story here, any solution to get points for this task? I've tried my code locally and it computes peaks from failing test cases correctly :/