Read p.153 to understand how to use the primitives word, last, and butlast.
Here is a recursive procedure that inverts the characters of a word.
to invertword :m if emptyp :m [output "] output word last :m invertword butlast :m end print invertword "abcde edcba |
A palindrome is a word, or a phrase that can be read in both sense (Examples: A man, a plan, a canal: Panama ...).
# test if the word :m is a palindrome to palindrom :m if :m=invertword :m [output true] [output false] end |
Finally, this little kind program, (Thanks Olivier SC):
to palin :n if palindrom :n [print :n stop] print (list :n "PLUS invertword :n "EQUAL sum :n invertword :n) palin :n + invertword :n end palin 78 78 PLUS 87 EQUAL 165 165 PLUS 561 EQUAL 726 726 PLUS 627 EQUAL 1353 1353 PLUS 3531 EQUAL 4884 4884 |