How to resolve the algorithm Stem-and-leaf plot step by step in the ACL2 programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Stem-and-leaf plot step by step in the ACL2 programming language

Table of Contents

Problem Statement

Create a well-formatted stem-and-leaf plot from the following data set, where the leaves are the last digits: The primary intent of this task is the presentation of information. It is acceptable to hardcode the data set or characteristics of it (such as what the stems are) in the example, insofar as it is impractical to make the example generic to any data set. For example, in a computation-less language like HTML the data set may be entirely prearranged within the example; the interesting characteristics are how the proper visual formatting is arranged. If possible, the output should not be a bitmap image. Monospaced plain text is acceptable, but do better if you can. It may be a window, i.e. not a file.

Note: If you wish to try multiple data sets, you might try this generator.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Stem-and-leaf plot step by step in the ACL2 programming language

Source code in the acl2 programming language

(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))))


  

You may also check:How to resolve the algorithm Terminal control/Clear the screen step by step in the jq programming language
You may also check:How to resolve the algorithm Soloway's recurring rainfall step by step in the Rust programming language
You may also check:How to resolve the algorithm Fibonacci sequence step by step in the Euphoria programming language
You may also check:How to resolve the algorithm Empty string step by step in the Run BASIC programming language
You may also check:How to resolve the algorithm Maximum triangle path sum step by step in the EasyLang programming language