This will probably be a little series :)

X-Shape

You will get an odd Integer n (>= 3) and your task is to draw a X. Each line is separated with '\n'.

Use the following characters:  ■ □

For Ruby, Crystal and PHP:   whitespace and o 

e.g.:



                                     ■□□□■
            ■□■                      □■□■□
  x(3) =>   □■□              x(5)=>  □□■□□
            ■□■                      □■□■□
                                     ■□□□■


 Series: ASCII Fun

ASCII Fun #1: X-Shape
ASCII Fun #2: Funny Dots
ASCII Fun #3: Puzzle Tiles
ASCII Fun #4: Build a pyramid

Source: codewars | Difficulty: EASY
Tags: String algorithms

Starter code: def x(n):
	

Solutions:
def x(n):
	ret = [['□' for _ in range(n)] for _ in range(n)]
	for i in range(len(ret)):
		ret[i][i] = '■'
		ret[i][-1 - i] = '■'
	return '\n'.join((''.join(row) for row in ret))


(f, e) = '■□'

def x(n):
	l = n // 2
	middle = [f'{e * l}{f}{e * l}']
	half = [f'{e * i}{f}{e * (n - 2 * i - 2)}{f}{e * i}' for i in range(l)]
	return '\n'.join(half + middle + half[::-1])


def x(n):
	result = []
	for i in range(int(n / 2) + 1):
		line = '□' * i + '■' + '□' * (int(n / 2) - i)
		result.append(line + line[::-1][1:])
	return '\n'.join(result + result[::-1][1:])


def x(n):
	return '\n'.join((''.join(('■' if row == col or row == n - 1 - col else '□' for col in range(n))) for row in range(n)))


def x(n):
	m = n - 1
	return '\n'.join((''.join(('□■'[i + j == m or i == j] for j in range(n))) for i in range(n)))


def x(n):
	i = 0
	out = ''
	while i < n:
		out = out + line(n, i)
		if i != n - 1:
			out = out + '\n'
		i = i + 1
	return out

def line(x, ln):
	blank = '□'
	pixel = '■'
	str = ''
	n = 0
	while n < x:
		if n == ln:
			str = str + pixel
		elif n == x - 1 - ln:
			str = str + pixel
		else:
			str = str + blank
		n = n + 1
	return str


def x(n):
	res = ''
	for i in range(n):
		t = ''
		for j in range(n):
			t += '■' if j == i or j == n - 1 - i else '□'
		res += t + '\n'
	return res[:len(res) - 1]


def x(n):
	arr = [['□'] * n for _ in range(n)]
	for i in range(len(arr)):
		arr[i][i] = arr[i][-1 - i] = '■'
	return '\n'.join([''.join(i) for i in arr])


def x(n):
	tmpl = '\n'.join((''.join(('{1}' if j in (i, n - i - 1) else '{0}' for j in range(n))) for i in range(n)))
	return tmpl.format('□', '■')


def x(n):
	g = []
	for i in range(n // 2 + 1):
		rt = ['□'] * n
		(rt[i], rt[-(i + 1)]) = ('■', '■')
		g.append(rt)
	return '\n'.join((''.join(e) for e in g + g[:-1][::-1]))