Post History
Python 3, 131 75 62 bytes f=lambda n:n>0and 2+3*f(n-1)+4*f(n-2)+2*sum(map(f,range(n-2))) I know, a one-liner is boring. This is because I apparently didn't need a separate function/lambda to...
#3: Post edited
# Python 3, <s>131</s> 75 bytes- ```python
f=lambda n:2+3*f(n-1)+4*f(n-2)+2*sum([f(i)for i in range(n-2)])if n>0else 0- ```
I know, a one-liner is boring. This is because I apparently didn't need a separate function/lambda to compute the sum of something. So there you have it, a 56 byte save. :D
- # Python 3, <s>131</s> <s>75</s> 62 bytes
- ```python
- f=lambda n:n>0and 2+3*f(n-1)+4*f(n-2)+2*sum(map(f,range(n-2)))
- ```
- I know, a one-liner is boring. This is because I apparently didn't need a separate function/lambda to compute the sum of something. So there you have it, a <s>56</s> 69 (nice) byte save in total. :D
#2: Post edited
# Python 3, 131 bytes- ```python
def s(u,f):r=0for i in range(u):r+=f(i)return rf=lambda n:2+3*f(n-1)+4*f(n-2)+2*s(n-2,lambda i:f(i))if n>1else 2if n>0else 0- ```
It may be helpful to note that while the function `s(u,f)` does compute a sum, it doesn't compute $\sum_{i=0}^uf(i)$, but actually$$s(u,f)=\sum_{i=0}^{u-1}f(i)$$since Python ranges omit the value of the upper bound.
- # Python 3, <s>131</s> 75 bytes
- ```python
- f=lambda n:2+3*f(n-1)+4*f(n-2)+2*sum([f(i)for i in range(n-2)])if n>0else 0
- ```
- I know, a one-liner is boring. This is because I apparently didn't need a separate function/lambda to compute the sum of something. So there you have it, a 56 byte save. :D
#1: Initial revision
# Python 3, 131 bytes ```python def s(u,f): r=0 for i in range(u):r+=f(i) return r f=lambda n:2+3*f(n-1)+4*f(n-2)+2*s(n-2,lambda i:f(i))if n>1else 2if n>0else 0 ``` It may be helpful to note that while the function `s(u,f)` does compute a sum, it doesn't compute $\sum_{i=0}^uf(i)$, but actually$$s(u,f)=\sum_{i=0}^{u-1}f(i)$$since Python ranges omit the value of the upper bound.