Count the number of repetitions of each element in the list in LISP
Write a program in Lisp to enter a number n and create a list of
length n of repeated elements. Count the number of repetitions of each element
in the list. Display the count value of each element in character.
( Eg (1 2 1 1 3) should give the output
“element 1: three times”).
(defun
Num()
(print
"Enter a Number:")
(setq
a(read))
(loop for
i from 0 to a collect(random 3)
)
)
NUM
(defun
occurence()
(setf
b(Num))
(format t
"Elements are : ~S ~%" b)
(setq
m(count 0 b))
(format t
"Element : ~R ~R times ~%" 0 m)
(setq
c(count 1 b))
(format t
"Element : ~R ~R times ~%" 1 c)
(setq
d(count 2 b))
(format t
"Element : ~R ~R times ~%" 2 d)
(setq
e(count 3 b))
(format t
"Element : ~R ~R times ~%" 3 d)
)
OCCURENCE
0 comments: