How to resolve the algorithm Sierpinski triangle step by step in the Factor programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Sierpinski triangle step by step in the Factor 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 Factor programming language
Source code in the factor programming language
USING: io kernel math sequences ;
IN: sierpinski
: iterate-triangle ( triange spaces -- triangle' )
[ [ dup surround ] curry map ]
[ drop [ dup " " glue ] map ] 2bi append ;
: (sierpinski) ( triangle spaces n -- triangle' )
dup 0 = [ 2drop "\n" join ] [
[
[ iterate-triangle ]
[ nip dup append ] 2bi
] dip 1 - (sierpinski)
] if ;
: sierpinski ( n -- )
[ { "*" } " " ] dip (sierpinski) print ;
You may also check:How to resolve the algorithm Monty Hall problem step by step in the C# programming language
You may also check:How to resolve the algorithm Horner's rule for polynomial evaluation step by step in the Perl programming language
You may also check:How to resolve the algorithm Metaprogramming step by step in the Raku programming language
You may also check:How to resolve the algorithm Sequence: nth number with exactly n divisors step by step in the Ruby programming language
You may also check:How to resolve the algorithm Bitmap/Bresenham's line algorithm step by step in the SparForte programming language