Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
41
Task/Stem-and-leaf-plot/ACL2/stem-and-leaf-plot.acl2
Normal file
41
Task/Stem-and-leaf-plot/ACL2/stem-and-leaf-plot.acl2
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
(defun insert (x xs)
|
||||
(cond ((endp xs) (list x))
|
||||
((> x (first xs))
|
||||
(cons (first xs) (insert x (rest xs))))
|
||||
(t (cons x xs))))
|
||||
|
||||
(defun isort (xs)
|
||||
(if (endp xs)
|
||||
nil
|
||||
(insert (first xs) (isort (rest xs)))))
|
||||
|
||||
(defun stem-and-leaf-bins (xs bin curr)
|
||||
(cond ((endp xs) (list curr))
|
||||
((= (floor (first xs) 10) bin)
|
||||
(stem-and-leaf-bins (rest xs)
|
||||
bin
|
||||
(cons (first xs) curr)))
|
||||
(t (cons curr
|
||||
(stem-and-leaf-bins (rest xs)
|
||||
(floor (first xs) 10)
|
||||
(list (first xs)))))))
|
||||
|
||||
(defun print-bin (bin)
|
||||
(if (endp bin)
|
||||
nil
|
||||
(progn$ (cw " ~x0" (mod (first bin) 10))
|
||||
(print-bin (rest bin)))))
|
||||
|
||||
(defun stem-and-leaf-plot-r (bins)
|
||||
(if (or (endp bins) (endp (first bins)))
|
||||
nil
|
||||
(progn$ (cw "~x0 |" (floor (first (first bins)) 10))
|
||||
(print-bin (first bins))
|
||||
(cw "~%")
|
||||
(stem-and-leaf-plot-r (rest bins)))))
|
||||
|
||||
(defun stem-and-leaf-plot (xs)
|
||||
(stem-and-leaf-plot-r
|
||||
(reverse (stem-and-leaf-bins (reverse (isort xs))
|
||||
0
|
||||
nil))))
|
||||
Loading…
Add table
Add a link
Reference in a new issue