< PREVIOUS KATA
NEXT KATA >

## Task:

You have to write a function `pattern` which returns the following Pattern(See Examples) upto desired number of rows. 

* Note:```Returning``` the pattern is not the same as ```Printing``` the pattern.

### Parameters:
    
    pattern(        n        ,        x        ,        y        );
                    ^                 ^                 ^   
                    |                 |                 |
             Term upto which   Number of times   Number of times
              Basic Pattern     Basic Pattern     Basic Pattern
                should be         should be         should be
                 created          repeated           repeated
                                horizontally        vertically
    
* Note: `Basic Pattern` means what we created in Complete The Pattern #12

## Rules/Note:

* The pattern should be created using only unit digits.
* If `n < 1` then it should return "" i.e. empty string.
* If `x <= 1` then the basic pattern should not be repeated horizontally.
* If `y <= 1` then the basic pattern should not be repeated vertically.
* `The length of each line is same`, and is equal to the length of longest line in the pattern.
* Range of Parameters (for the sake of CW Compiler) :
  + `n ∈ (-∞,25]`
  + `x ∈ (-∞,10]`
  + `y ∈ (-∞,10]`
* If only two arguments are passed then the function `pattern` should run as if `y <= 1`.
* If only one argument is passed then the function `pattern` should run as if `x <= 1` & `y <= 1`.
* The function `pattern` should work when extra arguments are passed, by ignoring the extra arguments.
   
   
## Examples:

* Having Three Arguments-

 + pattern(4,3,2):

        1     1     1     1
         2   2 2   2 2   2 
          3 3   3 3   3 3  
           4     4     4   
          3 3   3 3   3 3  
         2   2 2   2 2   2 
        1     1     1     1
         2   2 2   2 2   2 
          3 3   3 3   3 3  
           4     4     4   
          3 3   3 3   3 3  
         2   2 2   2 2   2 
        1     1     1     1
       
* Having Two Arguments-

  + pattern(10,2):

        1                 1                 1
         2               2 2               2 
          3             3   3             3  
           4           4     4           4   
            5         5       5         5    
             6       6         6       6     
              7     7           7     7      
               8   8             8   8       
                9 9               9 9        
                 0                 0         
                9 9               9 9        
               8   8             8   8       
              7     7           7     7      
             6       6         6       6     
            5         5       5         5    
           4           4     4           4   
          3             3   3             3  
         2               2 2               2 
        1                 1                 1

* Having Only One Argument-

  + pattern(25):

        1                                               1
         2                                             2 
          3                                           3  
           4                                         4   
            5                                       5    
             6                                     6     
              7                                   7      
               8                                 8       
                9                               9        
                 0                             0         
                  1                           1          
                   2                         2           
                    3                       3            
                     4                     4             
                      5                   5              
                       6                 6               
                        7               7                
                         8             8                 
                          9           9                  
                           0         0                   
                            1       1                    
                             2     2                     
                              3   3                      
                               4 4                       
                                5                        
                               4 4                       
                              3   3                      
                             2     2                     
                            1       1                    
                           0         0                   
                          9           9                  
                         8             8                 
                        7               7                
                       6                 6               
                      5                   5              
                     4                     4             
                    3                       3            
                   2                         2           
                  1                           1          
                 0                             0         
                9                               9        
               8                                 8       
              7                                   7      
             6                                     6     
            5                                       5    
           4                                         4   
          3                                           3  
         2                                             2 
        1                                               1
        
>>>LIST OF ALL MY KATAS<<<

Source: codewars | Difficulty: EASY
Tags: String algorithms

Fundamentals

Data structures

Starter code: def pattern(n, x=1, y=1, *args):
	

Solutions:
def pattern(n, x=1, y=1, *args):
	if n < 1:
		return ''
	result = []
	for i in range(1, n + 1):
		line = ' ' * (i - 1) + str(i % 10) + ' ' * (n - i)
		result.append(line + line[::-1][1:] + (line[1:] + line[::-1][1:]) * (x - 1))
	return '\n'.join(result + result[::-1][1:] + (result[1:] + result[::-1][1:]) * (y - 1))


def pattern(n, y=1, z=1, *e):
	res = []
	for i in range(1, n + 1):
		line = ' ' * (i - 1) + str(i % 10) + ' ' * (n - i)
		res.append(patt(line) + cott(patt(line), y))
	res1 = patt(res) + cott(patt(res), z)
	return '\n'.join(res1)
