The sports centre needs repair. Vandals have been kicking balls so hard into the roof that some of the tiles have started sticking up. The roof is represented by r.

As a quick fix, the committee have decided to place another old roof over the top, if they can find one that fits. This is your job.

A 'new' roof (f) will fit if it currently has a hole in it at the location where the old roof has a tile sticking up.

Sticking up tiles are represented by either '\\' or '/'. Holes in the 'new' roof are represented by spaces (' '). Any other character can not go over a sticking up tile.

Return true if the new roof fits, false if it does not.

Source: codewars | Difficulty: EASY
Tags: String algorithms

Fundamentals

Data structures

Starter code: def roof_fix(f,r):
	

Solutions:
def roof_fix(new, old):
	return all((patch == ' ' for (patch, tile) in zip(new, old) if tile in '\\/'))


def roof_fix(f, r):
	return all((x == ' ' or y == '_' for (x, y) in zip(f, r)))


def roof_fix(f, r):
	return all((b == ' ' for (a, b) in zip(r, f) if a in '\\//'))


def roof_fix(f, r):
	return all((b not in '\\/' or a == ' ' for (a, b) in zip(f, r)))


def roof_fix(f, r):
	return all((new == ' ' for (old, new) in zip(r, f) if old in '\\/'))


def roof_fix(f, r):
	return all(([True, a == ' '][b in '\\/'] for (a, b) in zip(f, r)))


def roof_fix(f, r):
	for i in range(len(r)):
		if r[i] in '/\\' and f[i] != ' ':
			return False
	return True


def roof_fix(f, r):
	for (u, y) in zip(f, r):
		if u.isalpha() and y in '/\\':
			return False
	return True


def roof_fix(f, r):
	return not any([pair[0] in '/\\' and pair[1] != ' ' for pair in zip(r, f)])