How to resolve the algorithm Trabb Pardo–Knuth algorithm step by step in the Common Lisp programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Trabb Pardo–Knuth algorithm step by step in the Common Lisp programming language

Table of Contents

Problem Statement

The TPK algorithm is an early example of a programming chrestomathy. It was used in Donald Knuth and Luis Trabb Pardo's Stanford tech report The Early Development of Programming Languages. The report traces the early history of work in developing computer languages in the 1940s and 1950s, giving several translations of the algorithm. From the wikipedia entry: The task is to implement the algorithm:

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Trabb Pardo–Knuth algorithm step by step in the Common Lisp programming language

Source code in the common programming language

(defun read-numbers ()
  (princ "Enter 11 numbers (space-separated): ")
  (let ((numbers '()))
    (dotimes (i 11 numbers)
      (push (read) numbers))))

(defun trabb-pardo-knuth (func overflowp)
  (let ((S (read-numbers)))
    (format T "~{~a~%~}"
            (substitute-if "Overflow!" overflowp (mapcar func S)))))
                     
(trabb-pardo-knuth (lambda (x) (+ (expt (abs x) 0.5) (* 5 (expt x 3))))
                   (lambda (x) (> x 400)))


  

You may also check:How to resolve the algorithm Append a record to the end of a text file step by step in the Lua programming language
You may also check:How to resolve the algorithm Quaternion type step by step in the Factor programming language
You may also check:How to resolve the algorithm Permutations step by step in the APL programming language
You may also check:How to resolve the algorithm Digital root/Multiplicative digital root step by step in the Red programming language
You may also check:How to resolve the algorithm HTTP step by step in the Java programming language