Home » List the Polydivisible numbers

List the Polydivisible numbers

List the Polydivisible numbers. A Polydivisible number is that number where first 2 digits are divisible by 2, first 3 digits by 3 and so on. Ex. 9876 98 is divisible by 2 987 is divisible by 3 9876 is divisible by 4

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

Solving the challenge of List the Polydivisible numbers with Power Query

Power Query solution 1 for List the Polydivisible numbers, proposed by Bo Rydobon 🇹🇭:
let
  Source = Excel.CurrentWorkbook(){[Name = "Table1"]}[Content], 
  Ans = Table.SelectRows(
    Source, 
    each 
      let
        n = [Number], 
        l = Number.IntegerDivide(Number.Log10(n) + 1, 1)
      in
        List.Max(
          List.Transform(
            {1 .. l}, 
            (i) => Number.Mod(Number.IntegerDivide(n, Number.Power(10, l - i)), i)
          )
        )
          = 0
  )
in
  Ans
Power Query solution 2 for List the Polydivisible numbers, proposed by Zoran Milokanović:
let
  Source = Excel.CurrentWorkbook(){[Name = "Input"]}[Content], 
  T = each Text.From(_), 
  C = each 
    let
      l = Text.Length(_), 
      d = Expression.Evaluate(_ & "/" & T(l))
    in
      d = Int64.From(d) and (l = 1 or @C(Text.RemoveRange(_, l - 1))), 
  S = Table.SelectRows(Source, each C(T([Number])))
in
  S
Power Query solution 3 for List the Polydivisible numbers, proposed by Aditya Kumar Darak 🇮🇳:
let
  Source = Excel.CurrentWorkbook(){[Name = "data"]}[Content], 
  Return = Table.SelectRows(
    Source, 
    each [
      T = Text.From([Number]), 
      D = List.Transform({2 .. Text.Length(T)}, (f) => Number.Mod(Number.From(Text.Start(T, f)), f)), 
      R = List.Max(D) = 0
    ][R]
  )
in
  Return
Power Query solution 4 for List the Polydivisible numbers, proposed by Alejandro Simón 🇵🇦 🇪🇸:
let
  Origen = Excel.CurrentWorkbook(){0}[Content], 
  Sol = Table.SelectRows(
    Origen, 
    each 
      let
        a = Text.From([Number]), 
        b = {2 .. Text.Length(a)}, 
        c = List.Transform(b, each Number.Mod(Number.From(Text.Start(a, _)), _) = 0), 
        d = List.AllTrue(c)
      in
        d
  )
in
  Sol
Power Query solution 5 for List the Polydivisible numbers, proposed by Luan Rodrigues:
let
  Fonte = Tabela1, 
  res = Table.SelectRows(
    Fonte, 
    each [
      a = Text.From([Number]), 
      b = List.AllTrue(
        List.Transform(
          {2 .. Text.Length(a)}, 
          (x) =>
            Int64.From(Number.From(Text.Middle(a, 0, x)) / x)
              = Number.From(Text.Middle(a, 0, x))
              / x
        )
      )
    ][b]
  )
in
  res
Power Query solution 6 for List the Polydivisible numbers, proposed by Brian Julius:
let
  Source = Excel.CurrentWorkbook(){[Name = "Table1"]}[Content], 
  AddModSum = Table.AddColumn(
    Source, 
    "ModSum", 
    each [
      a = [Number], 
      b = Number.From(Text.Length(Text.From(a))), 
      c = {2 .. b}, 
      d = List.Transform(c, each Number.Mod(Number.From(Text.Start(Text.From(a), _)), _)), 
      e = List.Sum(d)
    ][e]
  ), 
  Filter = Table.SelectColumns(Table.SelectRows(AddModSum, each ([ModSum] = 0)), "Number")
in
  Filter
