How to resolve the algorithm Sierpinski triangle step by step in the Icon and Unicon programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Sierpinski triangle step by step in the Icon and Unicon 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 Icon and Unicon programming language

Source code in the icon programming language

# text based adaptaion of 

procedure main(A)

   width := 2 ^ ( 1 + (order := 0 < integer(\A[1]) | 4))  # order of arg[1] or 4
   write("Triangle order= ",order)

   every !(canvas := list(width)) := list(width," ")      # prime the canvas
   every y := 1 to width & x := 1 to width do             # traverse it
      if iand(x - 1, y - 1) = 0 then canvas[x,y] := "*"   # fill

   every x := 1 to width & y := 1 to width do
      writes((y=1,"\n")|"",canvas[x,y]," ")               # print

end


  

You may also check:How to resolve the algorithm Permutations by swapping step by step in the Go programming language
You may also check:How to resolve the algorithm Ethiopian multiplication step by step in the Bracmat programming language
You may also check:How to resolve the algorithm File size distribution step by step in the Nim programming language
You may also check:How to resolve the algorithm Palindrome detection step by step in the Ruby programming language
You may also check:How to resolve the algorithm Universal Turing machine step by step in the JavaScript programming language