Home » Multiply Fibonacci and Lucas Numbers

Multiply Fibonacci and Lucas Numbers

Lucas Numbers – A term is sum of immediate previous two terms. Starting two terms are 2 & 1. So, these are like Fibonacci numbers but starting two terms in Fibonacci numbers are 0 & 1. List the product of first 20 Fibonacci & Lucas numbers term by term. Hence F1*L1, F2*L2, F3*L3….F20*L20 need to be listed. For reference purpose to know how the answer was arrived (in your solution, you will need to generate these) – First 20 Fibonacci numbers = 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181 First 20 Lucas numbers = 2, 1, 3, 4, 7, 11, 18, 29, 47, 76, 123, 199, 322, 521, 843, 1364, 2207, 3571, 5778, 9349 Unconfirmed Fact – It was Edouard Lucas who coined the term Fibonacci numbers.

📌 Challenge Details and Links
ExcelBI Excel Challenge Number: 376
Challenge Difficulty: ⭐️
📥Download Sample File
📥Link to the solutions on LinkedIn

Solving the challenge of Multiply Fibonacci and Lucas Numbers with Power Query

Power Query solution 1 for Multiply Fibonacci and Lucas Numbers, proposed by John V.:
let
 b = {0..19}, f = (i) => List.Accumulate(b, {i, 1}, (s, c) => s & {List.Sum(List.LastN(s, 2))})
in
 List.Transform(b, each f(0){_} * f(2){_})

or ( محمد حلمي
idea : )

✅
= List.Accumulate({0..18}, {0}, (s, c) => s & {1 + List.Sum(s) + List.Max(s)})

Blessings!


                    
                  
          
Power Query solution 2 for Multiply Fibonacci and Lucas Numbers, proposed by Alejandro Simón 🇵🇦 🇪🇸:
let
  Fib = List.Generate(
    () => [x = 1, y = 0, z = 0], 
    each [z] < 20, 
    each [x = [y], y = [x] + [y], z = [z] + 1], 
    each [y]
  ), 
  Lucas = List.Generate(
    () => [x = 2, y = 1, z = 0], 
    each [z] < 20, 
    each [x = [y], y = [x] + [y], z = [z] + 1], 
    each [x]
  ), 
  Sol = List.Transform({0 .. List.Count(Fib) - 1}, each Fib{_} * Lucas{_})
in
  Sol
Power Query solution 3 for Multiply Fibonacci and Lucas Numbers, proposed by An Nguyen:
let
  GenerateFibo = List.Accumulate(
    List.Buffer({1 .. 38}), 
    [r = {0, 1}], 
    (state, current) =>
      [Currentvalue = List.Sum(List.LastN(state[r], 2)), r = state[r] & {Currentvalue}]
  )[r], 
  MakeTable = Table.FromColumns({GenerateFibo}, {"Fibonacci Numbers"}), 
  AddIdx = Table.AddIndexColumn(MakeTable, "Idx"), 
  Result = Table.SelectRows(AddIdx, each Number.IsEven([Idx]))[Fibonacci Numbers]
in
  Result
Power Query solution 4 for Multiply Fibonacci and Lucas Numbers, proposed by Ramiro Ayala Chávez:
let
  a = List.Generate(
    () => [x = 0, y = 1, c = 1], 
    each [c] <= 20, 
    each [y = [x] + [y], x = [y], c = [c] + 1], 
    each [x]
  ), 
  b = List.Generate(
    () => [x = 2, y = 1, c = 1], 
    each [c] <= 20, 
    each [y = [x] + [y], x = [y], c = [c] + 1], 
    each [x]
  ), 
  c = List.Transform({0 .. 19}, each a{_} * b{_}), 
  Sol = Table.FromColumns({c}, {"Answer Expected"})
in
  Sol
Power Query solution 5 for Multiply Fibonacci and Lucas Numbers, proposed by Rafael González B.:
Hi Everyone, my {M} code:
FibLuc = 
 
 List.Generate(
 () => [i = 1, X = 0, Y = 1, X1 = 2, Y1 = 1],
 each [i] <= 20,
 each [
 i = [i] + 1,
 X = [Y],
 Y = [X] + [Y],
 X1 = [Y1],
 Y1 = [X1] + [Y1]
 ],
 each [X] * [X1]
 )
in
 FibLuc
                    
                  
