Check if a String is a Palindrome in Larzscript
Detect whether a string reads the same forwards and backwards, ignoring case, spaces and punctuation.
str.is_palindrome() lowercases and strips non-alphanumeric characters before comparing - so real sentences like "A man, a plan, a canal: Panama" work, not just single words.
larzscript pkg install str
Code
import "str" as str_
print(str_.is_palindrome("A man a plan a canal Panama"))
print(str_.is_palindrome("racecar"))
print(str_.is_palindrome("Larzscript"))Output
true true false
Related
larzstrWord-game string helpers→FizzBuzz in LarzscriptThe classic interview warm-up: print 1 to N, but Fizz for multiples of 3, Buzz for multiples of 5, FizzBuzz for both.→Reverse a String in LarzscriptFlip a string end to end - one of the smallest real string algorithms, and a good first look at the str package.→Sort a List in LarzscriptSort a list of numbers - and see exactly how many comparisons and swaps each algorithm actually costs.→