How to resolve the algorithm Sierpinski carpet step by step in the Common Lisp programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Sierpinski carpet step by step in the Common Lisp programming language
Table of Contents
Problem Statement
Produce a graphical or ASCII-art representation of a Sierpinski carpet of order N.
For example, the Sierpinski carpet of order 3 should look like this: The use of the # character is not rigidly required for ASCII art. The important requirement is the placement of whitespace and non-whitespace characters.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Sierpinski carpet step by step in the Common Lisp programming language
Source code in the common programming language
(defun print-carpet (order)
(let ((size (expt 3 order)))
(flet ((trinary (x) (format nil "~3,vR" order x))
(ones (a b) (and (eql a #\1) (eql b #\1))))
(loop for i below size do
(fresh-line)
(loop for j below size do
(princ (if (some #'ones (trinary i) (trinary j))
" "
"#")))))))
You may also check:How to resolve the algorithm Null object step by step in the Standard ML programming language
You may also check:How to resolve the algorithm Loops/For step by step in the NetRexx programming language
You may also check:How to resolve the algorithm Pseudo-random numbers/Splitmix64 step by step in the Ruby programming language
You may also check:How to resolve the algorithm Read a file character by character/UTF8 step by step in the Go programming language
You may also check:How to resolve the algorithm Combinations step by step in the Eiffel programming language