Midterm exam 2 solutions: 1. False. It's the language with zero or more a's. True. The weighted sum of the inputs is 0 which is not >= 1 (the threshold). False. It depends on the heuristic function and even with a good one, dfs may get lucky. False. In the function: a = "I live" b = "coding" c = "CS" (it's default value) so the result would be: "I live coding CS" False. Lines read from a file are always strings, so "line" would be a string not an int. line * 10 for strings would replicated the line multiple time, e.g. "1111111111" for the first line. False. Decreasing the weights makes it even harder to achieve the threshold, so we would need to decrease the threshold (and by more than just 1). 2. a. i. aca abcba abbcbba abbbcbbba ii. No. iii. Strings that: - start and end with an 'a' - have a 'c' in the middle - have zero or more b's in between the a's and c's, symmetrically More mathematically: a b^n c b^n a for n = 0, 1, ... b. w_1 = -1 w_2 = -1 T = -1.5 c. Same node by add an additional input which is always 1 and a weight of -0.5. 3. a. 5, 9, 8, 3, 10, 7, 2, 4, 1, 6 or (if you used the second figure) 5, 9, 8, 10, 3, 7, 2, 4, 1, 6 b. 5, 2, 1, 6, 4, 7, 9, 3, 10, 8 or (if you used the second figure) 5, 2, 1, 6, 4, 7, 9, 3, 8, 10 c. 5, 2, 7, 9, 1, 4, 3, 8, 6, 10 d. No, Yes, Yes 4. a. Apricot Pie with 8 slices left Strawberry Pie with 8 slices left b. Two lines need changing: - in init: add self.size = size - in get_area: change size to self.size c. - in eat_slice: change type to self.type d. i. No. It should print something like: Cherry pie with 0 slices left Cherry pie with 8 slices left It doesn't make sense to "bake" (i.e. make) a new pie and return it with 0 slices left. ii. - in bake_another_pie: change self.slices_left = 8 to new_state.slices_left = 8