Skip to main content
added 57 characters in body
Source Link
simon
  • 351
  • 1
  • 9

C, 82 3838 36 bytes

I looked2 bytes saved thanks to @BrainSteel

The formulas at the OEIS page and were able to make thismade it much shorter:

a(n){return(n<2)--n<1?0:4*a(n-1)+a(n-21)+2;} 

Try it online!

82 bytes:

x,s,p,n,c;f(N){s=0;p=n=1;c=2;while(n<N){if(~c&1)s+=c,n++;x=p+c;p=c;c=x;}return s;} 

The first version is 75 bytes but the function is not reusable, unless you always call f with greater N than the previous call :-)

x,s,p=1,n=1,c=2;f(N){while(n<N){if(~c&1)s+=c,n++;x=p+c;p=c;c=x;}return s;} 

My first answer here. Didn't check any other answers nor the OEIS. I guess there are a few tricks that I can apply to make it shorter :-)

C, 82 38 bytes

I looked at the OEIS page and were able to make this:

a(n){return(n<2)?0:4*a(n-1)+a(n-2)+2;} 

Try it online!

82 bytes:

x,s,p,n,c;f(N){s=0;p=n=1;c=2;while(n<N){if(~c&1)s+=c,n++;x=p+c;p=c;c=x;}return s;} 

The first version is 75 bytes but the function is not reusable, unless you always call f with greater N than the previous call :-)

x,s,p=1,n=1,c=2;f(N){while(n<N){if(~c&1)s+=c,n++;x=p+c;p=c;c=x;}return s;} 

My first answer here. Didn't check any other answers nor the OEIS. I guess there are a few tricks that I can apply to make it shorter :-)

C, 82 38 36 bytes

2 bytes saved thanks to @BrainSteel

The formulas at the OEIS page made it much shorter:

a(n){return--n<1?0:4*a(n)+a(n-1)+2;} 

Try it online!

82 bytes:

x,s,p,n,c;f(N){s=0;p=n=1;c=2;while(n<N){if(~c&1)s+=c,n++;x=p+c;p=c;c=x;}return s;} 

The first version is 75 bytes but the function is not reusable, unless you always call f with greater N than the previous call :-)

x,s,p=1,n=1,c=2;f(N){while(n<N){if(~c&1)s+=c,n++;x=p+c;p=c;c=x;}return s;} 

My first answer here. Didn't check any other answers nor the OEIS. I guess there are a few tricks that I can apply to make it shorter :-)

added 138 characters in body
Source Link
simon
  • 351
  • 1
  • 9

C, 8282 38 bytes

I looked at the OEIS page and were able to make this:

a(n){return(n<2)?0:4*a(n-1)+a(n-2)+2;} 

Try it online!

82 bytes:

x,s,p,n,c;f(N){s=0;p=n=1;c=2;while(n<N){if(~c&1)s+=c,n++;x=p+c;p=c;c=x;}return s;} 

Try it online!

The first version is 75 bytes but the function is not reusable, unless you always call f with greater N than the previous call :-)

x,s,p=1,n=1,c=2;f(N){while(n<N){if(~c&1)s+=c,n++;x=p+c;p=c;c=x;}return s;} 

My first answer here. Didn't check any other answers nor the OEIS. I guess there are a few tricks that I can apply to make it shorter :-)

C, 82 bytes

x,s,p,n,c;f(N){s=0;p=n=1;c=2;while(n<N){if(~c&1)s+=c,n++;x=p+c;p=c;c=x;}return s;} 

Try it online!

The first version is 75 bytes but the function is not reusable, unless you always call f with greater N than the previous call :-)

x,s,p=1,n=1,c=2;f(N){while(n<N){if(~c&1)s+=c,n++;x=p+c;p=c;c=x;}return s;} 

My first answer here. Didn't check any other answers nor the OEIS. I guess there are a few tricks that I can apply to make it shorter :-)

C, 82 38 bytes

I looked at the OEIS page and were able to make this:

a(n){return(n<2)?0:4*a(n-1)+a(n-2)+2;} 

Try it online!

82 bytes:

x,s,p,n,c;f(N){s=0;p=n=1;c=2;while(n<N){if(~c&1)s+=c,n++;x=p+c;p=c;c=x;}return s;} 

The first version is 75 bytes but the function is not reusable, unless you always call f with greater N than the previous call :-)

x,s,p=1,n=1,c=2;f(N){while(n<N){if(~c&1)s+=c,n++;x=p+c;p=c;c=x;}return s;} 

My first answer here. Didn't check any other answers nor the OEIS. I guess there are a few tricks that I can apply to make it shorter :-)

added 228 characters in body
Source Link
simon
  • 351
  • 1
  • 9

C, 7582 bytes

x,s,p,n,c;f(N){s=0;p=n=1;c=2;while(n<N){if(~c&1)s+=c,n++;x=p+c;p=c;c=x;}return s;} 

Try it online!

The first version is 75 bytes but the function is not reusable, unless you always call f with greater N than the previous call :-)

x,s,p=1,n=1,c=2;f(N){while(n<N){if(~c&1)s+=c,n++;x=p+c;p=c;c=x;}return s;} 

My first answer here. Didn't check any other answers nor the OEIS. I guess there are a few tricks that I can apply to make it shorter :-)

Try it online!

C, 75 bytes

x,s,p=1,n=1,c=2;f(N){while(n<N){if(~c&1)s+=c,n++;x=p+c;p=c;c=x;}return s;} 

My first answer here. Didn't check any other answers nor the OEIS. I guess there are a few tricks that I can apply to make it shorter :-)

Try it online!

C, 82 bytes

x,s,p,n,c;f(N){s=0;p=n=1;c=2;while(n<N){if(~c&1)s+=c,n++;x=p+c;p=c;c=x;}return s;} 

Try it online!

The first version is 75 bytes but the function is not reusable, unless you always call f with greater N than the previous call :-)

x,s,p=1,n=1,c=2;f(N){while(n<N){if(~c&1)s+=c,n++;x=p+c;p=c;c=x;}return s;} 

My first answer here. Didn't check any other answers nor the OEIS. I guess there are a few tricks that I can apply to make it shorter :-)

Source Link
simon
  • 351
  • 1
  • 9
Loading