How to resolve the algorithm Sierpinski triangle step by step in the Picat programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Sierpinski triangle step by step in the Picat programming language
Table of Contents
Problem Statement
Produce an ASCII representation of a Sierpinski triangle of order N.
The Sierpinski triangle of order 4 should look like this:
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Sierpinski triangle step by step in the Picat programming language
Source code in the picat programming language
go =>
foreach(N in 1..4)
sierpinski(N),
nl
end,
nl.
sierpinski(N) =>
Size = 2**N,
foreach(Y in Size-1..-1..0)
printf("%s", [' ' : _I in 1..Y]),
foreach(X in 0..Size-Y-1)
printf("%s ", cond(X /\ Y == 0, "*", " "))
end,
nl
end.
You may also check:How to resolve the algorithm Tokenize a string step by step in the Lang programming language
You may also check:How to resolve the algorithm IBAN step by step in the AutoHotkey programming language
You may also check:How to resolve the algorithm Look-and-say sequence step by step in the AppleScript programming language
You may also check:How to resolve the algorithm Munching squares step by step in the Befunge programming language
You may also check:How to resolve the algorithm Balanced brackets step by step in the Objeck programming language