Reverse Fibonacci
Python 2, 62 59 bytes
n,l,a,b=input(),[],0,1
while a<=n:l=[a]+l;a,b=b,a+b
print l
Try it online!
Jelly, 9 8 bytes
ḤḶÆḞṚ>Ðḟ
A monadic link taking a number and returning the list of numbers.
Try it online!
Note: I am assuming 1s are not both required, if they are the previous 9 byter works: +2ḶµÆḞṚfṖ
How?
ḤḶÆḞṚ>Ðḟ - Link: number, n
Ḥ - double n (this is to cater for inputs less than 6)
Ḷ - lowered range of that -> [0,1,2,...,2*n-1]
ÆḞ - nth Fibonacci number for €ach -> [0,1,1,...,fib(2*n-1)]
Ṛ - reverse that
Ðḟ - filter discard if:
> - greater than n?
...the reason this only outputs [1,0]
for an input of 1
is that the unfiltered list does not contain fib(2)
, the second 1
.
The 9 byter works by adding two, +2
, to form the lowered range [0,1,2,...,n,(n+1)]
rather than doubling and then filter keeping, f
, any results which are in a popped, Ṗ
, version of that same list, [0,1,2,...,n]
(the value accessed by making a monadic chain, µ
).
Haskell, 52 bytes
p=0:scanl(+)1p
f 1=[1,0]
f n=reverse$takeWhile(<=n)p
Second line is necessary for the n = 1
edge-case. I wasn't able to get around it.