APALINDROME

=APALINDROME(a)

a
array, 1D vertical array

checks an array for palindromes

Xlambda

Well-known Member
Joined
Mar 8, 2021
Messages
837
Office Version
  1. 365
Platform
  1. Windows
APALINDROME checks an array for palindromes. calls AKEEP , AREVERSE
Excel Formula:
=LAMBDA(a,
    LET(x,AKEEP(a,T_CHARS(,2,),),y,AREVERSE(x),
       IF(x=y,"Yes !","No !")
    )
)
LAMBDA 7.0.xlsx
ABCDE
1check palindrome sentences=APALINDROME(A2:A6)
2¡ Murder for a jar of red rum !Yes !
3Borrow or rob?Yes !
4Eva, can I see bees in a cave?Yes !
5Yo, banana boy!Yes !
6Radar is radar !No !
7
APALINDROME post
Cell Formulas
RangeFormula
C1C1=FORMULATEXT(C2)
C2:C6C2=APALINDROME(A2:A6)
Dynamic array formulas.
 
Upvote 0
How do you do this? Everytime I think of something, I check here minutes later you post the exact LAMBDA. I was just thinking of a PALINDROME LAMBDA. Great work
 
Hi, thanks, does not matter, if you have a different approach you should post. Only time, and other users will tell which one will get traction.
On 98% of the cases when I write a formula, I am stuck to the first idea that comes to my mind, and this could make me blind to other better solutions, solutions that other eyes can see, and so on.
So, I encourage you to post, you are a very good exceler. ✌?
 
I've been playing around with making recursive functions.

Came up with a way to do a PALINDROME function recursively.

PALINDROME
Excel Formula:
=LAMBDA(
    text,
        IF(
            AOR(LEN(text),"0,1"),
                TRUE,
                IF(
                    LEFT(text)=RIGHT(text),
                        PALINDROME(MID(text,2,LEN(text)-2)),
                        FALSE
                )
            )
)

PALINDROME
JK
21racecarTRUE
22abbaTRUE
23monkeyFALSE
Sheet5
Cell Formulas
RangeFormula
K21:K23K21=PALINDROME(J21)


Helper function AOR, checks to see if any value in comma separated string is equal to value.

AOR
Excel Formula:
=LAMBDA(
    val,oStr,
        LET(
            ts,TEXTSPLIT(oStr,","),
            OR(
                MAP(
                    ts,
                    LAMBDA(
                        x,
                        IFERROR(
                            x+0=val,
                            x=val
                        )
                    )
                )
            )
        )
)
 
Cool that you play with recursive functions !! ✌️
In this case, my function was designed to work not only with single words in single cells, but with an array vector of sentences with random punctuation marks.
Anyhow, if I would have designed it for single words only palindrome check, I would have used one of these 2:
ISPLNDRM(x) - non recursive
Excel Formula:
=LAMBDA(x,LET(l,LEN(x),s,SEQUENCE(l),AND(MID(x,s,1)=MID(x,l-s+1,1))))
PLNDRM(x) - recursive (does not call any helper function)
Excel Formula:
=LAMBDA(x,LET(l,LEN(x),IF(l<2,TRUE,IF(LEFT(x,1)=RIGHT(x,1),PLNDRM(MID(x,2,l-2)),FALSE))))
Book1.xlsx
ABCDEFGHIJKL
1Wrong results for sentences
2lrobbo314's fction
3¡ Murder for a jar of red rum !FALSE=PALINDROME(A3)
4Borrow or rob?FALSE=PALINDROME(A4)
5Eva, can I see bees in a cave?FALSE=PALINDROME(A5)
6Yo, banana boy!FALSE=PALINDROME(A6)
7
8Single cells, single words
9non recursiverecursive
10
11abaTRUE=ISPLNDRM(A11)TRUE=PLNDRM(A11)
12abbaTRUE=ISPLNDRM(A12)TRUE=PLNDRM(A12)
13racecarTRUE=ISPLNDRM(A13)TRUE=PLNDRM(A13)
14A12321ATRUE=ISPLNDRM(A14)TRUE=PLNDRM(A14)
15xyzyxTRUE=ISPLNDRM(A15)TRUE=PLNDRM(A15)
16LevelTRUE=ISPLNDRM(A16)TRUE=PLNDRM(A16)
17CivicTRUE=ISPLNDRM(A17)TRUE=PLNDRM(A17)
18KayakTRUE=ISPLNDRM(A18)TRUE=PLNDRM(A18)
19nopalindromeFALSE=ISPLNDRM(A19)FALSE=PLNDRM(A19)
20
21ISPLNDRM(x) =
22 =LAMBDA(x,LET(l,LEN(x),s,SEQUENCE(l),AND(MID(x,s,1)=MID(x,l-s+1,1))))
23
24PLNDRM(x) =
25 =LAMBDA(x,LET(l,LEN(x),IF(l<2,TRUE,IF(LEFT(x,1)=RIGHT(x,1),PLNDRM(MID(x,2,l-2)),FALSE))))
26
Sheet1
Cell Formulas
RangeFormula
C3:C6C3=FORMULATEXT(B3:B6)
B3:B6B3=PALINDROME(A3)
C11:C19,F11:F19C11=FORMULATEXT(B11:B19)
B11:B19B11=ISPLNDRM(A11)
E11:E19E11=PLNDRM(A11)
Dynamic array formulas.
 
