How to resolve the algorithm Sierpinski carpet step by step in the ALGOL W programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Sierpinski carpet step by step in the ALGOL W 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 ALGOL W programming language
Source code in the algol programming language
begin
for depth := 3 do begin
integer dim;
dim := 1;
for i := 0 until depth - 1 do dim := dim * 3;
for i := 0 until dim - 1 do begin
for j := 0 until dim - 1 do begin
integer d;
d := dim div 3;
while d not = 0
and not ( ( i rem ( d * 3 ) ) div d = 1 and ( j rem ( d * 3 ) ) div d = 1 )
do d := d div 3;
writeon( if d not = 0 then " " else "##" )
end for_j;
write()
end for_i;
write()
end for_depth
end.
You may also check:How to resolve the algorithm Ordered words step by step in the Burlesque programming language
You may also check:How to resolve the algorithm Sum of a series step by step in the Action! programming language
You may also check:How to resolve the algorithm Environment variables step by step in the Slate programming language
You may also check:How to resolve the algorithm Fibonacci word step by step in the Kotlin programming language
You may also check:How to resolve the algorithm Case-sensitivity of identifiers step by step in the UNIX Shell programming language