Home » Print Sine Wave for Amplitudes

Print Sine Wave for Amplitudes

Print Sine Wave for Amplitudes given in B2 Example for Amplitudes 2, 3 and 4 are given. Always 5 columns only need to be filled in.

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

Solving the challenge of Print Sine Wave for Amplitudes with Power Query

Power Query solution 1 for Print Sine Wave for Amplitudes, proposed by Bo Rydobon 🇹🇭:
let
  n   = 3, 
  b   = List.Accumulate({2 .. n}, {"1"}, (s, l) => s & {Text.From(l) & List.Last(s) & Text.From(l)}), 
  c   = List.Repeat({null}, n - 1) & List.Reverse(b), 
  Ans = Table.FromColumns({b, c, b, c, b})
in
  Ans
Power Query solution 2 for Print Sine Wave for Amplitudes, proposed by Zoran Milokanović:
let
  Source = 5 /* Amp */, 
  A = List.Accumulate, 
  T = List.Transform, 
  L = List.Last, 
  S = Table.FromColumns(
    A(
      {1 .. 4}, 
      {
        T(
          {1 .. Source}, 
          each Text.Combine(
            T(
              A(
                {1 .. _ * 2 - 2}, 
                {_}, 
                (s, c) => s & {L(s, _) + Number.Sign(Number.From(List.Contains(s, 1)) - .1)}
              ), 
              Text.From
            )
          )
        )
          & List.Repeat({null}, Source - 1)
      }, 
      (s, c) => s & {List.Reverse(L(s))}
    )
  )
in
  S
Power Query solution 3 for Print Sine Wave for Amplitudes, proposed by Aditya Kumar Darak 🇮🇳:
let
  N = 4, 
  Generate = List.Generate(
    () => [a = 1, b = "1"], 
    each [a] < 2 * N, 
    each [a = [a] + 1, T = Text.From(a), b = if a > N then null else T & [b] & T], 
    each Number.From([b])
  ), 
  List = List.RemoveLastN(List.Repeat({Generate} & {List.Reverse(Generate)}, 3), 1), 
  Return = Table.FromColumns(List)
in
  Return
Power Query solution 4 for Print Sine Wave for Amplitudes, proposed by Alejandro Simón 🇵🇦 🇪🇸:
let
  Source = Excel.CurrentWorkbook(){[Name = "Table1"]}[Content]{0}[Column1], 
  Process = List.Transform(
    {1 .. Source}, 
    each Text.Combine(List.Transform(List.Reverse({1 .. _}) & List.Skip({1 .. _}), Text.From))
  )
    & List.Repeat({null}, Source - 1), 
  Sol = Table.FromColumns(
    List.Transform({1 .. 5}, each if Number.IsOdd(_) then Process else List.Reverse(Process))
  )
in
  Sol
Power Query solution 5 for Print Sine Wave for Amplitudes, proposed by Luan Rodrigues:
let
  Fonte = 5, 
  fx = (n) => {1 .. n}, 
  res = [
    a = Table.TransformRows(Table.FromColumns({{1 .. Fonte}}), each fx([Column1])), 
    b = List.Transform(a, each List.RemoveLastN(List.Reverse(_))), 
    c = List.Transform(
      List.Zip({b, a}), 
      each Text.Combine(List.Transform(List.Combine(_), Text.From))
    )
      & List.Repeat({null}, Fonte - 1), 
    d = Table.FromColumns(List.RemoveLastN(List.Repeat({c} & {List.Reverse(c)}, 3)))
  ][d]
in
  res
Power Query solution 6 for Print Sine Wave for Amplitudes, proposed by Rafael González B.:
let
 Source = 5, // Amp Number
 L = List.Generate( () => [a = {"1"}, i = 0],
 each [i] <= Source - 1,
 each [a = [a] & {Text.From(b{[i]}) & List.Last([a]) & Text.From(b{[i]})}, 
 b = {2..Source},
 i = [i] + 1],
 each [a]
 ),
 O = L{Source - 1},
 N = List.Repeat({null}, Source - 1),
 U = List.InsertRange(O,Source, N),
 R = List.Reverse(U),
 Z = List.Zip({U,R}),
 T = hashtag#table(null, Z),
 D = List.Repeat(T[Column1] & T[Column2],3),
 S = List.Split(D, List.Count(Z)),
 E = List.RemoveLastN(S),
 Ans = Table.FromColumns(E)
 
