Subversion Repositories programming

Rev

Rev 427 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 427 Rev 428
Line 23... Line 23...
23
(defun PALINDROME (LI)
23
(defun PALINDROME (LI)
24
  (append LI (reverse LI))
24
  (append LI (reverse LI))
25
)
25
)
26
 
26
 
27
;;; Problem 2
27
;;; Problem 2
28
 
-
 
29
; Tail-recursive helper for problem 2
-
 
30
(defun PALINDROMEP1 (L1 L2)
-
 
31
  (cond
-
 
32
    ((null L1)                 t)
-
 
33
    ((equal (car L1) (car L2)) (PALINDROMEP1 (cdr L1) (cdr L2)))
-
 
34
    (t                         nil)
-
 
35
  )
-
 
36
)
-
 
37
 
-
 
38
(defun PALINDROMEP (LI)
28
(defun PALINDROMEP (LI)
-
 
29
  ; define a local function so we can do this tail-recursively
-
 
30
  (labels ((PAL-HELP (L1 L2)
-
 
31
              (cond
-
 
32
                ((null L1) t)
-
 
33
                ((equal (car L1) (car L2)) (PAL-HELP (cdr L1) (cdr L2)))
-
 
34
                (t                        nil)
-
 
35
              )
-
 
36
            ))
-
 
37
    ; call the tail-recursive local function
39
  (PALINDROMEP1 LI (reverse LI))
38
    (PAL-HELP LI (reverse LI))
-
 
39
  )
40
)
40
)
41
 
41
 
42
;;; Problem 3
42
;;; Problem 3
43
(defun DIVISIBLE-BY-N (DIVIDEND DIVISOR)
43
(defun DIVISIBLE-BY-N (DIVIDEND DIVISOR)
44
  (cond
44
  (cond