fork download
  1. ; two palindrome exercises
  2.  
  3. (define (number-palindrome? n)
  4. (let loop ((x n) (z 0))
  5. (if (zero? x) (= n z)
  6. (let ((q (quotient x 10)) (r (remainder x 10)))
  7. (loop q (+ (* z 10) r))))))
  8.  
  9. (display (number-palindrome? 123454321)) (newline)
  10. (display (number-palindrome? 123456789)) (newline)
  11.  
  12. (define (mappend f . xss) (apply append (apply map f xss)))
  13.  
  14. (define (string-palindrome? xs)
  15. (let ((chars (mappend string->list xs)))
  16. (equal? chars (reverse chars))))
  17.  
  18. (define x '("a" "bcd" "ef" "g" "f" "ed" "c" "ba"))
  19. (display (string-palindrome? x)) (newline)
  20. (display (string-palindrome? (cdr x))) (newline)
Success #stdin #stdout 0.01s 42848KB
stdin
Standard input is empty
stdout
#t
#f
#t
#f