Home » Find Reverse-Divisible Non-Palindromes

Find Reverse-Divisible Non-Palindromes

Reverse a number. If this new number is perfectly divisible by original number and both numbers are not Palindrome numbers, then list that number. (We are excluding Palindrome numbers as reversed number is equal to original number itself) List first 12 such numbers. Minimum digits should be 2. Example: 2178. Reversed number is 8712. 8712 / 2178 = 4 and these two numbers are not Palindrome numbers.

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

Solving the challenge of Find Reverse-Divisible Non-Palindromes with Power Query

Power Query solution 1 for Find Reverse-Divisible Non-Palindromes, proposed by Aditya Kumar Darak 🇮🇳:
let
  Generate = List.Generate(
    () => [a = 1, c = 0], 
    each [c] < 13, 
    each [a = [a] * 10 + 1, b = {a * 99, a * 99 * 2}, c = [c] + 2], 
    each [b]
  ), 
  Return = List.Combine(List.Skip(Generate))
in
  Return
Power Query solution 2 for Find Reverse-Divisible Non-Palindromes, proposed by Ramiro Ayala Chávez:
let
  a   = {10 .. 22000000}, 
  S   = List.Select, 
  T   = Text.From, 
  R   = Text.Reverse, 
  b   = S(a, each Number.Mod(Number.From(R(T(_))), _) = 0), 
  c   = S(b, each T(_) <> R(T(_))), 
  Sol = Table.FromColumns({c}, {"Expected Answer"})
in
  Sol

Solving the challenge of Find Reverse-Divisible Non-Palindromes with Excel

Excel solution 1 for Find Reverse-Divisible Non-Palindromes, proposed by Bo Rydobon 🇹🇭:
=LET(
    s,
    SEQUENCE(
        5,
        ,
        2
    ),
    n,
    SORT(
        99*TOCOL(
            TOCOL(
                REPLACE(
                    REPT(
                        1,
                        s
                    ),
                    s/2+1,
                    0,
                    {"",
                    "00"}
                )
            )*{1,
            2}
        )
    ),
    d,
    BYROW(
        MID(
            n,
            9-SEQUENCE(
                ,
                8
            ),
            1
        ),
        CONCAT
    )/n,
    
    FILTER(
        n,
        INT(
            d
        )=d
    )
)

=SORT(
    --TOCOL(
        VSTACK(
            REPT(
                1,
                SEQUENCE(
        5,
        ,
        2
    )
            ),
            110011
        )*{1,
        2}*99
    )
)
Excel solution 2 for Find Reverse-Divisible Non-Palindromes, proposed by Rick Rothstein:
=LET(
    y,
    1089,
    z,
    2178,
    f,
    LAMBDA(
        n,
        SCAN(
            "",
            SEQUENCE(
                5,
                ,
                0
            ),
            LAMBDA(
                a,
                x,
                LEFT(
                    n,
                    2
                )&REPT(
                    9,
                    x
                )&RIGHT(
                    n,
                    2
                )
            )
        )
    ),
    v,
    VSTACK(
        f(
            y
        ),
        f(
            z
        ),
        y&y,
        z&z
    ),
    SORT(
        0+v
    )
)

Note 1: Mathematically,
     the only solutions for this type of number (known as palintiples)
Excel solution 3 for Find Reverse-Divisible Non-Palindromes, proposed by Rick Rothstein:
=LET(
    y,
    1089,
    z,
    2178,
    f,
    LAMBDA(
        n,
        SCAN(
            "",
            SEQUENCE(
                12,
                ,
                0
            ),
            LAMBDA(
                a,
                x,
                LEFT(
                    n,
                    2
                )&REPT(
                    9,
                    x
                )&RIGHT(
                    n,
                    2
                )
            )
        )
    ),
    g,
    LAMBDA(
        n,
        SCAN(
            "",
            SEQUENCE(
                12,
                ,
                0
            ),
            LAMBDA(
                a,
                x,
                n&REPT(
                    0,
                    x
                )&n
            )
        )
    ),
    v,
    VSTACK(
        f(
            y
        ),
        f(
            z
        ),
        g(
            y
        ),
        g(
            z
        )
    ),
    TAKE(
        SORT(
            0+v
        ),
        40
    )
)
Excel solution 4 for Find Reverse-Divisible Non-Palindromes, proposed by John V.:
=LET(s,
    99*ROW(
        1:220022
    ),
    r,
    BYROW(
        MID(
            s,
            9-COLUMN(
                A:H
            ),
            1
        ),
        CONCAT
    )/s,
    TOCOL(s/(r>1)/(r=INT(
        r
    )),
    2))

