Skip to content

paul-pearson/SierpinskiChallenge

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 

Repository files navigation

Sierpinski Pattern Challenges

Feel free to use helper functions and whatever is needed!

Forbidden:

  • ChatGPT/CoPilot
  • StackOverflow etc

Hints:

Step 1 Sierpinski triangle n=1

Write a Java program to draw Triangle as below.

drawTriangle(4);

Output:
   *   
  * *  
 *   * 
*******

Step 2: Sierpinski Carpet

Implement a Java program to generate and display a Sierpinski Carpet using recursion. The provided code gives you a starting point with a function drawSierpinskiCarpet that takes two parameters - order and size. The order determines the level of recursion, and size sets the size of the carpet. The program initializes a 2D char array representing the carpet, fills it with empty spaces, and then populates it with '*' characters based on the Sierpinski pattern.

Output for drawSierpinskiCarpet(3, 27)
***************************
* ** ** ** ** ** ** ** ** *
***************************
***   ******   ******   ***
* *   * ** *   * ** *   * *
***   ******   ******   ***
***************************
* ** ** ** ** ** ** ** ** *
***************************
*********         *********
* ** ** *         * ** ** *
*********         *********
***   ***         ***   ***
* *   * *         * *   * *
***   ***         ***   ***
*********         *********
* ** ** *         * ** ** *
*********         *********
***************************
* ** ** ** ** ** ** ** ** *
***************************
***   ******   ******   ***
* *   * ** *   * ** *   * *
***   ******   ******   ***
***************************
* ** ** ** ** ** ** ** ** *
***************************

Step 3: Sierpinski Triangle Implementation

Write a Java program to draw a Sierpinski Triangle Implement the drawSierpinskiTriangle function that takes an integer parameter n representing the order of the triangle. The function should draw an equilateral triangle of size 2^n - 1 using '*' characters. The triangle should be centered in the console. The program should have a main method to demonstrate the function.

drawSierpinskiTriangle(3);

Output:
    *           
    **          
                
   *  *         
   ** **        
                
                
  *     *       
 **     **                      
*  *   *  *     
** **  ** **    

The output does not need to be exactly the same. The closer to the best results the better!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 100.0%