Power Query solution 7 for List the Polydivisible numbers, proposed by Rafael González B.:
let
  Source = Excel.CurrentWorkbook(){0}[Content], 
  Fx_PD = (N as number) =>
    let
      a = N, 
      b = Text.From(a), 
      c = Text.ToList(b), 
      d = List.Generate(
        () => [Ext = 2, y = {}], 
        each [Ext] <= List.Count(c) + 1, 
        each [
          Ext = [Ext] + 1, 
          y = 
            let
              aa = List.FirstN(c, [Ext]), 
              bb = Text.Combine(aa), 
              cc = Text.Split(bb, "")
            in
              cc
        ], 
        each [y]{0}
      ), 
      e = 
        let
          o = List.RemoveFirstN(d), 
          p = List.Transform(
            o, 
            each 
              let
                p1 = Number.From(_), 
                p2 = Text.Length(_), 
                p3 = Number.Mod(p1, p2) = 0
              in
                p3
          )
        in
          p
    in
      List.AllTrue(e), 
  Add = Table.AddColumn(Source, "Check", each Fx_PD([Number])), 
  Ans = Table.SelectRows(Add, each [Check])[[Number]]
in
  Ans

Solving the challenge of List the Polydivisible numbers with Excel

Excel solution 1 for List the Polydivisible numbers, proposed by Bo Rydobon 🇹🇭:
=TOCOL(
    MAP(
        A2:A10,
        LAMBDA(
            n,
            LET(
                s,
                SEQUENCE(
                    LEN(
                        n
                    )
                ),
                d,
                LEFT(
                    n,
                    s
                )/s,
                n/AND(
                    INT(
                        d
                    )=d
                )
            )
        )
    ),
    3
)
Excel solution 2 for List the Polydivisible numbers, proposed by Rick Rothstein:
=FILTER(
    A2:A10,
    MAP(
        A2:A10,
        LAMBDA(
            x,
            LET(
                s,
                SEQUENCE(
                    LEN(
                        x
                    )
                ),
                t,
                LEFT(
                    x,
                    s
                ),
                SUM(
                    t-s*INT(
                        t/s
                    )
                )=0
            )
        )
    )
)
Excel solution 3 for List the Polydivisible numbers, proposed by John V.:
=TOCOL(
    MAP(
        A2:A10,
        LAMBDA(
            x,
            LET(
                s,
                SEQUENCE(
                    LEN(
                        x
                    )
                ),
                n,
                LEFT(
                    x,
                    s
                )/s,
                x/AND(
                    n=INT(
                        n
                    )
                )
            )
        )
    ),
    2
)
Excel solution 4 for List the Polydivisible numbers, proposed by محمد حلمي:
=TOCOL(
    MAP(
        A2:A10,
        LAMBDA(
            a,
            LET(
                s,
                SEQUENCE(
                    LEN(
                        a
                    )-1,
                    ,
                    2
                ),
                i,
                LEFT(
                    a,
                    s
                )/s,
                a/AND(
                    INT(
                        i
                    )=i
                )
            )
        )
    ),
    2
)
Excel solution 5 for List the Polydivisible numbers, proposed by Kris Jaganah:
=TOCOL(MAP(A2:A10,
    LAMBDA(x,
    LET(a,
    SEQUENCE(
        LEN(
            x
        )-1,
        ,
        LEN(
            x
        ),
        -1
    ),
    b,
    MID(
        x,
        1,
        a
    )/a,
    x/MIN(--(INT(
        b
    )=b))))),
    3)
Excel solution 6 for List the Polydivisible numbers, proposed by Timothée BLIOT:
=FILTER(A2:A10,
    MAP(A2:A10,
    LAMBDA(z,
    SUM(MAP(SEQUENCE(
        LEN(
            z
        )-1,
        ,
        2
    ),
    LAMBDA(x,
    LET(A,
    MID(
        z,
        1,
        x
    )*1,
    --(A=QUOTIENT(
        A,
        x
    )*x)))))=LEN(
            z
        )-1)))