Power Query solution 6 for Multiply Fibonacci and Lucas Numbers, proposed by Arden Nguyen, CPA:
let
  n = 20, 
  fn = (i as number, x1 as number, x2 as number, optional L as list) =>
    let
      a = L ?? {x1} & {x2}, 
      b = 
        if i <= n - 2 then
          @fn(i + 1, x1, x2, a & {List.Sum(List.LastN(a, 2))})
        else if n > 1 then
          a
        else
          {x1}
    in
      b, 
  res = List.Transform(List.Zip({fn(1, 0, 1), fn(1, 2, 1)}), List.Product)
in
  res

Solving the challenge of Multiply Fibonacci and Lucas Numbers with Excel

Excel solution 1 for Multiply Fibonacci and Lucas Numbers, proposed by Bo Rydobon 🇹🇭:
=TAKE(
    WRAPROWS(
        REDUCE(
            {0;1},
            SEQUENCE(
                38
            ),
            LAMBDA(
                a,
                v,
                VSTACK(
                    a,
                    SUM(
                        TAKE(
                            a,
                            -2
                        )
                    )
                )
            )
        ),
        2
    ),
    ,
    1
)
Excel solution 2 for Multiply Fibonacci and Lucas Numbers, proposed by Rick Rothstein:
=LET(
    f,
    LAMBDA(
        x,
        y,
        REDUCE(
            VSTACK(
                x,
                y
            ),
            SEQUENCE(
                18
            ),
            LAMBDA(
                a,
                v,
                VSTACK(
                    a,
                    SUM(
                        TAKE(
                            a,
                            -2
                        )
                    )
                )
            )
        )
    ),
    f(
        0,
        1
    )*f(
        2,
        1
    )
)
Excel solution 3 for Multiply Fibonacci and Lucas Numbers, proposed by John V.:
=LET(
    f,
    LAMBDA(
        i,
        REDUCE(
            i,
            ROW(
                1:18
            ),
            LAMBDA(
                a,
                v,
                VSTACK(
                    a,
                    SUM(
                        TAKE(
                            a,
                            -2
                        )
                    )
                )
            )
        )
    ),
    f(
        {0;1}
    )*f(
        {2;1}
    )
)
Excel solution 4 for Multiply Fibonacci and Lucas Numbers, proposed by محمد حلمي:
=INDEX(
    REDUCE(
        {0;1},
        SEQUENCE(
            38
        ),
        LAMBDA(
            a,
            d,
            VSTACK(
                a,
                SUM(
                    TAKE(
                        a,
                        -2
                    )
                )
            )
        )
    ),
    SEQUENCE(
        20,
        ,
        ,
        2
    )
)
Excel solution 5 for Multiply Fibonacci and Lucas Numbers, proposed by محمد حلمي:
=REDUCE(
    {0;1},
    SEQUENCE(
        18
    ),
    LAMBDA(
        a,
        d,
        VSTACK(
            a,
            SUM(
                a,
                MAX(
                    a
                ),
                1
            )
        )
    )
)
Excel solution 6 for Multiply Fibonacci and Lucas Numbers, proposed by محمد حلمي:
=REDUCE(
    {0;1},
    SEQUENCE(
        18
    ),
    LAMBDA(
        a,
        d,
        VSTACK(
            a,
            
            SUM(
                a
            )+TAKE(
                a,
                -1
            )+1
        )
    )
)
Excel solution 7 for Multiply Fibonacci and Lucas Numbers, proposed by Kris Jaganah:
=TAKE(WRAPROWS(REDUCE({0;1},
    SEQUENCE(
        38
    ),
    LAMBDA(x,
    y,
    VSTACK(x,
    SUM((TAKE(
        x,
        -2
    )))))),
    2),
    ,
    1)
