9
Consider a sequence F
of positive integers where F(n) = F(n-1) + F(n-2)
for n >= 2
. The Fibonacci sequence is almost one example of this type of sequence for F(0) = 0, F(1) = 1
, but it's excluded because of the positive integer requirement. Any two initial values will yield a different sequence. For example F(0) = 3, F(1) = 1
produces these terms.
3, 1, 4, 5, 9, 14, 23, 37, 60, 97, ...
Challenge
The task is to find F(0)
and F(1)
that minimize F(0) + F(1)
given some term of a sequence F(n)
. Write a function or complete program to complete the task.
Input
Input is a single positive integer, F(n)
. It may be accepted as a parameter or from standard input. Any reasonable representation is allowed, including direct integer or string representations.
Invalid inputs need not be considered.
Output
The output will be two positive integers, F(0)
and F(1)
. Any reasonable format is acceptable. Here are some examples of reasonable formats.
- Written on separate lines to standard output
- Formatted on standard output as a delimited 2-element list
- Returned as a tuple or 2-element array of integers from a function
Examples
60 -> [3, 1]
37 -> [3, 1]
13 -> [1, 1]
26 -> [2, 2]
4 -> [2, 1]
5 -> [1, 1]
6 -> [2, 2]
7 -> [2, 1]
12 -> [3, 2]
1 -> [1, 1]
Scoring
This is code golf. The score is calculated by bytes of source code.
does
12 -> [4, 0]
count? – Flame – 2018-11-02T19:10:35.390F
is a sequence of positive integers, and 0 isn't positive, so that's not valid. – recursive – 2018-11-02T19:10:59.043Nitpick: the Fibonacci sequence may be defined by $F[0] = 0, F[1] = 1$ or $F[1] = F[2] = 1$. Many of the sequence's well-known properties rely on this indexing. – Dennis – 2018-11-02T20:58:42.910
@Dennis: Technical correctness being the best kind, I've tweaked that part. – recursive – 2018-11-02T21:28:58.810
This feels familiar but, at the same time, I think the challenge I might be thinking of is the reverse of this - given
F(0)
,F(1)
andn
as input, outputF(n-1)+F(n-2)
. – Shaggy – 2018-11-02T22:48:08.747This looks like a duplicate of The lowest initial numbers in a Fibonacci-like sequence
– xnor – 2018-11-02T22:50:45.333@xnor: Yes, I suppose it is. Being the author isn't enough to close it though, but I voted for it. – recursive – 2018-11-02T23:07:23.490
1I knew this challenge looked familiar but I couldn't find it. I've closed it, although I forgot that my vote was a hammer. – Giuseppe – 2018-11-02T23:28:33.883