# Description

Write a function that accepts the current position of a knight in a chess board, it returns the possible positions that it will end up after 1 move. The resulted should be sorted. 

## Example

"a1" -> ["b3", "c2"]

Source: codewars | Difficulty: EASY
Tags: Fundamentals

Starter code: def possible_positions(pos):
	

Solutions:
def possible_positions(p):
	(r, c) = (ord(p[0]) - 96, int(p[1]))
	moves = [(-2, -1), (-2, 1), (-1, -2), (-1, 2), (1, -2), (1, 2), (2, -1), (2, 1)]
	return [''.join((chr(r + i + 96), str(c + j))) for (i, j) in moves if 1 <= r + i <= 8 and 1 <= c + j <= 8]


def possible_positions(pos):
	col = 'abcdefgh'
	row = '12345678'
	ret = []
	dir = [[1, 2], [1, -2], [-1, 2], [-1, -2], [2, 1], [2, -1], [-2, 1], [-2, -1]]
	(c, r) = (pos[0], pos[1])
	for d in dir:
		x = col.index(c) + d[0]
		y = row.index(r) + d[1]
		if 0 <= x < 8 and 0 <= y < 8:
			ret.append(''.join([col[x], row[y]]))
	return sorted(ret)


import string
KNIGHT = [(-2, -1), (-2, 1), (-1, -2), (-1, 2), (1, -2), (1, 2), (2, -1), (2, 1)]
BOARD_SIZE = 8

def moves(x, y, directions):
	for (dx, dy) in directions:
		(x2, y2) = (x + dx, y + dy)
		if 0 <= x2 < BOARD_SIZE > y2 >= 0:
			yield (x2, y2)

def possible_positions(pos):
	(x, y) = (string.ascii_lowercase.find(pos[0]), int(pos[1]) - 1)
	return [f'{string.ascii_lowercase[x]}{y + 1}' for (x, y) in moves(x, y, KNIGHT)]


def possible_positions(pos):
	board = [[r + str(c) for c in range(1, 9)] for r in 'abcdefgh']
	(x, y) = (ord(pos[0]) - 97, int(pos[1]) - 1)
	return sorted([board[py][px] for (py, px) in [(x + 2, y + 1), (x + 2, y - 1), (x - 2, y + 1), (x - 2, y - 1), (x + 1, y + 2), (x + 1, y - 2), (x - 1, y + 2), (x - 1, y - 2)] if 0 <= px < 8 and 0 <= py < 8])


def possible_positions(pos):
	moves = [(-2, -1), (-2, 1), (-1, -2), (-1, 2), (1, -2), (1, 2), (2, -1), (2, 1)]
	res = []
	for m in moves:
		let = chr(ord(pos[0]) + m[0])
		num = int(pos[1]) + m[1]
		if let in 'abcdefgh' and 0 < num < 9:
			res.append(let + str(num))
	return res


def possible_positions(pos):
	abc = 'abcdefgh'
	(x, y) = (abc.index(pos[0]), int(pos[1]))
	l = [[x + 2, y - 1], [x + 2, y + 1], [x - 2, y - 1], [x - 2, y + 1], [x - 1, y + 2], [x + 1, y + 2], [x - 1, y - 2], [x + 1, y - 2]]
	m = sorted(filter(lambda x: 0 <= x[0] <= 7 and 1 <= x[1] <= 8, l), key=lambda x: (x[0], x[1]))
	return list(map(lambda x: ''.join([abc[x[0]], str(x[1])]), m))


moves = ((-2, -1), (-2, 1), (-1, -2), (-1, 2), (1, -2), (1, 2), (2, -1), (2, 1))

def possible_positions(pos):
	(x, y) = (ord(pos[0]) - 96, int(pos[1]))
	return [f'{chr(96 + x + i)}{y + j}' for (i, j) in moves if -i < x < 9 - i and -j < y < 9 - j]


to_coords = lambda s: (ord(s[0]) - 96, int(s[1]))
from_coords = lambda i, j: f'{chr(i + 96)}{j}'
L = ((1, 2), (1, -2), (-1, 2), (-1, -2), (2, 1), (2, -1), (-2, 1), (-2, -1))

def possible_positions(pos):
	(i, j) = to_coords(pos)
	return sorted((from_coords(i + k, j + l) for (k, l) in L if 0 < i + k <= 8 and 0 < j + l <= 8))


possible_positions = lambda p, m='abcdefgh': (lambda x, y: sorted([m[e[0] + x] + str(e[1] + y) for e in [(-2, 1), (-1, 2), (1, 2), (2, 1), (-2, -1), (-1, -2), (1, -2), (2, -1)] if 8 > e[0] + x >= 0 and 9 > e[1] + y > 0]))(m.find(p[0]), int(p[1]))


def possible_positions(pos):
	(rows, cols) = ('abcdefgh', '12345678')
	row = rows.index(pos[0])
	col = cols.index(pos[1])
	M = [(a, b) for a in [1, -1] for b in [2, -2]]
	P = [(row + rr, col + cc) for (rr, cc) in M + [e[::-1] for e in M]]
	return sorted((rows[r] + cols[c] for (r, c) in P if 0 <= r <= 7 and 0 <= c <= 7))