Excel solution 8 for Multiply Fibonacci and Lucas Numbers, proposed by Timothée BLIOT:
=LET(
    A,
    LAMBDA(
        x,
        y,
        REDUCE(
            VSTACK(
                x,
                y
            ),
            SEQUENCE(
                18
            ),
            LAMBDA(
                a,
                v,
                VSTACK(
                    a,
                    SUM(
                        TAKE(
                            a,
                            -2
                        )
                    )
                )
            )
        )
    ),
    A(
        0,
        1
    )*A(
        2,
        1
    )
)
Excel solution 9 for Multiply Fibonacci and Lucas Numbers, proposed by Sunny Baggu:
=LET(
 _e1,
     LAMBDA(
         arr,
         
          REDUCE(
              arr,
               SEQUENCE(
                   20
               ),
               LAMBDA(
                   A,
                    V,
                    VSTACK(
                        A,
                         SUM(
                             TAKE(
                                 A,
                                  -2
                             )
                         )
                    )
               )
          )
          
     ),
    
 TAKE(_e1({0; 1}) * _e1({2; 1}),
     20)
)
Excel solution 10 for Multiply Fibonacci and Lucas Numbers, proposed by LEONARD OCHEA 🇷🇴:
=LET(s,
    2*(ROW(
        1:20
    )-1),
    x,
    5^0.5,
    y,
    (1+x)/2,
    z,
    y-x,
    (y^s-z^s)/x)
Excel solution 11 for Multiply Fibonacci and Lucas Numbers, proposed by Abdallah Ally:
=LET(
    n,
    20,
    f,
    LAMBDA(
        f,
        a,
        b,
        IF(
            b=n,
            a,
            f(
                f,
                VSTACK(
                    a,
                    SUM(
                        TAKE(
                            a,
                            -2
                        )
                    )
                ),
                b+1
            )
        )
    ),
     f(
         f,
         {0;1},
         2
     )*f(
         f,
         {2;1},
         2
     )
)
Excel solution 12 for Multiply Fibonacci and Lucas Numbers, proposed by An Nguyen:
=LET(p,
    (1+SQRT(
        5
    ))/2,
    f,
    LAMBDA(x,
    (p^x-(1-p)^x)/SQRT(
        5
    )),
    f(
        SEQUENCE(
            20,
            ,
            0
        )
    )*VSTACK(
        2,
        1,
        ROUND(
            p^SEQUENCE(
                18,
                ,
                2
            ),
            0
        )
    ))
Excel solution 13 for Multiply Fibonacci and Lucas Numbers, proposed by Charles Roldan:
=LET(f,
     LAMBDA(
         G,
          G(
              G
          )
     )(LAMBDA(g,
     
 LAMBDA(a,
     n,
     
 IF(n <= COUNTA(
     a
 ),
     TAKE(
         a,
          n
     ),
     
 LAMBDA(
     x,
      VSTACK(
          x,
           SUM(
               TAKE(
                   x,
                    -2
               )
           )
      )
 )(g(
     g
 )(a,
     n - 1)))))),
    
 f(
     {0; 1},
      20
 ) * f(
     {2; 1},
      20
 ))
Excel solution 14 for Multiply Fibonacci and Lucas Numbers, proposed by Charles Roldan:
=INT(((1+SQRT(
    5
))/2)^(2*SEQUENCE(
    20,
    ,
    0
))/SQRT(
    5
))
Excel solution 15 for Multiply Fibonacci and Lucas Numbers, proposed by Bilal Mahmoud kh.:
=REDUCE(
    0,
    ROW(
        1:20
    ),
    LAMBDA(
        x,
        y,
        VSTACK(
            x,
            IFERROR(
                LARGE(
                    x,
                    1
                )+LARGE(
                    x,
                    2
                ),
                1
            )
        )
    )
)
and for the Lucas series,
     we can generate by the following formula:
