-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexercises.py
More file actions
43 lines (36 loc) · 1.57 KB
/
exercises.py
File metadata and controls
43 lines (36 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
def is_anagram(s1, s2):
"""
Write an algorithm that returns whether s1 and s2 are anagrams of each other, i.e.
if s1 and s2 contain the same letters in a possibly different order.
E.g.: "abc" and "cab" are anagrams, "aab" and "bba" are not.
:param s1: string
:param s2: string
:return: True or False
"""
# Write your code here
pass
def check_parenthesis_consistency(string):
"""
Write an algorithm that determines if the parenthesis (round brackets "()") in a string are properly balanced.
An expression is said to be properly parenthesised if it has the form "(p)" or "pq", where p and q are
properly parenthesised expressions. Any string (including an empty string) that does not contain any parenthesis
is properly parenthesised.
E.g.: "()()" is properly parenthesised, "(()" is not.
:param string: the string to analyse.
:return: True if the parentheses are balanced, False if not.
"""
# Write your code here
pass
def shortest_path(start, end, maze):
"""
Write an algorithm that finds the shortest path in a maze from start to end
The maze is represented by a list of lists containing 0s and 1s:
0s are walls, paths cannot go through them
The only movements allowed are UP/DOWN/LEFT/RIGHT
:param start: tuple (x_start, y_start) - the starting point
:param end: tuple (x_end, y_end) - the ending point
:param maze: list of lists - the maze
:return: list of positions [(x1, y1), (x2, y2), ...] representing the shortest path in the maze
"""
# Write your code here
pass