代写15-112 F24 Practice Final帮做R语言

15-112 F24

Practice Final

Recommended Time: 3 hours

Reminders that will also be true for the Final:

●   You may not use any concepts (including builtin functions) which were not covered during the semester.

●    Read each question carefully, as some questions may restrict what topics you can use to write your solution.

●   You may assume that almost Equal(x, y) and rounded(n) have been supplied for you. You must write all other helper functions that you wish to use.

   You’re going to do great :)

Please utilize the CS Academy Sandbox tool to test your solutions – especially CTs. If you are unsure how to start a problem or if your solution is correct, feel free to attend OH for help!

There will also be a Practice Final Solution Session where you will be able to see TAs solve the practice midterm and ask any questions that you have! Please check Ed for details.

Note that, like on quizzes and other exams, the test cases provided to you are not exhaustive; you should account for edge cases unless otherwise specified in the problem statement.

True or False

1. .sort() and sorted() both run in O(N^2) time

 True  False

2. All iterative functions can be written recursively

 True  False

3. The following code will cause an MVC violation

def redrawAll(app):

app.color = ‘blue’

drawCircle(100, 100, 40, fill = app.color)

 True  False

Multiple Choice

1. Which of the following is NOT a list method?

 L.index()  L.find()  L.count()  L.append()

2. Converting a list to a set runs in ____

 O(1)  O(log N)  O(N)  O(N^2)

3. Which of the following searching & sorting algorithms has the best efficiency?

 Binary Search  Selection Sort  Merge Sort  Linear Search

CT1:

Indicate what the following code prints. Place your answer (and nothing else) in the box below.

def ct1(L, M):

if len(M) - len(L) <= 2:

return sorted(M)

if (M[0] % 2 == 1):

L.append(M[0])

return [L[0] - M[-1]] + ct1(L, M[1:])

else:

return [L[0] + M[-1]] + ct1(L[2:], M[1:])

print(ct1([], [1, 2, 1, 3, 2]))

CT2:

Indicate what the following code prints. Place your answer (and nothing else) in the box below.

def foo(x):

x + 1

return x - 1

def bar(y):

a = y % 3

print(f"a: {a}")

a += 1

return a

def ct2(x):

print(x + 3)

y = foo(bar(x) + foo(12))

print(f"y: {y}")

print(2 * bar(y))

return y

print("Go!")

ct2(5)

CT3:

Indicate what the following code prints. Place your answer (and nothing else) in the box below.

def ct3(x):

j = c = 0

for i in range(x):

while j < 2 * i:

j += i

c += 1

if (i ** i != j): continue

print(i, j)

return c

print(ct3(3))

CT4:

Indicate what the following code prints. Place your answer (and nothing else) in the box below.

class Point():

def __init__(self, a, b):

self.a = a

self.b = b

def sum(self, other):

return Point(self.a + other.a, self.b + other.b)

def ct4 (a, b):

p1 = Point(a, a * 2)

p2 = Point(b, b - 1)

p3 = p1.sum(p2)

return (p3.a, p3.b)

print(ct4(1, 2))

Free Response 1: nthBalancedPrime(n)

Background: A number is a balanced prime if the following conditions are true:

1.   The number itself is prime, and

2.   It is equal to the average of the nearest prime below it and the nearest prime above it.

For example, 5 is a balanced prime because it is prime and the average of 3 (the nearest prime less than 5) and 7 (the nearest prime greater than 5) is 5.

With this in mind, write the function nthBalanced Prime(n) that takes in a non-negative integer n and returns the nth integer which is a balanced prime.

Here are some test cases:

assert(nth Balanced Prime(0) == 5)

# (3 + 7) / 2 == 5

assert(nth Balanced Prime(1) == 53)

# (47 + 59) / 2 == 53

assert(nth Balanced Prime(2) == 157)

# (151 + 163) / 2 == 157

assert(nth Balanced Prime(3) == 173)

# (167 + 179) / 2 == 173

assert(nth Balanced Prime(4) == 211)

# (199 + 223) / 2 == 211

assert(nth Balanced Prime(9) == 593)

# (587 + 599) / 2 == 593

Free Response 2: Chow Time Animation!

Write an animation that does the following:

1.   Kimchee, a red circle with radius 20, starts at the center of the app and begins moving

towards the user’s mouse. If the user’s mouse is already centered on Kimchee, Kimchee should not be moving. Otherwise, every 0.05 seconds, Kimchee moves one pixel in each direction (x and y) towards the user’s mouse.

2.   Every 2 seconds Mike drops in a piece of food at a random location within the canvas, as represented by a blue circle with radius 10.

3.   There should be no more than 10 pieces of food at any time; if there are 10 pieces in the tank, Mike will wait to drop in any more until Kimchee has eaten one.

4.  A score, drawn in the top right corner of the screen, starts off at zero.

5.   If Kimchee intersects with any part of a ‘food’ circle:

a.   The food should disappear.

b.   The score should increase by 1.

6.   If the ‘r’ key is pressed, all of the food should leave the tank, but Kimchee’s position should not reset. The score should also reset to 0.

7.   app.stepsPerSecond should be set to 20.

Note: You may not assume a specific canvas size. Your solution should be resizable.

Free Response 3: bishopDict(L, color)

Write the function bishopDict(L, color) which takes in a rectangular 2D list L representing a chessboard (of any dimensions), where each cell is guaranteed to be one of the following:

"-" = empty

"b" = black bishop

"w" = white bishop,

as well as a color (either "b" or "w").

This function returns a dictionary mapping each (row, col) where there is a bishop of our specified color to the set of all (row, col) tuples that the bishop can attack. In other words, we map each existing bishop to targetable bishops of the other color.

A bishop can only move diagonally and it cannot move through other pieces. This function should be  non-mutating.

Here is a test case:

L = [["b""-""w""-""-"],

["-""b""-""-""-"],

["-""-""w""-""w"],

["-""-""-""b""-"],

["-""-""-""-""-"],

["-""w""-""w""-"]]

assert(bishopDict(L, "b") == {

(0, 0) : set(),

(1, 1) : {(0, 2), (2, 2)},

(3, 3) : {(2, 2), (2, 4), (5, 1)}})

assert(bishopDict(L, "w") == {

(0, 2) : {(1, 1)},

(2, 2) : {(1, 1), (3, 3)},

(2, 4) : {(3, 3)},

(5, 1) : {(3, 3)},

(5, 3) : set()})

Free Response 4: evensAreSorted(L)

Without using loops or strings, write function evensAreSorted(L) that takes a possibly-empty list  L and returns True if the evens are sorted in strictly increasing order. Odd values are ignored. Lists containing no even values (including an empty list) should also return True.

Note:  Your solution must use recursion. You may not use loops or strings in your solution.

You may not use builtin functions which run in O(N) or worse.

You may not create a new list containing only the even digits.

Here are some test cases:

assert(evensAreSorted([2, 4, 8]) == True)

assert(evensAreSorted([1, 2, 3, 4, 5, 8]) == True)

assert(evensAreSorted([4, 2, 4, 2, 4]) == False)

assert(evensAreSorted([1,2,3,3,2,1]) == False)

assert(evensAreSorted([42, 33, 10, 80]) == False)

assert(evensAreSorted([4]) == True)

assert(evensAreSorted([9]) == True)

assert(evensAreSorted([]) == True)

Free Response 5: kSuperSplit(L, k, n)

Write the function kSuperSplit which takes in a list of positive integers L, a positive integer k,    and a positive integer n, and returns a list of k 1D lists that, when combined, they contain each element of L exactly once, and that the sum of each of each 1D list is at most n.

For example:

L = [1, 5, 1, 1, 2, 3, 4, 5]

k = 3

n = 8

The following is one possible return value for kSuperSplit(L, k, n) given the values above:

L = [ [1, 5, 1, 1],   [3, 5],   [2, 4] ]

The example below has no possible solutions, so kSuperSplit(L, k, n) would return None.

L = [1, 5, 1, 1, 2, 3, 4, 5]

k = 6

n = 4