=REDUCE(
    2,
    ROW(
        1:20
    ),
    LAMBDA(
        x,
        y,
        IF(
            LARGE(
                    x,
                    1
                )<>3,
            VSTACK(
            x,
            IFERROR(
                LARGE(
                    x,
                    1
                )+LARGE(
                    x,
                    2
                ),
                1
            )
        ),
            VSTACK(
                x,
                IFERROR(
                    LARGE(
                    x,
                    1
                )+SMALL(
                    x,
                    1
                ),
                    1
                )
            )
        )
    )
)
Excel solution 16 for Multiply Fibonacci and Lucas Numbers, proposed by JvdV -:
=REDUCE(
    ,
    ROW(
        1:20
    )-1,
    LAMBDA(
        x,
        y,
        VSTACK(
            x,
            SUM(
                x,
                MAX(
                    x
                ),
                1
            )
        )
    )
)
Excel solution 17 for Multiply Fibonacci and Lucas Numbers, proposed by Pieter de Bruijn:
=REDUCE(
    ,
    SEQUENCE(
        20
    )-1,
    LAMBDA(
        x,
        y,
        VSTACK(
            x,
            SUM(
                x,
                MAX(
                    x
                ),
                1
            )
        )
    )
)
Excel solution 18 for Multiply Fibonacci and Lucas Numbers, proposed by Pieter de Bruijn:
=LET(
    z,
    LAMBDA(
        x,
        y,
        REDUCE(
            VSTACK(
                x,
                y
            ),
            ROW(
                1:18
            ),
            LAMBDA(
                x,
                y,
                VSTACK(
                    x,
                    SUM(
                        TAKE(
                            x,
                            -2
                        )
                    )
                )
            )
        )
    ),
    z(
        0,
        1
    )*z(
        2,
        1
    )
)
Excel solution 19 for Multiply Fibonacci and Lucas Numbers, proposed by Giorgi Goderdzishvili:
=LET(
    
    lst,
    SCAN(
        "0!1",
        SEQUENCE(
            75
        ),
        LAMBDA(
            a,
            v,
            
            CONCAT(
                TAKE(
                    TEXTSPLIT(
                        a,
                        "!"
                    ),
  &                  ,
                    -1
                ),
                "!",
                SUM(
                    --TEXTSPLIT(
                        a,
                        "!"
                    )
                )
            )
        )
    ),
    
    tx,
     VSTACK(
         0,
         1*TEXTBEFORE(
             lst,
             "!"
         )
     ),
    
    FILTER(
        TAKE(
            tx,
            40
        ),
        ISODD(
            --SEQUENCE(
                40
            )
        )
    )
)
Excel solution 20 for Multiply Fibonacci and Lucas Numbers, proposed by Arden Nguyen, CPA:
=LET(
    
    a,
    LAMBDA(
        x,
        REDUCE(
            VSTACK(
                x,
                 1
            ),
             SEQUENCE(
                 18,
                  ,
                  2
             ),
             LAMBDA(
                 s,
                 c,
                  VSTACK(
                      s,
                       INDEX(
                           s,
                            c
                       ) + INDEX(
                           s,
                            c - 1
                       )
                  )
             )
        )
    ),
    
    a(
        2
    )*a(
        0
    )
)

Solving the challenge of Multiply Fibonacci and Lucas Numbers with Python

Python solution 1 for Multiply Fibonacci and Lucas Numbers, proposed by John V.:
Hi everyone!
def s(i, n):
 p = [i, 1]
 [p.append(p[-2] + p[-1]) for _ in range(2, 1+n)]
 return p
[a * b for a, b in zip(s(0, 19), s(2, 19))]
s = [0]
[s.append(1 + sum(s) + s[-1]) for _ in range(1, 20)]
s
Blessings!
                    
                  
Python solution 2 for Multiply Fibonacci and Lucas Numbers, proposed by Giorgi Goderdzishvili:
srt_lst = [0,1]
for k in range(0,20):
 for i in range(50):
 new = srt_lst[-2] + srt_lst[-1]
 srt_lst.append(new)
 print(srt_lst[2*k])
                    
                  
Python solution 3 for Multiply Fibonacci and Lucas Numbers, proposed by Jan Willem Van Holst:
in Python:
import numpy as np
fib = [0,1]
luc = [2,1]
for i in range(2,20):
 new = fib[i-2]+fib[i-1]
 fib.append(new)
 new = luc[i-2]+luc[i-1]
 luc.append(new)
answer  = np.array(fib) * np.array(luc)
                    
                  

Solving the challenge of Multiply Fibonacci and Lucas Numbers with R

R solution 1 for Multiply Fibonacci and Lucas Numbers, proposed by Konrad Gryczan, PhD:
library(tidyverse)
library(readxl)
test = read_excel("Excel/376 Mult of Lucas and Fibonacci.xlsx", range = "A1:A21") %>%
 pull(`Answer Expected`)
 if (n == 1)
 return(first)
 if (n == 2)
 return(c(first, second))
 
 sequence = reduce(rep(1, n - 2), function(x, y) {
 c(x, sum(tail(x, 2)))
 }, .init = c(first, second))
 
 return(sequence)
}
fib = generate_sequence(20, 0, 1)
lucas = generate_sequence(20, 2, 1)
result = tibble(fib = fib,
 lucas = lucas,
 ratio = lucas * fib) %>%
 pull(ratio)
                    
                  

&&

Leave a Reply