✅=SORT(
    TOCOL(
        {1,
        2}*VSTACK(
            10891089,
            REPLACE(
                1089,
                3,
                ,
                REPT(
                    9,
                    ROW(
                        1:5
                    )-1
                )
            )
        )
    )
)
Excel solution 5 for Find Reverse-Divisible Non-Palindromes, proposed by Kris Jaganah:
=LET(a,
    SEQUENCE(
        1000000,
        10,
        9,
        9
    ),
    b,
    --MAP(
        a,
        LAMBDA(
            x,
            CONCAT(
                MID(
                    x,
                    SEQUENCE(
                        15,
                        ,
                        15,
                        -1
                    ),
                    1
                )
            )
        )
    ),
    TOCOL(a/((b/a=INT(
        b/a
    ))*(a<>b)),
    3))
Excel solution 6 for Find Reverse-Divisible Non-Palindromes, proposed by Julian Poeltl:
=LET(
    S,
    SEQUENCE(
        230000,
        ,
        198,
        99
    ),
    R,
    MAP(
        S,
        LAMBDA(
            A,
            E_ReverseString(
                A
            )
        )
    ),
    N,
    IF(
        MOD(
            R,
            S
        )=0,
        IF(
            MAP(
                S,
                LAMBDA(
                    A,
                    E_ISPalindrome(
                A
            )
                )
            )=FALSE,
            IF(
                MAP(
                    R,
                    LAMBDA(
                    A,
                    E_ISPalindrome(
                A
            )
                )
                )=FALSE,
                S,
                ""
            ),
            ""
        ),
        ""
    ),
    FILTER(
        N,
        N<>""
    )
)
Pre-programmed Lambdas:
E_ReverseString:
=LAMBDA(
    String,
    CONCAT(
        MID(
            String,
            SEQUENCE(
                ,
                LEN(
                    String
                ),
                LEN(
                    String
                ),
                -1
            ),
            1
        )
    )
)
E_ISPalindrome:
=LAMBDA(PAL?,
    LET(Text,
    PAL?,
    L,
    LEFT(Text,
    ROUNDUP((LEN(
        Text
    )-1)/2,
    0)),
    R,
    CONCAT(L_ReverseHorizontalArray(MID(RIGHT(Text,
    ROUNDUP((LEN(
        Text
    )-1)/2,
    0)),
    SEQUENCE(,
    LEN(RIGHT(Text,
    ROUNDUP((LEN(
        Text
    )-1)/2,
    0)))),
    1))),
    RES,
    L=R,
    RES))
L_ReverseHorizontalArray:
=LAMBDA(
    Array,
    TRANSPOSE(
        INDEX(
            TRANSPOSE(
                Array
            ),
            SEQUENCE(
                ROWS(
                    TRANSPOSE(
                Array
            )
                ),
                1,
                ROWS(
                    TRANSPOSE(
                Array
            )
                ),
                -1
            ),
            SEQUENCE(
                1,
                COLUMNS(
                    TRANSPOSE(
                Array
            )
                )
            )
        )
    )
)
Excel solution 7 for Find Reverse-Divisible Non-Palindromes, proposed by Timothée BLIOT:
=LET(S,
    SEQUENCE(
        10^5
    ),
    A,
    VSTACK(
        S*99,
        S*1089
    ),
    B,
    MAP(
        A,
        LAMBDA(
            x,
            --CONCAT(
                MID(
                    x,
                    LEN(
                        x
                    )+1-SEQUENCE(
                        LEN(
                        x
                    )
                    ),
                    1
                )
            )
        )
    ),
    UNIQUE(SORT(FILTER(A,
    (INT(
        B/A
    )=B/A)*(B<>A)))))
Excel solution 8 for Find Reverse-Divisible Non-Palindromes, proposed by Sunny Baggu:
=LET(
 _s,
     SEQUENCE(
         22000000 / 100,
          100,
          1000
     ),
    
 _e1,
     LAMBDA(
         x,
         
          LET(
              
               _a,
               x,
              
               _b,
               CONCAT(
                   
                    MID(
                        x,
                         LEN(
                             x
                         ) + 1 - SEQUENCE(
                             LEN(
                             x
                         )
                         ),
                         1
                    )
                    
               ) + 0,
              
               AND(
                   LEN(
                       _a
                   ) > 3,
                    MOD(
                        _b,
                         x
                    ) = 0,
                    _a <> _b
               )
               
          )
          
     ),
    
 TAKE(TOCOL(IF(MAP(_s,
     LAMBDA(y,
     _e1(y))),
     _s,
     x),
     3),
     12)
)
Excel solution 9 for Find Reverse-Divisible Non-Palindromes, proposed by LEONARD OCHEA 🇷🇴:
=TOCOL(MAP(SEQUENCE(
    222220,
    ,
    11
)*99,
    LAMBDA(a,
    LET(d,
    CONCAT(
        MID(
            a,
            9-SEQUENCE(
                8
            ),
            1
        )
    )/a,
    a/(d=INT(
        d
    ))/(d>1)))),
    3)

