A Fibonacci number is a sum of previous two terms starting with 0 & 1. Hence, 0, 1, 1, 2, 3, 5, 8, 13, 21, 34….are Fibonacci numbers. Find the first 20 EVEN Fibonacci numbers.
📌 Challenge Details and Links
ExcelBI Excel Challenge Number: 316
Challenge Difficulty: ⭐️
📥Download Sample File
📥Link to the solutions on LinkedIn
Solving the challenge of Find the first 20 EVEN Fibonacci numbers with Power Query
Power Query solution 1 for Find the first 20 EVEN Fibonacci numbers, proposed by Bo Rydobon 🇹🇭:
let
Fb = List.Alternate(
List.Accumulate({1 .. 58}, {0, 1}, (s, l) => s & {List.Sum(List.LastN(s, 2))}),
2,
1,
1
)
in
Fb
Power Query solution 2 for Find the first 20 EVEN Fibonacci numbers, proposed by Zoran Milokanović:
let
Source = 20,
S = List.Accumulate(
{1 .. Source - 2},
{0, 2},
(s, c) =>
let
l = List.LastN(s, 2)
in
s & {l{0} + 4 * l{1}}
)
in
S
Power Query solution 3 for Find the first 20 EVEN Fibonacci numbers, proposed by Kris Jaganah:
let
A = List.Generate(
() => 1,
each _ < 10000000000000,
each Number.Round(_ * 1.61803398874989, 0),
each if Number.IsEven(_) then _ else null
),
B = List.FirstN(List.InsertRange({0}, 1, List.RemoveNulls(A)), 20)
in
B
Power Query solution 4 for Find the first 20 EVEN Fibonacci numbers, proposed by Rick de Groot:
let
GRatio = (1 + Number.Sqrt(5)) / 2,
NP = Number.Power
in
List.Transform({0 .. 19}, each (NP(GRatio, 3 * _) - NP(- GRatio, - 3 * _)) / (2 * GRatio - 1))
Power Query solution 5 for Find the first 20 EVEN Fibonacci numbers, proposed by Aditya Kumar Darak 🇮🇳:
let
Generate = List.Generate(
() => [a = {0, 1}, b = 0, c = 1],
each [c] <= 20,
each [
a = {[a]{1}, List.Sum([a])},
b = if TF then a{1} else null,
TF = Number.IsEven(a{1}),
c = [c] + Number.From(TF)
],
each [b]
),
Return = List.RemoveNulls(Generate)
in
Return
Power Query solution 6 for Find the first 20 EVEN Fibonacci numbers, proposed by Alejandro Simón 🇵🇦 🇪🇸:
let
Sol = List.Select(
{0}
& List.Generate(
() => [x = 1, y = 0, z = 1],
each [z] <= 19,
each [x = [y], y = [y] + [x], z = if Number.IsEven(y) then [z] + 1 else [z]],
each [x] + [y]
),
each Number.IsEven(_)
)
in
Sol
Power Query solution 7 for Find the first 20 EVEN Fibonacci numbers, proposed by Alexis Olson:
let
phi = (1 + Number.Sqrt(5)) / 2,
result = List.Transform(
{0 .. 19},
(n) => (Number.Power(phi, 3 * n) - Number.Power(- phi, - 3 * n)) / (2 * phi - 1)
)
in
result
Power Query solution 8 for Find the first 20 EVEN Fibonacci numbers, proposed by Luke Jarych:
let
Fibonacci = List.Generate(
() => [x = 0, y = 1, counter = 0],
each [counter] < 20,
each [y = [x] + [y], x = [y], counter = if Number.IsEven(y) then [counter] + 1 else [counter]],
each [x]
),
SelectEvens = List.Select(Fibonacci, each Number.IsEven(_))
in
SelectEvens
Solving the challenge of Find the first 20 EVEN Fibonacci numbers with Excel
Excel solution 1 for Find the first 20 EVEN Fibonacci numbers, proposed by Bo Rydobon 🇹🇭:
=INDEX(
REDUCE(
{0;1},
SEQUENCE(
60
),
LAMBDA(
a,
v,
VSTACK(
a,
SUM(
TAKE(
a,
-2
)
)
)
)
),
SEQUENCE(
20,
,
,
3
)
)
Excel solution 2 for Find the first 20 EVEN Fibonacci numbers, proposed by Rick Rothstein:
=TOCOL(
MAP(
SEQUENCE(
58,
,
0
),
LAMBDA(
x,
LET(
f,
FN(
x
),
IF(
ISEVEN(
f
),
f,
1/0
)
)
)
),
3
)
Excel solution 3 for Find the first 20 EVEN Fibonacci numbers, proposed by John V.:
=LET(b,
5^0.5,
s,
3*ROW(
1:20
)-3,
((1+b)^s-(1-b)^s)/2^s/b)
Excel solution 4 for Find the first 20 EVEN Fibonacci numbers, proposed by محمد حلمي:
=REDUCE(
{0;2},
SEQUENCE(
18
),
LAMBDA(
a,
v,
VSTACK(
a,
SUM(
TAKE(
a,
-2
)*{1;4}
)
)
)
)
Excel solution 5 for Find the first 20 EVEN Fibonacci numbers, proposed by Kris Jaganah:
=LET(a,VSTACK(0,1,SCAN(1,SEQUENCE(60),LAMBDA(x,y,ROUND(x*1.61803398874991,0)))),TAKE(FILTER(a,ISEVEN(a)),20))
Excel solution 6 for Find the first 20 EVEN Fibonacci numbers, proposed by Julian Poeltl:
=LET(S,
SEQUENCE(
1000,
,
0
),
FB,
(1/SQRT(
5
))*(((1+SQRT(
5
))/2)^S-((1-SQRT(
5
))/2)^S),
IE,
INT(
FB/2
)=(
FB/2
),
TAKE(
FILTER(
FB,
IE=TRUE
),
20
))
Excel solution 7 for Find the first 20 EVEN Fibonacci numbers, proposed by Timothée BLIOT:
=LET(
A,
REDUCE(
{0;1},
SEQUENCE(
99
),
LAMBDA(
a,
v,
VSTACK(
a,
SUM(
TAKE(
a,
-2
)
)
)
)
),
TAKE(
TOCOL(
IF(
ISODD(
A
),
1/0,
A
),
3
),
20
)
)
Recursive Lambda approach:
=LET(
F,
LAMBDA(
me,
n,
m,
IF(
n=1,
m,
me(
me,
n-1,
VSTACK(
m,
SUM(
TAKE(
m,
-2
)
)
)
)
)
),
A,
F(
F,
99,
{0;1}
),
TAKE(
TOCOL(
IF(
ISODD(
A
),
1/0,
A
),
3
),
20
)
)
Excel solution 8 for Find the first 20 EVEN Fibonacci numbers, proposed by Sunny Baggu:
=VSTACK(
0,
TAKE(
LET(
_num,
REDUCE(
1,
SEQUENCE(
100
),
LAMBDA(
a,
v,
VSTACK(
a,
SUM(
TAKE(
a,
-2
)
)
)
)
),
FILTER(
_num,
ISEVEN(
_num
)
)
),
19
)
)
Excel solution 9 for Find the first 20 EVEN Fibonacci numbers, proposed by LEONARD OCHEA 🇷🇴:
=LET(s,
SEQUENCE(
100,
,
0
),
k,
5^0.5,
n,
(((1+k)/2)^s-((1-k)/2)^s)/k,
TAKE(TOCOL(n/(INT(
n/2
)=n/2),
2),
20))
Excel solution 10 for Find the first 20 EVEN Fibonacci numbers, proposed by LEONARD OCHEA 🇷🇴:
=LET(s,
3*ROW(
1:20
)-3,
k,
5^0.5,
(((1+k)/2)^s-((1-k)/2)^s)/k)
Excel solution 11 for Find the first 20 EVEN Fibonacci numbers, proposed by Abdallah Ally:
=LET(
n,
20,
rfn,
LAMBDA(
f,
a,
x,
y,
IF(
COUNT(
UNIQUE(
a,
1
)
)=n,
UNIQUE(
a,
1
),
f(
f,
EXPAND(
a,
,
COUNT(
a
)+1,
IF(
ISEVEN(
y
),
y,
0
)
),
y,
x+y
)
)
),
TOCOL(
rfn(
rfn,
{0},
0,
1
)
)
)
Excel solution 12 for Find the first 20 EVEN Fibonacci numbers, proposed by Charles Roldan:
=ROUND(((1+SQRT(5))/2)^(3*SEQUENCE(20,,0))/SQRT(5),)
Excel solution 13 for Find the first 20 EVEN Fibonacci numbers, proposed by Peter Tholstrup:
= LAMBDA(
[a],
LET(
init,
SEQUENCE(
2,
,
0
),
a,
IF(
COUNT(
a
) < 2,
init,
a
),
next,
SUM(
TAKE(
a,
-2
)
),
new,
VSTACK(
a,
next
),
evens,
FILTER(
new,
MOD(
new,
2
) = 0
),
result,
IF(
COUNT(
evens
) < 20,
GetFirst20EvenFibonacciNumbers(
new
),
evens
),
result
)
)
Excel solution 14 for Find the first 20 EVEN Fibonacci numbers, proposed by Ziad A.:
=LET(f,REDUCE({0;1},ROW(1:56),LAMBDA(a,c,VSTACK(a,SUM(TAKE(a,-2))))),TOCOL(f/ISEVEN(f),2))
Excel solution 15 for Find the first 20 EVEN Fibonacci numbers, proposed by Giorgi Goderdzishvili:
=LET(
lst,
SCAN(
"0!1",
SEQUENCE(
60
),
LAMBDA(
a,
v,
CONCAT(
TAKE(
TEXTSPLIT(
a,
"!"
),
,
-1
),
"!",
SUM(
--TEXTSPLIT(
a,
"!"
)
)
)
)
),
rl,
VSTACK(
0,
--TEXTBEFORE(
lst,
"!"
)
),
fn,
TAKE(
FILTER(
rl,
ISEVEN(
--rl
)
),
20
),
fn
)
Excel solution 16 for Find the first 20 EVEN Fibonacci numbers, proposed by Amardeep Singh:
=LET(
d,
{0;2},
REDUCE(
d,
SEQUENCE(
18
),
LAMBDA(
x,
y,
VSTACK(
x,
CHOOSEROWS(
x,
-1
)*4 + CHOOSEROWS(
x,
-2
)
)
)
)
)
Excel solution 17 for Find the first 20 EVEN Fibonacci numbers, proposed by Amardeep Singh:
=LET(d,{0;1},
z,REDUCE(d,SEQUENCE(100),LAMBDA(x,y,VSTACK(x,SUM(TAKE(x,-2))))),
TAKE(FILTER(z,ISEVEN(z)),20))
Excel solution 18 for Find the first 20 EVEN Fibonacci numbers, proposed by Jeff Blakley:
=LET(f,LAMBDA(fx,a,IF(SUM(--ISEVEN(a))=20,a,fx(fx,VSTACK(a,SUM(TAKE(a,-2)))))),n,f(f,{0;1}),FILTER(n,ISEVEN(n)))
Solving the challenge of Find the first 20 EVEN Fibonacci numbers with Python
Python solution 1 for Find the first 20 EVEN Fibonacci numbers, proposed by John V.:
Hi everyone!
One [Python] option could be:
((1 + b) ** s &- (1 - b) ** s) / 2 ** s / b
Blessings!
Solving the challenge of Find the first 20 EVEN Fibonacci numbers with R
R solution 1 for Find the first 20 EVEN Fibonacci numbers, proposed by Konrad Gryczan, PhD:
library(tidyverse)
library(readxl)
test = read_excel("Even Fibonacci Numbers.xlsx", range = "A1:A21") %>% pull()
generate_even_fibonacci <- function() {
fibonacci_sequence <- c(1, 2)
even_fibonacci <- c(0, 2)
while (length(even_fibonacci) < 20) {
next_fibonacci <- sum(tail(fibonacci_sequence, 2))
fibonacci_sequence <- c(fibonacci_sequence, next_fibonacci)
if (next_fibonacci %% 2 == 0) {
even_fibonacci <- c(even_fibonacci, next_fibonacci)
}
}
return(even_fibonacci)
}
even_fibonacci <- generate_even_fibonacci()
identical(even_fibonacci, test)
Solving the challenge of Find the first 20 EVEN Fibonacci numbers with Excel VBA
Excel VBA solution 1 for Find the first 20 EVEN Fibonacci numbers, proposed by Rick Rothstein:
Rick Rothstein
Function FN(ByVal N As Long) As String
Dim X As Long, Z As Long
Dim Carry As Long
Dim PosSum As Long
Dim Minus0 As String
Dim Minus1 As String
Dim Minus2 As String
If N = 0 Then
FN = 0
ElseIf N = 1 Or N = 2 Then
FN = 1
Else
Minus1 = "1"
Minus2 = "1"
For X = 3 To N
Carry = 0
Minus0 = Space$(Len(Minus1))
If Len(Minus1) > Len(Minus2) Then
Minus2 = "0" & Minus2
End If
For Z = Len(Minus1) To 1 Step -1
PosSum = Val(Mid(Minus1, Z, 1)) + _
Val(Mid(Minus2, Z, 1)) + Carry
Mid$(Minus0, Z, 1) = Right(CStr(PosSum), 1)
Carry = IIf(PosSum < 10, 0, 1)
Next
If Carry Then Minus0 = "1" & Minus0
Minus2 = Minus1
Minus1 = Minus0
Next
FN = Minus0
End If
End Function
Excel VBA solution 2 for Find the first 20 EVEN Fibonacci numbers, proposed by Davit Bekurishvili:
Sub fibonacci()
Dim Previous As LongLong
Dim current As LongLong
Dim result As LongLong
Dim i As Long
Dim n As Long
n = 70
Previous = 0
current = 1
Cells(2, 1).Value = Previous
Cells(2, 2).Value = Previous Mod 2
Cells(3, 1).Value = current
Cells(3, 2).Value = current Mod 2
For i = 4 To n
result = Previous + current
Cells(i, 1).Value = result
Cells(i, 2).Value = result Mod 2
Previous = current
current = result
Next i
Set filterRange = ActiveSheet.Range("A2:B" & n)
filterRange.AutoFilter Field:=2, Criteria1:="=1", Operator:=xlFilterValues
filterRange.SpecialCells(xlCellTypeVisible).EntireRow.Delete
Range("B1").EntireColumn.Delete
Range("A22:A" & Rows.Count).EntireRow.Delete
Range("A1").EntireColumn.AutoFit
End Sub
&&
