Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
r;fb;f(a,lint*a)int*a;{forb=(r=0;l--;b=*a++)r+=*a%2*~?b%2*~-*a++;l=r;b+f(a):0;}
Input as an0-terminated array a and its length l.
a
l
Try it online! Recursive function.
-10 bytes thanks to Arnauld!
Try it online!
r;f(a,l)int*a;{for(r=0;l--;)r+=*a%2*~-*a++;l=r;}
Input as an array a and its length l.
b;f(int*a){b=(b=*a++)?b%2*~-b+f(a):0;}
Input as 0-terminated array a.
Recursive function.