=TOCOL(MAP(SEQUENCE(
    222222,
    ,
    99,
    99
),
    LAMBDA(a,
    LET(d,
    CONCAT(
        MID(
            a,
            9-SEQUENCE(
                8
            ),
            1
        )
    )/a,
    a/(OR(
        d={4;9}
    ))))),
    3)
Excel solution 10 for Find Reverse-Divisible Non-Palindromes, proposed by Tyler Cameron:
=LET(
    y,
    MAP(
        99*SEQUENCE(
            222000,
            ,
            10
        ),
        LAMBDA(
            x,
            LET(
                a,
                LEN(
                    x
                ),
                b,
                --CONCAT(
                    MID(
                        x,
                        SEQUENCE(
                            a,
                            ,
                            a,
                            -1
                        ),
                        1
                    )
                ),
                IF(
                    AND(
                        RIGHT(
                            x,
                            ROUNDDOWN(
                                a/2,
                                0
                            )
                        )<>RIGHT(
                            b,
                            ROUNDDOWN(
                                a/2,
                                0
                            )
                        ),
                        MOD(
                            b,
                            x
                        )=0
                    ),
                    x,
                    ""
                )
            )
        )
    ),
    FILTER(
        y,
        y<>""
    )
)

Solving the challenge of Find Reverse-Divisible Non-Palindromes with Python

Python solution 1 for Find Reverse-Divisible Non-Palindromes, proposed by Cristobal Salcedo Beltran:
Code:____________________________
def is_palindrome(number):
 
 return str(number) == str(number)[::-1]
valid_numbers = []
current_number = 10 
while len(valid_numbers) < 12:
 reversed_number = int(str(current_number)[::-1])
 if reversed_number % current_number == 0 and not is_palindrome(current_number) and not is_palindrome(reversed_number):
 valid_numbers.append(current_number)
 current_number += 1
print("Expected Answer:")
for number in valid_numbers:
 print(number)
                    
                  
Python solution 2 for Find Reverse-Divisible Non-Palindromes, proposed by Cristobal Salcedo Beltran:
code______________________
from pyspark.sql import SparkSession
from pyspark.sql.functions import udf, col
from pyspark.sql.types import IntegerType, BooleanType
spark = SparkSession.builder.appName("Find Numbers").getOrCreate()
is_palindrome_udf = udf(lambda num: str(num) == str(num)[::-1], BooleanType())
reverse_number_udf = udf(lambda num: int(str(num)[::-1]), IntegerType())
numbers_df = spark.range(10, 100000000).toDF("number")
filtered_df = numbers_df.withColumn("reversed", reverse_number_udf("number")) 
 .filter(~is_palindrome_udf("number")) 
 .filter(~is_palindrome_udf("reversed")) 
 .filter(col("reversed") % col("number") == 0)
filtered_df.select("number").limit(18).show()
                    
                  

Solving the challenge of Find Reverse-Divisible Non-Palindromes with Python in Excel

Python in Excel solution 1 for Find Reverse-Divisible Non-Palindromes, proposed by Abdallah Ally:
# Assuming that these numbers do not conform to any pattern
# I used a normal looping which takes time to complete
import pandas as pd
file_path = 'Excel_Challenge_419 - Reverse Divisible & Not Palindromes.xlsx'
df = pd.read_excel(file_path)
def reverse_divisible_not_palindrome(n):
 numbers = []
 number = 10
 while len(numbers) != n:
 rev_number = int(str(number)[::-1])
 value = rev_number / number
 if value == int(value) and number != rev_number:
 numbers.append(number)
 number += 1
 return numbers
df['My Answer'] = pd.Series(reverse_divisible_not_palindrome(11))
print(df)
                    
                  
Python in Excel solution 2 for Find Reverse-Divisible Non-Palindromes, proposed by ferhat CK:
a=xl("A1:A12", headers=True)
say=[]
for i in a['Expected Answer']:
 s1=float(int(str(i)[::-1])/i)
 s2=int(int(str(i)[::-1])/i) 
 if s1==s2 and int(str(i)[::-1])!=i :
 say.append(i)
say
                    
                  

&&&

Leave a Reply