Here are some test cases:

L = [1, 5, 1, 1, 2, 3, 4, 5]

res = kSuperSplit(L, 3, 8)

assert(res != None)

assert(len(res) == 3)

assert(sorted(res[0] + res[1] + res[2]) == sorted(L))

assert(sum(res[0]) <= 8 and sum(res[1]) <= 8 and sum(res[2]) <= 8)

L = [1, 5, 1, 1, 2, 3, 4, 5]

res = kSuperSplit(L, 4, 6)

assert(res != None)

assert(len(res) == 4)

assert(sorted(res[0] + res[1] + res[2] + res[3]) == sorted(L))

assert(sum(res[0]) <= 6 and sum(res[1]) <= 6 and sum(res[2]) <= 6 and

sum(res[3]) <= 6)

res = kSuperSplit([1, 5, 1, 1, 2, 3, 4, 5], 6, 4)

assert(res == None)

res = kSuperSplit([1, 5, 1, 1, 2, 3, 4, 5], 7, 3)

assert(res == None)

Note: This function must be solved using recursive backtracking! Non-recursive functions may receive zero points, and solutions that do not meet the requirements for backtracking will only be eligible for up to half credit, even if they pass the test cases.


热门主题

课程名

mktg2509 csci 2600 38170 lng302 csse3010 phas3226 77938 arch1162 engn4536/engn6536 acx5903 comp151101 phl245 cse12 comp9312 stat3016/6016 phas0038 comp2140 6qqmb312 xjco3011 rest0005 ematm0051 5qqmn219 lubs5062m eee8155 cege0100 eap033 artd1109 mat246 etc3430 ecmm462 mis102 inft6800 ddes9903 comp6521 comp9517 comp3331/9331 comp4337 comp6008 comp9414 bu.231.790.81 man00150m csb352h math1041 eengm4100 isys1002 08 6057cem mktg3504 mthm036 mtrx1701 mth3241 eeee3086 cmp-7038b cmp-7000a ints4010 econ2151 infs5710 fins5516 fin3309 fins5510 gsoe9340 math2007 math2036 soee5010 mark3088 infs3605 elec9714 comp2271 ma214 comp2211 infs3604 600426 sit254 acct3091 bbt405 msin0116 com107/com113 mark5826 sit120 comp9021 eco2101 eeen40700 cs253 ece3114 ecmm447 chns3000 math377 itd102 comp9444 comp(2041|9044) econ0060 econ7230 mgt001371 ecs-323 cs6250 mgdi60012 mdia2012 comm221001 comm5000 ma1008 engl642 econ241 com333 math367 mis201 nbs-7041x meek16104 econ2003 comm1190 mbas902 comp-1027 dpst1091 comp7315 eppd1033 m06 ee3025 msci231 bb113/bbs1063 fc709 comp3425 comp9417 econ42915 cb9101 math1102e chme0017 fc307 mkt60104 5522usst litr1-uc6201.200 ee1102 cosc2803 math39512 omp9727 int2067/int5051 bsb151 mgt253 fc021 babs2202 mis2002s phya21 18-213 cege0012 mdia1002 math38032 mech5125 07 cisc102 mgx3110 cs240 11175 fin3020s eco3420 ictten622 comp9727 cpt111 de114102d mgm320h5s bafi1019 math21112 efim20036 mn-3503 fins5568 110.807 bcpm000028 info6030 bma0092 bcpm0054 math20212 ce335 cs365 cenv6141 ftec5580 math2010 ec3450 comm1170 ecmt1010 csci-ua.0480-003 econ12-200 ib3960 ectb60h3f cs247—assignment tk3163 ics3u ib3j80 comp20008 comp9334 eppd1063 acct2343 cct109 isys1055/3412 math350-real math2014 eec180 stat141b econ2101 msinm014/msing014/msing014b fit2004 comp643 bu1002 cm2030
联系我们
EMail: 99515681@qq.com
QQ: 99515681
留学生作业帮-留学生的知心伴侣!
工作时间:08:00-21:00
python代写
微信客服:codinghelp
站长地图