Find the Fibonacci Patterns
MATL, 14 bytes
Thanks to Emigna for pointing out a mistake, now corrected
`yVdd~?yD]wy+T
Infinite loop that outputs the numbers as they are found.
Try it online! Note that in the online interpreter the results are displayed after the 1-minute time-out.
Explanation
Let F(n)
and F(n+1)
denote two generic consecutive terms of the Fibonacci sequence. Each iteration of the loop starts with the stack containing F(n)
, F(n+1)
for some n
.
` % Do...while
y % Duplicate from below. Takes the two inputs F(0), F(1) (implicitly)
% in the first iteration
% STACK: F(n), F(n+1), F(n)
V % Convert to string. Let the digits of F(n) be '3579' for example
% STACK: F(n), F(n+1), '3579'
d % Consecutive differences (of ASCII codes)
% STACK: F(n), F(n+1), [2 2 2]
d % Consecutive differences
% STACK: F(n), F(n+1), [0 0]
~ % Logical negate, element-wise
% STACK: F(n), F(n+1), [1 1]
? % If top of the stack is non-empty and only contains non-zero entries
% (this is the case for digits '3579', but not for '3578' or '33')
% STACK: F(n), F(n+1)
y % Duplicate from below
% STACK: F(n), F(n+1), F(n)
D % Display immediately. This prints the copy of F(n)
% STACK: F(n), F(n+1)
] % End
w % Swap
% STACK: F(n+1), F(n)
y % Duplicate from below
% STACK: F(n+1), F(n), F(n+1)
+ % Add. Note that F(n)+F(n+1) is F(n+2)
% STACK: F(n+1), F(n+2)
T % Push true. This will be used as loop condition
% STACK: F(n+1), F(n+2), true
% End (implicit). The top of the stack is consumed as loop condition.
% Since it is true, a new iteration will begin, with the stack
% containing F(n+1), F(n+2)
05AB1E, 17 16 15 bytes
тFÂ2£O¸«}ʒS¥¥_W
Try it online!
Explanation
# implicitly input list of F(0) and F(1)
тF } # 100 times do:
 # bifurcate current list
2£ # take the first 2 items
O # sum
¸« # append to list
ʒ # filter, keep only elements that are true after:
S¥¥ # delta's of delta's of digits
_ # logically negate each
W # min
JavaScript (ES6), 85 84 81 bytes
f=(p,q,a=[])=>p|q?f(q,p+q,![...p+''].some(x=d=n=>r=d-(d=x-(x=n)))/r?[...a,p]:a):a
Try it online!
Testing adjacent digits
![...p + ''].some(x = d = n => r = d - (d = x - (x = n))) / r
Both x and d are initialized to an anonymous function, which forces NaN
for all arithmetic operations they're involved in. The first iteration of some()
always gives (d = [function] - n) === NaN
and (r = [function] - d) === NaN
(falsy). On the second iteration, we have d = x - n
(an integer) and (r = NaN - d) === NaN
(falsy again). Starting from the third iteration, r is set to an integer which is non-zero if the difference between digit #3 and digit #2 is not equal to the difference between digit #2 and digit #1.
The number p is meeting the required criteria if and only if some()
is falsy (all adjacent digits have the same difference) and the final value of r is 0 (there were at least 3 iterations). This gives !false / 0 === true / 0 === Infinity
(truthy).
We may otherwise have:
!true / r
with r > 0 or r < 0, which givesfalse / r === 0
(falsy)!false / NaN
, which givestrue / NaN === NaN
(falsy)
Halting condition
The recursion stops when p | q
evaluates to 0. This is guaranteed to happen when both p and q reach values around 1025 which are 84-bit long. Because JS has 52 bits of mantissa, the last 32 bits are zeroed. So, the 32-bit bitwise OR evaluates to 0.
Due to the fast growing rate of the sequence, this happens rather quickly.