Excel solution 7 for List the Polydivisible numbers, proposed by Hussein SATOUR:
=FILTER(A2:A10,
     MAP(A2:A10,
     LAMBDA(x,
     LET(
a,
     SEQUENCE(
         LEN(
             x
         )-1,
         ,
         2
     ),
     b,
     MID(
         x,
          1,
          a
     )/a,
     
SUM((b<>INT(
    b
))*1)=0))))
Excel solution 8 for List the Polydivisible numbers, proposed by Sunny Baggu:
=TOCOL(
    
     A2:A10 * 1 /
     MAP(
         
          A2:A10,
         
          LAMBDA(
              x,
              
               LET(
                   
                    _s,
                    SEQUENCE(
                        LEN(
                            x
                        )
                    ),
                   
                    _val,
                    LEFT(
                        x,
                         _s
                    ) / _s,
                   
                    AND(
                        _val - ROUND(
                            _val,
                             0
                        ) = 0
                    )
                    
               )
               
          )
          
     ),
    
     3
    
)
Excel solution 9 for List the Polydivisible numbers, proposed by LEONARD OCHEA 🇷🇴:
=TOCOL(MAP(A2:A10,LAMBDA(a,LET(s,SEQUENCE(LEN(a)),d,LEFT(a,s)/s,a/AND(d=INT(d))))),3)
Excel solution 10 for List the Polydivisible numbers, proposed by Abdallah Ally:
=FILTER(
    A2:A10,
    BYROW(
        A2:A10,
        LAMBDA(
            x,
            LET(
                a,
                x,
                b,
                SEQUENCE(
                    LEN(
                        a
                    )
                ),
                AND(
                    IFERROR(
                        MOD(
                            LEFT(
                                a,
                                b
                            ),
                            b
                        ),
                        0
                    )=0
                )
            )
        )
    )
)
Excel solution 11 for List the Polydivisible numbers, proposed by 🇵🇪 Ned Navarrete C.:
=FILTER(
    A2:A10,
    
     MAP(
         A2:A10,
         
          LAMBDA(
              f,
              LET(
                  
                   _a,
                  SEQUENCE(
                      ,
                      LEN(
                          f
                      )-1,
                      2
                  ),
                  
                   _b,
                  MID(
                      f,
                      1,
                      _a
                  ),
                  
                   _c,
                  _b/_a,
                  
                   AND(
                       _c=INT(
                           _c
                       )
                   )
                   
              )
               
          )
          
     )
    
)
Excel solution 12 for List the Polydivisible numbers, proposed by Charles Roldan:
=LET(M,
     LAMBDA(
         g,
          g(
              g
          )
     ),
     Mp,
     LAMBDA(
         g,
          LAMBDA(
              x,
               MAP(
                   x,
                    g
               )
          )
     ),
     Fl,
     LAMBDA(
         g,
          LAMBDA(
              x,
               FILTER(
                   x,
                    g(
                        x
                    )
               )
          )
     ),
     _MOD,
     LAMBDA(
         n,
         d,
          n - d * INT(
              n / d
          )
     ),
     f,
     M(LAMBDA(g,
     LAMBDA(x,
     LET(l,
     LEN(
                        x
                    ),
     IF(l = 0,
     TRUE,
     IF(_MOD(
         x,
          l
     ) = 0,
     g(
              g
          )(LEFT(
              x,
               l - 1
          )))))))),
     Fl(
         Mp(
             f
         )
     ))(A2:A10)
Excel solution 13 for List the Polydivisible numbers, proposed by Julien Lacaze:
=FILTER(
    A2:A10,
    MAP(
        A2:A10,
        LAMBDA(
            d,
            
            LET(
                s,
                SEQUENCE(
                    LEN(
                        d
                    )-1,
                    ,
                    2
                ),
                
                t,
                --LEFT(
                    d,
                    s
                )/s,
                
                AND(
                    t=INT(
                        t
                    )
                )
            )
        )
    )
)
Excel solution 14 for List the Polydivisible numbers, proposed by Pieter de Bruijn:
=LET(a,
    A2:A10,
    s,
    SEQUENCE(
        ,
        15,
        2
    ),
    n,
    MID(
        a,
        1,
        s
    ),
    FILTER(a,
    MMULT(--ISNUMBER(FIND(".",
    n/s*(LEN(
        n
    )>=s),
    1)),
    TOCOL(
        s
    )^0)=0))
