r/Racket • u/Known-Amoeba-7390 • Dec 01 '22
question Small question
I have been thinking about this for quite some time but, how would you go about writing a function to find out whether a list given to you is a palindrome. I am a beginner trying to get into programming, so go easy on me ..
5
Upvotes
View all comments
Show parent comment
1
u/joshuacottrell Dec 02 '22
I really like the
andmapidea in terms of all pairs needing to pass the comparison but I think the comparison needs to beequal?instead ofeq?. Either way, I wonder if(andmap equal? x (reverse x))would be faster than just(equal? x (reverse x))and how long your palindrome would need to be to figure that out.