Skip to content

Instantly share code, notes, and snippets.

@gsinclair
Created April 4, 2020 11:24
Show Gist options
  • Save gsinclair/f2026a126019d6d12948626b28042a87 to your computer and use it in GitHub Desktop.
Save gsinclair/f2026a126019d6d12948626b28042a87 to your computer and use it in GitHub Desktop.
# --- Question 1 ------------------------------------------- #
# Return the number of jumps required to get to zero.
def light_years(n):
return 0
def test_light_years(n):
assert light_years(10) == 4
assert light_years(11) == 4
assert light_years(30) == 5
# --- Question 2 ------------------------------------------- #
# Return the crate number for a robot with sorting number _n_.
def robot_sort(n):
return 0
def test_robot_sort():
assert robot_sort(5) == 2 # I think
# --- Question 3 ------------------------------------------- #
# Per the example, "CDABFE" -> "331121"
def encrypt_password(S):
return ""
# Per the example, "331121" -> "CDABFE"
def decrypt_password(S):
return ""
def test_encrypt_password():
assert encrypt_password("CDABFE") == "331121"
def test_decrypt_password():
assert decrypt_password("331121") == "CDABFE"
def test_round_trip():
for s in ["ABCDEF", "FEDCBA", "BADCFE", "FDCBAE", "AFECBD"]:
assert decrypt_password(encrypt_password(s)) == s
# --- Question 4 ------------------------------------------- #
# Return the value of a reverse-polish-notation expression, where
# p stands for plus and t stands for times.
# There is no need for = at the end.
def polish(s):
return 0
def test_polish(s):
assert polish("3 5 t") == 15
assert polish("4 3 5 t p") == 19
assert polish("1 4 p 2 7 p t") == 45
# --- Question 5 ------------------------------------------- #
DATA_FT = {
1: [2,3,4,5],
2: [6,7],
3: [8],
4: [],
5: [9,10],
6: [11,12],
7: [13,14,15],
8: [16],
9: [17,18],
10: [19,20,21],
11: [22]
}
# Return the number of grandchildren of person #1.
def familty_tree(data):
return 0
def answer_family_tree():
return family_tree(DATA) 
# --- Question 6 ------------------------------------------- #
# Return the number of locations within 4 blocks of at least two schools.
def twins_schools(rows, cols, school_locations):
return 0
def answer_twins_schools():
return twins_schools(6, 8, [(0,0), (1,7), (5,3)])
# --- Question 7 ------------------------------------------- #
def antarctic(distance, sep, locations, costs):
return 0
def test_antarctic():
assert antarctic(10, 5, [2,4,6,8], [3,2,4,2]) == 4 # camps 4 and 8
def q43():
return antarctic(50, 10,
[4,8,12,16,20,24,28,32,36,40,44],
[4,9,4,6,9,2,6,5,4,8,3]
)
# --- Question 8 ------------------------------------------- #
DATA_JR = ["xxxxx xxxx",
"xx xxxxx xx",
"x x xx",
"xxxxxx x xx",
" x xx x x",
"xxx x xxxx",
"x x xxxx xx",
"x xxxx x xx"]
def jumping_robot(data, starting_location):
return 0
def answer_jumping_robot():
return jumping_robot(DATA_JR, (5,3))
# --- Question 9 ------------------------------------------- #
DATA_SG = ["xxxxxxxx",
"xx xxxxx",
"xx xxxxx",
"xx xxxx ",
"xxx xx",
"xxxxxxxx",
"x xx x",
"xxxxxxxx"]
def sugar_gliders(data, starting_locations):
return 0
def answer_sugar_gliders():
return sugar_gliders(DATA_SG, [(1,1), (3,6), (5,3)])
# --- Question 10 ------------------------------------------ #
DATA_NS = {
"A": (3, []),
"B": (4, ["A"]),
"C": (6, []),
"D": (4, ["B","C"]),
"E": (7, []),
"F": (5, ["E"]),
"G": (3, ["D","F"]),
"H": (5, ["G"]),
"I": (2, ["G"]),
"J": (4, ["I"]),
"K": (3, ["H","J"]),
}
def nursery(data):
return 0
def answer_nursery():
return nursery(DATA_NS)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment