Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Execute LISP Online

;; Подсчет вхождения атома в список
 
(defun counter (y x) (cond ((null x) 0)
                           ((eq y (car x)) (+ 1 (counter y (cdr x))))
                           (t  (counter y (cdr x)))))
 
;; Построение списка пар
 
(defun mkpair (x) (cond ((null x) nil)
                                 (t (append (list (list (car x) (counter (car x) x))) (mkpair (remove (car x) x))))))
 
 
;; Решение:
 
(defun task (x) (mkpair (collect (flatten x))))
 
==> task
(task '(((2) -3 (4) 0 -2)
          ( -4 0 2)
         ((-3) (3)-4 3) ))
 
==> ((2 2) (-3 2) (4 1) (0 2) (-2 1) (-4 2) (3 2))

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.