- Input: Integer `n`
- Output: String

Example:

`a(4)` prints as
```
   A   
  A A  
 A A A 
A     A
```

`a(8)` prints as
```
       A       
      A A      
     A   A     
    A     A    
   A A A A A   
  A         A  
 A           A 
A             A
```

`a(12)` prints as
```
           A           
          A A          
         A   A         
        A     A        
       A       A       
      A         A      
     A A A A A A A     
    A             A    
   A               A   
  A                 A  
 A                   A 
A                     A
```
Note:

- Each line's length is `2n - 1`
- Each line should be concatenate by line break `"\n"`
- If `n` is less than `4`, it should return `""`
- If `n` is odd, `a(n) = a(n - 1)`, eg `a(5) == a(4); a(9) == a(8)`

Source: codewars | Difficulty: EASY
Tags: String algorithms

Fundamentals

Starter code: def a(n):
	

Solutions:
def a(n):
	if n % 2 != 0:
		n = n - 1
	if n < 4:
		return ''
	side = ' ' * (n - 1)
	li = [side + 'A' + side]
	for i in range(1, n):
		side = side[1:]
		middle = 'A ' * (i - 1) if i == n / 2 else '  ' * (i - 1)
		li.append(side + 'A ' + middle + 'A' + side)
	return '\n'.join(li)


def a(n):
	if n < 4:
		return ''
	if n % 2:
		n -= 1
	lines = ('A' if i == 0 else ' '.join('A' * (i + 1)) if i == n // 2 else 'A' + ' ' * (2 * i - 1) + 'A' for i in range(n))
	width = 2 * n - 1
	return '\n'.join((line.center(width) for line in lines))


def a(n):
	n -= n % 2
	if n < 4:
		return ''
	return '\n'.join(('{0}{1}{0}'.format('A' * (i % (n // 2) != 0), ' ' * (i * 2 - 1) if i % (n // 2) else ' '.join(['A'] * (i + 1))).center(2 * n - 1) for i in range(n)))


a = lambda n: '\n'.join(['A'.center(2 * (n - (n & 1)) - 1)] + [[('A ' * ((n - (n & 1)) // 2 + 1)).rstrip().center(2 * (n - (n & 1)) - 1), ('A' + ' ' * (i * 2 + 1) + 'A').center(2 * (n - (n & 1)) - 1)][i != (n - (n & 1)) // 2 - 1] for i in range(n - 1 - (n & 1))]) if n - (n & 1) > 3 else ''