in
 Ans
🧙‍♂️🧙‍♂️🧙‍♂️
                    
                  
          
Power Query solution 7 for Print Sine Wave for Amplitudes, proposed by Rafael González B.:
let
 Source = 5, // Amp Number
 l1 = {2..Source},
 L = List.Accumulate(l1, {"1"}, 
 (s,c) => let 
 o = s,
 p = Text.From(c),
 q = List.Last(o)
 
 in 
 o & {p & q & p}
 ),
 
 N = List.Repeat({null}, Source - 1),
 U = List.InsertRange(L,Source, N),
 R = List.Reverse(U),
 Z = List.Zip({U,R}),
 T = hashtag#table(null, Z),
 D = List.Repeat(T[Column1] & T[Column2],3),
 S = List.Split(D, List.Count(Z)),
 E = List.RemoveLastN(S),
 Ans = Table.FromColumns(E)
 
in
 Ans


                    
                  
          

Solving the challenge of Print Sine Wave for Amplitudes with Excel

Excel solution 1 for Print Sine Wave for Amplitudes, proposed by Bo Rydobon 🇹🇭:
=LET(
    a,
    SEQUENCE(
        B1
    ),
    s,
    --SCAN(
        ,
        a,
        LAMBDA(
            a,
            v,
            v&a&v
        )
    ),
    t,
    DROP(
        VSTACK(
            IF(
                a,
                ""
            ),
            SORTBY(
                s,
                -s
            )
        ),
        1
    ),
    IFNA(
        HSTACK(
            s,
            t,
            s,
            t,
            s
        ),
        ""
    )
)
Excel solution 2 for Print Sine Wave for Amplitudes, proposed by Rick Rothstein:
=LET(s,
    SEQUENCE(
        N1
    ),
    n,
    SCAN(0,
    s,
    LAMBDA(a,
    x,
    IF(x=1,
    1,
    10*a+x+x*10^(2*x-2)))),
    c,
    COUNT(
        n
    ),
    r,
    VSTACK(
        SUBSTITUTE(
            SEQUENCE(
                N1-1,
                ,
                -1,
                0
            ),
            -1,
            NA()
        ),
        INDEX(
            n,
            SEQUENCE(
                c,
                ,
                c,
                -1
            )
        )
    ),
    IFNA(
        HSTACK(
            n,
            r,
            n,
            r,
            n
        ),
        ""
    ))
Excel solution 3 for Print Sine Wave for Amplitudes, proposed by John V.:
=LET(
    s,
    SEQUENCE(
        2*B1-1
    ),
    g,
    IF(
        s>B1,
        "",
        --SCAN(
            ,
            s,
            LAMBDA(
                a,
                v,
                v&a&v
            )
        )
    ),
    IF(
        {1,
        0,
        1,
        0,
        1},
        g,
        SORTBY(
            g,
            -s
        )
    )
)
Excel solution 4 for Print Sine Wave for Amplitudes, proposed by محمد حلمي:
=LET(
    b,
    B1,
    s,
    SEQUENCE(
        b*2-1
    ),
    i,
    SEQUENCE(
        ,
        5
    ),
    e,
    IF(
        i,
        --SCAN(
            ,
            s,
            LAMBDA(
                a,
                d,
                IF(
                    d<=b,
                    d&a&d,
                    MID(
                        a,
                        2,
                        LEN(
                            a
                        )-2
                    )
                )
            )
        )
    ),
    
    IF(
        MOD(
            i,
            2
        ),
        IF(
            s<=b,
            e,
            ""
        ),
        IF(
            s>=b,
            e,
            ""
        )
    )
)
Excel solution 5 for Print Sine Wave for Amplitudes, proposed by Kris Jaganah:
=LET(a,
    B1,
    b,
    SEQUENCE(
        a
    ),
    c,
    VSTACK(
        b,
        -DROP(
            SORT(
                b,
                ,
                -1
            ),
            1
        )
    ),
    d,
    ABS(
        c
    ),
    e,
    --MAP(d,
    LAMBDA(x,
    CONCAT(
        SORT(
            UNIQUE(
                IF(
                    x=d)*(d<>1),
    d,
    ""))))),
    f,
    SEQUENCE(
        ,
        5
    ),
    IFS(c=a,
    e,
    MOD(
        f,
        2
    )*(c>0),
    e,
    (MOD(
        f,
        2
    )=0)*(c<0),
    e,
    1,
    ""))
