Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Scheme/Racket

Name: Anonymous 2012-11-27 17:53

/prog/, How do you do this shit?

Write a Scheme function palindrome-strings that consumes a leaf-labelled tree lt, where all labels are strings, and produces a list of the strings in lt that are palindromes. Any order is acceptable. (a string is a palindrome if its reverse is identical to it, for example: “wow” “abcddcba” ). Some examples follow:

(define myllt '( ("hat" ("cat" "dog" "wow") ("abcba" "Wow" "nice") ("halah" "lol")) ("was saw" "end")))
(define myllt2 '(("hat" ("cat" "dog" "woww") ("abcbda" "nice") ("hala" "lolo")) ("was see" "end")))
(define myllt3 '( "aaa" ("hat" ("cat" "dog" "woww") ("hala" "baab")) ("was see" "end")))
(define res1 '("wow" "abcba" "halah" "lol" "was saw"))
(palindrome-strings myllt) => res1
(palindrome-strings myllt2) => empty
(palindrome-strings myllt3) => (list "aaa" "baab")



;; A leaf-labelled tree llt is one of the following:
;; empty
;; (cons l1 l2) where
;; l1 is a non-empty llt and
;; l2 is a llt
;; (cons v l) where
;; v is a string and
;; l is a llt

Name: Anonymous 2012-11-27 18:05

(defun palindrome (str)
       (when (string str)
         (if (equal str (reverse str))
         t)))

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List