or 
=LET(a,
    A2:A10,
    s,
    COLUMN(
        B:P
    ),
    n,
    LEFT(
        a,
        s
    ),
    FILTER(a,
    MMULT((n/s<>INT(
        n/s
    ))*(s<=LEN(
        a
    )),
    TOCOL(
        s^0
    ))=0))
Excel solution 15 for List the Polydivisible numbers, proposed by Giorgi Goderdzishvili:
=TOCOL(MAP(A2:A10,
    LAMBDA(x,
    LET(
nm,
    x,
    
ln,
     LEN(
         nm
     ),
    
chck,
     MID(
         nm,
         1,
         SEQUENCE(
             ,
             ln-1,
             2
         )
     )/SEQUENCE(
             ,
             ln-1,
             2
         ),
    
nm/(SUM(--(chck=INT(
    chck
)))=(ln-1))))),
    3)
Excel solution 16 for List the Polydivisible numbers, proposed by Abdelrahman Omer, MBA, PMP:
=TOCOL(MAP(A2:A10,LAMBDA(a,LET(b,LEFT(a,SEQUENCE(LEN(a))),c,SEQUENCE(LEN(a)),FILTER(a,SUM(INT(b/c)-b/c)=0)))),2)
Excel solution 17 for List the Polydivisible numbers, proposed by Daniel Garzia:
=TOCOL(
    MAP(
        A2:A10,
        LAMBDA(
            x,
            LET(
                s,
                SEQUENCE(
                    LEN(
                        &x
                    )-1,
                    ,
                    2
                ),
                d,
                MID(
                    x,
                    1,
                    s
                )/s,
                x/AND(
                    d-INT(
                        d
                    )=0
                )
            )
        )
    ),
    3
)
Excel solution 18 for List the Polydivisible numbers, proposed by Andres Rojas Moncada:
=FILTRAR(
    A2:A10,
    MAP(
        A2:A10,
        LAMBDA(
            _num,
            
            REDUCE(
                1,
                SECUENCIA(
                    LARGO(
                        _num
                    )
                ),
                LAMBDA(
                    _acu,
                    _val,
                    
                    LET(
                        _div,
                        EXTRAE(
                            _num,
                            1,
                            _val
                        )/_val,
                        Y(
                            _acu,
                            ENTERO(
                                _div
                            )=_div
                        )
                    )
                )
            )
        )
    )
)
Excel solution 19 for List the Polydivisible numbers, proposed by Jeff Blakley:
=FILTER(
    A2:A10,
     MAP(
         A2:A10,
          LAMBDA(
              x,
               LET(
                   s,
                    SEQUENCE(
                        LEN(
                            x
                        )-1,
                        ,
                        2
                    ),
                    d,
                    LEFT(
                        x,
                        s
                    )/s,
                    SUM(
                        d
                    )=SUM(
                        INT(
                        d
                    )
                    )
               )
          )
     )
)

Solving the challenge of List the Polydivisible numbers with Python in Excel

Python in Excel solution 1 for List the Polydivisible numbers, proposed by Bo Rydobon 🇹🇭:
[n for n in xl("A2:A10")[0] if all(int(str(n)[:i+1])%(i+1)==0 for i,m in enumerate(str(n)))]
Python in Excel solution 2 for List the Polydivisible numbers, proposed by John V.:
Hi everyone!
One (Python) option could be:
Blessings!
                    
                  

Solving the challenge of List the Polydivisible numbers with R

R solution 1 for List the Polydivisible numbers, proposed by Konrad Gryczan, PhD:
library(tidyverse)
library(readxl)
input = read_excel("Polydivisible Numbers.xlsx", range = "A1:A10")
test= read_excel("Polydivisible Numbers.xlsx", range = "B1:B6")
is_polydivisible = function(number) {
 digits = str_split(number, "")[[1]]
 
 map_lgl(1:length(digits), function(x)
 {
 num = as.numeric(paste0(digits[1:x], collapse = "")) 
 num %% x == 0 
 }) %>%
 all()
}
result = input %>%
 mutate(check = map_lgl(Number, is_polydivisible)) %>% 
 filter(check) %>%
 select(`Expected Answer` = Number)
identical(test, result)
#> [1] TRUE
                    
                  

&&

Leave a Reply