Excel solution 6 for Print Sine Wave for Amplitudes, proposed by Timothée BLIOT:
=LET(
    A,
    B1,
    F,
    LAMBDA(
        n,
        DROP(
            REDUCE(
                "",
                n,
                LAMBDA(
                    a,
                    v,
                    VSTACK(
                        a,
                        IF(
                            v=1,
                            1,
                            CONCAT(
                                VSTACK(
                                    SEQUENCE(
                                        v,
                                        ,
                                        v,
                                        -1
                                    ),
                                    SEQUENCE(
                                        v-1,
                                        ,
                                        2
                                    )
                                )
                            )
                        )
                    )
                )
            ),
            1 
        )
    ),
    
    G,
     LAMBDA(
         m,
         DROP(
             VSTACK(
                 F(
                     SEQUENCE(
                         m
                     )
                 ),
                 TEXTSPLIT(
                     REPT(
                         ":",
                         m
                     ),
                     ,
                     ":"
                 )
             ),
              -2
         )
     ),
    H,
    LAMBDA(
        m,
        DROP(
            VSTACK(
                TEXTSPLIT(
                    REPT(
                        ":",
                        m
                    ),
                    ,
                    ":"
                ),
                F(
                    SEQUENCE(
                        m,
                        ,
                         m,
                        -1
                    )
                )
            ),
            2
        )
    ),
    I,
    HSTACK(
        G(
            A
        ),
        H(
            A
        )
    ),
     HSTACK(
         I,
         I,
         G(
            A
        )
     )
)
Excel solution 7 for Print Sine Wave for Amplitudes, proposed by Sunny Baggu:
=LET(
    
     _col1,
     VSTACK(
         
          MAP(
              
               SEQUENCE(
                   B1
               ),
              
               LAMBDA(
                   a,
                    CONCAT(
                        SEQUENCE(
                            a,
                             ,
                             a,
                             -1
                        ),
                         IFERROR(
                             DROP(
                                 SEQUENCE(
                                     a
                                 ),
                                  1
                             ),
                              ""
                         )
                    )
               )
               
          ),
         
          EXPAND(
              "",
               B1 - 1,
               ,
               ""
          )
          
     ),
    
     _col2,
     SORTBY(
         _col1,
          -SEQUENCE(
              ROWS(
                  _col1
              )
          )
     ),
    
     IF(
         ISEVEN(
             COLUMN(
                 N4:R4
             )
         ),
          _col1,
          _col2
     )
    
)
Excel solution 8 for Print Sine Wave for Amplitudes, proposed by Sunny Baggu:
=LET(
 _col1, VSTACK(SCAN(, SEQUENCE(B1), LAMBDA(a, v, v & a & v)), EXPAND("", B1 - 1)),
 _col2, SORTBY(_col1, -SEQUENCE(B1 + (B1 - 1))),
 IFNA(HSTACK(_col1, _col2, _col1, _col2, _col1), "")
)
Excel solution 9 for Print Sine Wave for Amplitudes, proposed by Abdallah Ally:
=LET(
    a,
    B1,
    b,
    2*a-1,
    c,
    EXPAND(
        REDUCE(
            1,
            SEQUENCE(
                B1-1,
                ,
                2
            ),
            LAMBDA(
                x,
                y,
                VSTACK(
                    x,
                    CONCAT(
                        SEQUENCE(
                            y,
                            ,
                            y,
                            -1
                        ),
                        DROP(
                            SEQUENCE(
                                y,
                                ,
                                2
                            ),
                            -1
                        )
                    )
                )
            )
        ),
        b,
        1,
        ""
    ),
    d,
    SORTBY(
        c,
        SEQUENCE(
            b
        ),
        -1
    ),
    HSTACK(
        c,
        d,
        c,
        d,
        c
    )
)
Excel solution 10 for Print Sine Wave for Amplitudes, proposed by 🇵🇪 Ned Navarrete C.:
=MAKEARRAY(
    B1*2-1,
    
     5,
    
     LAMBDA(
         f,
         c,
         
          IF(
               AND(
                   f<=B1,
                   ISODD(
                       c
                   )
               ),
              
               REDUCE(
                   ,
                   SEQUENCE(
                       f
                   ),
                   LAMBDA(
                       c,
                       v,
                       v&c&v
                   )
               ),
              
               IF(
                   AND(
                       f>=B1,
                       ISEVEN(
                       c
                   )
                   ),
                   
                    REDUCE(
                        ,
                        SEQUENCE(
                            B1*2-f
                        ),
                        LAMBDA(
                       c,
                       v,
                       v&c&v
                   )
                    ),
                   
                    ""
                    
               )
               
          )
          
     )
    
)
Excel solution 11 for Print Sine Wave for Amplitudes, proposed by Julien Lacaze:
=LET(d,B1,_rows,2*d-1,s,MAP(SEQUENCE(_rows),LAMBDA(a,IF(a<=d,CONCAT(IFERROR(SEQUENCE(a-1,,a,-1),""),SEQUENCE(a)),""))),
INDEX(s,MAKEARRAY(_rows,5,LAMBDA(r,c,IF(ISODD(c),r,_rows+1-r)))))
Excel solution 12 for Print Sine Wave for Amplitudes, proposed by Pieter de Bruijn:
=LET(n,
    B1,
    a,
    SCAN(,
    SEQUENCE(
        n*2-1
    ),
    LAMBDA(i,
    s,
    IF(s<=n,
    --(s&i&s),
    ""))),
    b,
    SORT(
        a,
        ,
        -1
    ),
    IFNA(
        HSTACK(
            a,
            b,
            a,
            b,
            a
        ),
        ""
    ))
