12
1
For this code golf, you will receive an input of a fibonacci sequence, that is, a normal Fibonacci sequence but with one number incorrect. See, the sequence is fibbing! Get it? :D
Your job is to find out which number is incorrect, and print the index (0-based) of that number.
For example:
Input : 1 1 2 9 5 8 13
Output: 3
Input : 8 13 21 34 55 80
Output: 5
Input : 2 3 5 5 13 21
Output: 3
Specifications:
- The sequence may start at any number.
- The first two numbers of the input will always be correct.
- Shortest code (character count) wins.
The job is to find only the first such number, right? For example, if you started from the right in the first sequence you could think that
8
is incorrect because it doesn't equal9+5
– Luis Mendo – 2015-01-23T16:40:51.300@LuisMendo There will always be only one such number. – Doorknob – 2015-01-23T16:48:58.173
@Doorknob That depends on which criterion you use. In the first sequence, 9 and 8 are both incorrect, as I see it (9 is not 1+2; and 8 is not 9+5) – Luis Mendo – 2015-01-23T16:50:56.997
1@LuisMendo Okay, let me reword that: There will always be exactly one way to change a single number that causes the sequence to be correct. – Doorknob – 2015-01-23T16:53:47.590
@Doorknob Oh, I understand now. I think your rephrasing implies that the changed element should always be the first that is wrong (and so my answer is valid) – Luis Mendo – 2015-01-23T21:43:52.427
2Does the input have to be space-delimited or can commas be used as well? – Volatility – 2013-06-23T00:26:52.137
@Volatility Input is space-delimited. – Doorknob – 2013-06-23T00:33:26.563