patt = lambda elem: elem + elem[::-1][1:]
cott = lambda elem, x: elem[1:] * (x - 1)


def pattern(*arg):
	res = []
	arg = list(arg) + [1, 1]
	(n, y, z) = arg[:3]
	for i in range(1, n + 1):
		line = ' ' * (i - 1) + str(i % 10) + ' ' * (n - i)
		res.append(patt(line) + cott(patt(line), y))
	res1 = patt(res) + cott(patt(res), z)
	return '\n'.join(res1)
patt = lambda elem: elem + elem[::-1][1:]
cott = lambda elem, x=0: elem[1:] * (x - 1)


def getHorizontal(s, x):
	return s + s[1:] * (x - 1)

def pattern(n, x=1, y=1, *a):
	if n < 1:
		return ''
	(l, x, y) = (2 * n - 1, max(1, x), max(1, y))
	sngl = [getHorizontal('{}{}{}'.format(z % 10, ' ' * (l - 2 * z), z % 10 if z != n else '').center(l), x) for z in range(1, n + 1)]
	cross = sngl + sngl[:-1][::-1]
	return '\n'.join(cross + cross[1:] * (y - 1))


def pattern(n, x=1, y=1, *args):
	lines = []
	x -= 1
	for i in range(1, n + 1):
		line = ' ' * (i - 1) + str(i)[-1] + ' ' * (n - i)
		line += line[-2::-1]
		line += line[1:] * x
		lines.append(line)
	pat = lines + lines[-2::-1]
	pat += pat[1:] * (y - 1)
	return '\n'.join(pat)


def pattern(n, x=1, y=1, *_):
	pat = [''.join([' ' * (i - 1), str(i % 10), ' ' * (n - i)]) for i in range(1, n + 1)]
	pat = [''.join([i, i[-2::-1]]) for i in pat]
	pat = [''.join([i, i[1:] * (x - 1)]) for i in pat]
	pat1 = '\n'.join(pat + pat[-2::-1])
	return '' if n < 1 else pat1 + ('\n' + '\n'.join(pat[1:] + pat[-2::-1])) * (y - 1)


pattern = lambda n, x=1, y=1, *args: '\n'.join((lambda h: h + ['\n'.join(h[1:]) for k in range(1, y)])([(lambda r: ''.join(r) + ''.join([''.join(r[1:]) for j in range(1, x)]))([' '] * (i - 1) + [str(i % 10)] + [' '] * (2 * (n - i) - 1) + [str(i % 10)] + [' '] * (i - 1)) for i in range(1, n)] + [(lambda r: r + ''.join([r[1:] for j in range(1, x)]))(' ' * (n - 1) + str(n % 10) + ' ' * (n - 1))] + [(lambda r: ''.join(r) + ''.join([''.join(r[1:]) for j in range(1, x)]))([' '] * (i - 1) + [str(i % 10)] + [' '] * (2 * (n - i) - 1) + [str(i % 10)] + [' '] * (i - 1)) for i in range(n - 1, 0, -1)])) if n > 0 else ''


def pattern(n, m=1, l=1, *args):
	if n < 1:
		return ''
	m = max(1, m)
	(li, mid, r) = (['1' + ' ' * (n * 2 - 1 - 2) + '1' + (' ' * (n * 2 - 1 - 2) + '1') * (m - 1)], 1, n * 2 - 1 - 2 - 2)
	for i in range(2, n + 1):
		li.append(' ' * (i - 1) + f"{' ' * mid}".join([str(i % 10) + ' ' * r + (str(i % 10) if i != n else '') for o in range(m)]) + ' ' * (i - 1))
		r -= 2
		mid += 2
	li = li + li[:-1][::-1]
	well = li.copy()
	return '\n'.join(li + ['\n'.join(well[1:]) for i in range(l - 1)])


(m, r) = (lambda s: s + s[-2::-1], lambda s, n: s + s[1:] * n)
pattern = lambda n, h=1, v=1, *a: '\n'.join(r(m(list((r(m(' ' * (i - 1) + str(i % 10) + ' ' * (n - i)), h - 1) for i in range(1, n + 1)))), v - 1))