or the inversed result:
=LET(
    n,
    B1,
    a,
    SEQUENCE(
        n*2
    ),
    b,
    SEQUENCE(
        n
    ),
    c,
    IF(
        a>n,
        "",
   &     REPT(
            1,
            SEQUENCE(
        n
    )
        )^2
    ),
    IF(
        ISODD(
            SEQUENCE(
                ,
                5
            )
        ),
        c,
        SORT(
            c,
            ,
            -1
        )
    )
)
Excel solution 13 for Print Sine Wave for Amplitudes, proposed by Abdelrahman Omer, MBA, PMP:
=LET(
    amp,
    B1,
    a,
    IFERROR(
        SUBSTITUTE(
            VSTACK(
                SCAN(
                    "",
                    SEQUENCE(
                        amp
                    ),
                    LAMBDA(
                        x,
                        y,
                        VSTACK(
                            y&x&y
                        )
                    )
                ),
                MAKEARRAY(
                    amp-1,
                    1,
                    LAMBDA(
                        x,
                        y,
                        ""
                    )
                )
            ),
            1,
            "",
            1
        ),
        1
    ),
    b,
    SORTBY(
        a,
        SEQUENCE(
            amp*2-1
        ),
        -1
    ),
    HSTACK(
        a,
        b,
        a,
        b,
        a
    )
)
Excel solution 14 for Print Sine Wave for Amplitudes, proposed by Kriddakorn Pongthanisorn:
=LET(
    _x,
     B13,
     s,
     SEQUENCE(
         2*_x-1
     ),
     c,
    ARRAYFORMULA(
        IF(
            _x-s>=0,
            s,
            ""
        )
    ),
     d,
     SORT(
         ARRAYFORMULA(
             IF(
                 _x-s>=0,
                 s,
                 ""
             )
         ),
         1,
         0
     ) ,
     f,
     
    MAP(
        HSTACK(
            c,
            d,
            c,
            d,
            c
        ),
         LAMBDA(
             a,
              IFERROR(
                  --CONCATENATE(
                      ARRAYFORMULA(
                          ABS(
                              SEQUENCE(
                                  2*a-1
                              )-SORT(
                                  SEQUENCE(
                                  2*a-1
                              ),
                                  1,
                                  
                              )
                          )/2+1
                      )
                  ),
                  
              )
         )
    ),
    f
)
Excel solution 15 for Print Sine Wave for Amplitudes, proposed by Kriddakorn Pongthanisorn:
=LET(
    a,
     J13,
     
    s,
     SEQUENCE(
         2*a-1
     ),
     _s2,
     SEQUENCE(
         1,
         5
     ),
    
    _m1,
     ArrayFormula(
         --MID(
             LEFT(
                 REPT(
                     10,
                     3
                 ),
                 5
             ),
             _s2,
             1
         )
     ),
    
    _m2,
     ArrayFormula(
         --MID(
             RIGHT(
                 REPT(
                     10,
                     3
                 ),
                 5
             ),
             _s2,
             1
         )
     ),
     
    g,
     ARRAYFORMULA(
         MMULT(
             s,
             _m1
         ) + MMULT(
             SORT(
                 s,
                 1,
                 0
             ),
             _m2
         )
     ) ,
     
    MAP(
        ARRAYFORMULA(
            IF(
                g<=a,
                g,
                
            )
        ),
         LAMBDA(
             a,
              IFERROR(
                  --CONCATENATE(
                      ARRAYFORMULA(
                          ABS(
                              SEQUENCE(
         2*a-1
     )-SORT(
                                  SEQUENCE(
         2*a-1
     ),
                                  1,
                                  
                              )
                          )/2+1
                      )
                  ),
                  
              )
         ) 
    )
)

