5 kyu

Pattern Generator

68 of 228candrabeqx

Description:

Pattern Generator

create a function that accepts 1 (one) parameter and returns a string that has such a pattern:

parameter: 1, generate pattern:

x```
  • parameter: 2, generate pattern:

    x
    x x
    x
    
  • parameter: 3, generate pattern:

     x
      x
    x o x
    x
     x
    
  • parameter: 4, generate pattern:

      x
       x
      o x
    x o o x
    x o
     x
      x
    
  • parameter: 5, generate pattern:

       x
        x
       o x
        o x
    x o x o x
    x o
     x o
      x
       x
    
  • parameter: 6, generate pattern:

        x
         x
        o x
         o x
        x o x
    x o x x o x
    x o x
     x o 
      x o
       x 
        x
    

and so on...

assume that:

  • N is an integer within range [-100..200]

  • the function should return empty string if given parameter lower than 1

additional info

the result is compared with smart algorithm, so you don't have to worry about additional space characters that's not visible.

for example, this string:
    x    \n     x   \n    o x  \n     o x \nx o x o x\n x o     \n  x o    \n   x     \n    x    \n

which is seen as:

    x    
     x   
    o x  
     o x 
x o x o x
 x o     
  x o    
   x     
    x    
is treated the same as:
    x\n     x\n    o x\n     o x\nx o x o x\n x o\n  x o\n   x\n    x

which is seen as:

    x
     x
    o x
     o x
x o x o x
 x o
  x o
   x
    x
because both are visibly the same.
Algorithms
ASCII Art

Similar Kata:

More By Author:

Check out these other kata created by candrabeqx

Stats:

CreatedAug 9, 2017
PublishedAug 9, 2017
Warriors Trained1764
Total Skips533
Total Code Submissions4769
Total Times Completed228
JavaScript Completions68
PHP Completions49
Java Completions51
Crystal Completions4
Ruby Completions17
Python Completions73
Total Stars57
% of votes with a positive feedback rating95% of 59
Total "Very Satisfied" Votes54
Total "Somewhat Satisfied" Votes4
Total "Not Satisfied" Votes1
Total Rank Assessments9
Average Assessed Rank
5 kyu
Highest Assessed Rank
4 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • candrabeqx Avatar
  • GiacomoSorbi Avatar
  • Voile Avatar
  • Just4FunCoder Avatar
  • saudiGuy Avatar
Ad