Here is another way that I came up with.

Also, just for fun, I asked ChatGPT to write a palindrome function. It failed 3 times before reverting to VBA. The VBA was a 1-liner and it worked. But, I think we're safe from GPT for a while.

XPALINDROME
Excel Formula:
=LAMBDA(range,
    MAP(range,
        LAMBDA(t,
            LET(n,INT(LEN(t)/2),
            r,REVTEXT(t),
                LEFT(t,n)=LEFT(r,n))
        )
    )
)

REVTEXT
Excel Formula:
=LAMBDA(text,
    LET(n,LEN(text),
        TEXTJOIN("",,MID(text,SEQUENCE(n,,n,-1),1))
    )
)
 
Just for fun "comment" 😉: if XPALINDROME already calls r,REVTEXT(t), I don't think that comparing only half of the string, LEFT(t,n)=LEFT(r,n), will make the formula more efficient than using only t=r 😆✌️
Excel Formula:
=LAMBDA(range,
    MAP(range,
        LAMBDA(t,
            LET(r,REVTEXT(t),
                t=r)
        )
    )
)
 
I realized that after I posted it, lol. Was kinda hoping you wouldn't notice.
 
I realized that after I posted it, lol. Was kinda hoping you wouldn't notice.
😆✌️. Lol.
Anyhow, an updated 2023 APLNDRM(ar) function, Array Palindrome: checks an array of sentences for palindromes. Does not call any other function.
Excel Formula:
=LAMBDA(ar,
    LET(
        a, CONCAT(REDUCE(UPPER(ar), CHAR(SEQUENCE(26, , 65)), LAMBDA(v, i, SUBSTITUTE(v, i, "")))),
        r, REDUCE(ar, UNIQUE(MID(a, SEQUENCE(LEN(a)), 1)), LAMBDA(v, i, SUBSTITUTE(v, i, ""))),
        p, LAMBDA(x, LET(l, LEN(x), s, SEQUENCE(l), AND(MID(x, s, 1) = MID(x, l - s + 1, 1)))),
        MAP(r, p)
    )
)
Cool palindrome sentences from: 190+ Fun, Interesting Palindrome Words
Let's check them all.
Book1.xlsx
ABCDEFGH
1
2=TEXTSPLIT(A3,,CHAR(10))=APLNDRM(C3#)
3Dammit, I’m mad! A man, a plan, a canal – Panama. Don’t nod. No lemon, no melon! Bird rib. Go hang a salami, I’m a lasagna hog. Do geese see God? Mr. Owl ate my metal worm. Was it a car or a cat I saw? Borrow or rob? I did, did I? Evil did I dwell; lewd I did live. Rats live on no evil star. My gym. No devil lived on. Ma is a nun, as I am. A nut for a jar of tuna. Yo, banana boy! Red rum, sir, is murder. Madam, in Eden, I’m Adam. Taco cat. Al lets Della call Ed “Stella.” Amore, Roma. As I pee sir, I see Pisa! Dennis sinned. Step on no pets. UFO tofu? But sad Eva saved a stub. No trace; not one carton. No, sir, prefer prison. Do nine men interpret? “Nine men,” I nod. Bombard a drab mob. No “x” in “Nixon”. Ma is as selfless as I am. Gateman sees name, garageman sees name tag. A Toyota. Race fast, safe car. A Toyota. Top spot. Drab as a fool, aloof as a bard. Now I see bees, I won. Was it a cat I saw? Cigar? Toss it in a can. It is so tragic. Never odd or even Evade me, Dave. Race fast, safe car. Flee to me, remote elf. Naomi, did I moan? Ed, I saw Harpo Marx ram Oprah W. aside. Campus Motto: Bottoms up, Mac! Name now one man. Doc, note I dissent: a fast never prevents a fatness. I diet on cod. Rise to vote, sir. Senile felines. Murder for a jar of red rum. Dogma? I am God. Won’t lovers revolt now? Saw tide rose? So red it was. Stack cats. Did I draw Della too tall, Edward? I did? A Santa dog lived as a devil god at NASA. Meet animals; laminate ’em. Oozy rat in a sanitary zoo. So many dynamos! A tin mug for a jar of gum, Nita. Madam I’m Adam. Able was I, ere I saw Elba. Eva, can I see bees in a cave? Lived on Decaf; faced no Devil. Stella won no wallets. Cain: a maniac. Lonely Tylenol. No lemon, no melon.Dammit, I’m mad!TRUEall palindromes?
4A man, a plan, a canal – Panama.TRUE=AND(E3#)
5Don’t nod.TRUETRUE
6No lemon, no melon!TRUE
7Bird rib.TRUE
8Go hang a salami, I’m a lasagna hog.TRUE
9Do geese see God?TRUE
10Mr. Owl ate my metal worm.TRUE
11Was it a car or a cat I saw?TRUE
12Borrow or rob?TRUE
13I did, did I?TRUE
14Evil did I dwell; lewd I did live.TRUE
15Rats live on no evil star.TRUE
16My gym.TRUE
17No devil lived on.TRUE
18Ma is a nun, as I am.TRUE
19A nut for a jar of tuna.TRUE
20Yo, banana boy!TRUE
21Red rum, sir, is murder.TRUE
22Madam, in Eden, I’m Adam.TRUE
23Taco cat.TRUE
24Al lets Della call Ed “Stella.”TRUE
25Amore, Roma.TRUE
26As I pee sir, I see Pisa!TRUE
27Dennis sinned.TRUE
28Step on no pets.TRUE
29UFO tofu?TRUE
30But sad Eva saved a stub.TRUE
31No trace; not one carton.TRUE
32No, sir, prefer prison.TRUE
33Do nine men interpret? “Nine men,” I nod.TRUE
34Bombard a drab mob.TRUE
35No “x” in “Nixon”.TRUE
36Ma is as selfless as I am.TRUE
37Gateman sees name, garageman sees name tag.TRUE
38A Toyota. Race fast, safe car. A Toyota.TRUE
39Top spot.TRUE
40Drab as a fool, aloof as a bard.TRUE
41Now I see bees, I won.TRUE
42Was it a cat I saw?TRUE
43Cigar? Toss it in a can. It is so tragic.TRUE
44Never odd or evenTRUE
45Evade me, Dave.TRUE
46Race fast, safe car.TRUE
47Flee to me, remote elf.TRUE
48Naomi, did I moan?TRUE
49Ed, I saw Harpo Marx ram Oprah W. aside.TRUE
50Campus Motto: Bottoms up, Mac!TRUE
51Name now one man.TRUE
52Doc, note I dissent: a fast never prevents a fatness. I diet on cod.TRUE
53Rise to vote, sir.TRUE
54Senile felines.TRUE
55Murder for a jar of red rum.TRUE
56Dogma? I am God.TRUE
57Won’t lovers revolt now?TRUE
58Saw tide rose? So red it was.TRUE
59Stack cats.TRUE
60Did I draw Della too tall, Edward? I did?TRUE
61A Santa dog lived as a devil god at NASA.TRUE
62Meet animals; laminate ’em.TRUE
63Oozy rat in a sanitary zoo.TRUE
64So many dynamos!TRUE
65A tin mug for a jar of gum, Nita.TRUE
66Madam I’m Adam.TRUE
67Able was I, ere I saw Elba.TRUE
68Eva, can I see bees in a cave?TRUE
69Lived on Decaf; faced no Devil.TRUE
70Stella won no wallets.TRUE
71Cain: a maniac.TRUE
72Lonely Tylenol.TRUE
73No lemon, no melon.TRUE
74
Sheet2
Cell Formulas
RangeFormula
E2,G4,C2E2=FORMULATEXT(E3)
C3:C73C3=TEXTSPLIT(A3,,CHAR(10))
E3:E73E3=APLNDRM(C3#)
G5G5=AND(E3#)
Dynamic array formulas.
 
Book1.xlsx
A
1The Longest Palindrome Examples
2
3Are we not pure? “No sir!” Panama’s moody Noriega brags. “It is garbage!” Irony dooms a man; a prisoner up to new era.
4T. Eliot, top bard, notes putrid tang emanating, is sad. I’d assign it a name: gnat dirt upset on drab pot-toilet.
5Embargos are macabre. Sad Nell, listen O, not to no nets. I’ll lend a Serb a camera, so grab me.
6Er, go on, trap Steven in, I say. Me oh my. Nor can an “air” bee sew. We see, Brian. An acronym? Hoe my asinine vet’s part? No, ogre.
7Are we not pure? “No sir!” Panama’s moody Noriega brags. “It is garbage!” Irony dooms a man; a prisoner up to new era.
8“Son, say a papaya.” “Papayas.” “No ‘s.'”
9Dennis, Nell, Edna, Leon, Nedra, Anita, Rolf, Nora, Alice, Carol, Leo, Jane, Reed, Dena, Dale, Basil, Rae, Penny, Lana, Dave, Denny, Lena, Ida, Bernadette, Ben, Ray, Lila, Nina, Jo, Ira, Mara, Sara, Mario, Jan, Ina, Lily, Arne, Bette, Dan, Reba, Diane, Lynn, Ed, Eva, Dana, Lynne, Pearl, Isabel, Ada, Ned, Dee, Rena, Joel, Lora, Cecil, Aaron, Flora, Tina, Arden, Noel, and Ellen sinned.
10
11=APLNDRM(A3:A9)
12TRUE
13TRUE
14TRUE
15TRUE
16TRUE
17TRUE
18TRUE
19
Sheet3
Cell Formulas
RangeFormula
A11A11=FORMULATEXT(A12)
A12:A18A12=APLNDRM(A3:A9)
Dynamic array formulas.
 

Forum statistics

Threads
1,216,503
Messages
6,131,022
Members
449,616
Latest member
PsychoCube

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top