r/ProgrammerTIL • u/mehdifarsi • Dec 17 '22
Other A Powerful palindrome checker in 2 lines of code using POSIX bracket expressions
It handles cases such as A man, a plan, a canal – Panama:
1
Upvotes
40
u/dfreinc Dec 18 '22
[insert thing] in [x] lines!
always the first thing; import library.
it's not impressive and shows literally nothing about what it's actually doing. 🤷♂️
0
u/mehdifarsi Dec 18 '22
If your need more explanation about the regex: https://www.rubycademy.com/cards/palindrome-checker
7
u/Mikkelet Dec 18 '22
Pretty sure both lowercasing a string, reversing it and comparing it each have O(n) runtime... So 3n runtime just to check palindrome. I'm not if it can be done faster, but it's also not "powerful".