Solving the challenge of Print Sine Wave for Amplitudes with Python in Excel

Python in Excel solution 1 for Print Sine Wave for Amplitudes, proposed by Bo Rydobon 🇹🇭:
a=xl("B1")
r=range(2,a+1)
x='1'
b=['' for x in r]
c=[x]+[x:=str(n)+x+str(n) if n>1 else x for n in r]+b
d=sorted(c,key=lambda x:'Ω' if x=='' else x , reverse=1)
np.transpose(np.vstack((c,d,c,d,c)))
                    
                  
Python in Excel solution 2 for Print Sine Wave for Amplitudes, proposed by John V.:
Hi everyone!
One (Python) option could be:
n = xl("B1")
l = [''.join(map(str, list(range(j, 0, -1)) + list(range(2, j + 1)))) for j in range(1, n + 1)] + [''] * (n - 1)
list(zip(l, l[::-1], l, l[::-1], l))
Blessings!
                    
                  

Solving the challenge of Print Sine Wave for Amplitudes with R

R solution 1 for Print Sine Wave for Amplitudes, proposed by Konrad Gryczan, PhD:
library(tibble)
library(purrr)
generate_wave <- function(amp) {
 n_rows <- 2 * amp - 1
 generate_palindrome <- function(base) {
 sequence <- base:1
 number <- c(sequence, rev(sequence[-length(sequence)]))
 return(paste0(number, collapse = ""))
 }
 single_column <- rep(NA, n_rows)
 seq = c(1:amp, (amp-1):1)
 table = tibble(row = seq) %>%
 mutate(row_number = row_number(),
 col1 = map_chr(row, ~generate_palindrome(.x)),
 col2 = col1,
 col3 = col1,
 col4 = col1,
 col5 = col1) %>%
 mutate_at(vars(col1, col3, col5), 
 ~ifelse(row_number > amp, " ", .)) %>%
 mutate_at(vars(col2, col4), 
 ~ifelse(row_number < amp, " ", .)) %>%
 mutate_at(vars(col1, col2, col3, col4, col5), 
 ~str_pad(., max(nchar(.), na.rm = TRUE), side = "both")) %>%
 select(-c(row_number, row))
 return(table)
}
                    
                  

&&

Leave a Reply