How to resolve the algorithm Sierpinski pentagon step by step in the Sidef programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Sierpinski pentagon step by step in the Sidef programming language

Table of Contents

Problem Statement

Produce a graphical or ASCII-art representation of a Sierpinski pentagon (aka a Pentaflake) of order 5. Your code should also be able to correctly generate representations of lower orders: 1 to 4.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Sierpinski pentagon step by step in the Sidef programming language

Source code in the sidef programming language

define order = 5
define sides = 5
define dim   = 500
define scaling_factor = ((3 - 5**0.5) / 2)
var orders = order.of {|i| ((1-scaling_factor) * dim) * scaling_factor**i }

say <<"STOP";


    "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">

    style="fill:blue" transform="translate(#{dim},#{dim}) rotate(-18)"
    version="1.1" xmlns="http://www.w3.org/2000/svg">
STOP

var vertices = sides.of {|i| Complex(0, i * Number.tau / sides).exp }

for i in ^(sides**order) {
   var vector = ([vertices["%#{order}d" % i.base(sides) -> chars]] »*« orders «+»)
   var points = (vertices »*» orders[-1]*(1-scaling_factor) »+» vector »reals()» «%« '%0.3f')
   say ('')
}
 
say ''


  

You may also check:How to resolve the algorithm Solve a Hopido puzzle step by step in the Tcl programming language
You may also check:How to resolve the algorithm Matrix multiplication step by step in the Sidef programming language
You may also check:How to resolve the algorithm Unicode variable names step by step in the 8th programming language
You may also check:How to resolve the algorithm Create an object at a given address step by step in the Ada programming language
You may also check:How to resolve the algorithm Ackermann function step by step in the Quackery programming language