You've probably heard of Fibonacci numbers. Ya know, that integer sequence that starts with 1, 1
, and then each new number is the sum of the last two?
1 1 2 3 5 8 13...
And so on. Challenges about Fibonacci numbers are pretty popular 'round here. But who says that the Fibonacci numbers have to start with 1, 1
? Why couldn't they start with 0, 1
? Alright, let's redefine them to start at 0:
0 1 1 2 3 5 8 13...
But... We don't have to stop there either! If we can add the last two numbers to get the next one, we could also subtract the first number from the second number to prepend a new number. So it could start with 1, 0
:
1 0 1 1 2 3 5 8 13...
We can even end up with negatives:
-1 1 0 1 1 2 3 5 8 13...
And this series also goes on forever. I think it's interesting how it ends up kinda mirroring the regular Fibonacci numbers, just with every other number made negative:
13 -8 5 -3 2 -1 1 0 1 1 2 3 5 8 13...
Let's call this series the "Extended Fibonacci Number", or EFN. Since there isn't really an obvious negative number to start this series on, we'll say that 0 shows up at 0, the regular Fibonacci numbers extend in to the positive indices, and the negative (half-negative?) Fibonacci numbers extend in to the negative indices, like so:
Indices: ...-7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 ...
Values: ...13 -8 5 -3 2 -1 1 0 1 1 2 3 5 8 13...
This leads into today's challenge:
Given an integer N, return every index at which N appears in the EFN series.
Some random observations on this task:
1 appears more times in the EFN than any other number:
[-1, 1, 2]
. No number will appear in more than 3 places.Every Fibonacci number > 1 will show up either once (3, 8, 21, etc.) or twice (2, 5, 13, etc.)
Rule Clarifications:
- If
abs(N)
is not a Fibonacci number, it will never appear in the EFN series, so you must output nothing/an empty collection if possible, or if that is not possible in your language, you can output some constant non-numeric value. - If N appears at multiple places in the EFN, your output does not need to be sorted. Although each index must appear exactly once.
- Although most sequence challenges allow you to choose whether you want to use 1-based or 0-based indexing, this challenge must use the indexing described (where 0 appears at 0).
- You may take I/O through any standard format.
Test Cases
-13: []
-12: []
-11: []
-10: []
-9: []
-8: [-6]
-7: []
-6: []
-5: []
-4: []
-3: [-4]
-2: []
-1: [-2]
0: 0
1: [-1, 1, 2]
2: [-3, 3]
3: [4]
4: []
5: [-5, 5]
6: []
7: []
8: [6]
9: []
10: []
11: []
12: []
13: [-7, 7]
And some larger test cases:
89: [-11, 11]
1836311903: [46]
10000: []
-39088169: [-38]
As usual, shortest answer in bytes wins!