Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Challenges

Post History

60%
+1 −0
Challenges Give the fool's fibonacci sequence

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...

posted 12d ago by CrSb0001‭  ·  edited 10d ago by CrSb0001‭

Answer
#3: Post edited by user avatar CrSb0001‭ · 2025-04-09T18:31:09Z (10 days ago)
-13 bytes, -69 bytes total.
  • # 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 by user avatar CrSb0001‭ · 2025-04-09T16:42:22Z (10 days ago)
-56 bytes
  • # 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.
  • # 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 by user avatar CrSb0001‭ · 2025-04-07T20:34:11Z (12 days ago)
# 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.