May 17th, 2021
Below is a historgram of the results.
Key Statistics
You can find your answers on Gradescope. Let Juliette know if you do not have access to Gradescope.
Regrade Requests We try to grade as consistently as possible, but we are human and we might make mistakes. If you feel like one of your problems was misgraded, please file a regrade request on Gradescope before Monday May 24th at 2pm. Note that this is the only way to have your regrade request considered; in particular, asking your section leader to take a quick look to see whether a problem was misgraded isn't a way of short circuiting this process. We want you to have the credit you deserve, but filing a formal request helps us make sure that your request goes to the right person.
Can I get extra help?
Yes! Come to Nick or Juliette's office hours, post on Ed, and come to LaIR.
I wasn’t able to solve many of the problems on the diagnostic. Should I panic?
Absolutely not! It is normal to find these problems hard. If you didn’t do as well as you
would have liked you have a two step procedure. Step 1: make sure you know the
underlying concepts (for example, using the i variable in a for loop). Then if you know
the concepts but you weren’t able to come up with solutions in time the simple solution is
practice and review! Many people incorrectly think that they are not good at this. False!
We all can code. You just need more experience. Check out the review session.
My answer is different from the provided solution. Is my answer wrong?
Not necessarily. You will learn a lot by looking at the difference between the teaching
team solution and your work. Your answer might be great. There are many solutions.
Can I discuss my solution on ed?
Yes! You are free to share your solutions
Reminder of Grid features:
grid = Grid.build([['row', '0', '0'], ['row', '1', '1']]) # Grid properties: grid.width == 3, grid.height == 2 grid.in_bounds(x, y) - True if in bounds grid.get(x, y) - returns contents at that x,y, or None if empty grid.set(x, y, value) - sets new value into grid at x,y
Given a grid and an in-bounds y value. Every square in the grid is either sand 's', rock 'r', or None.
a. Write a while loop to search row y left-to-right to find the leftmost sand in it. The leftmost sand in a row is the one with the smallest x value.
If there is no sand in the row, return the grid unchanged, otherwise do step b.
b. We'll call the square where the leftmost sand is found the "found" square. In all cases, set the found square to be empty (None), so the sand disappears. If the square below the found square is empty, set it to contain sand ('s'), in effect moving the sand down.
In the example grid below, at row y=0, the leftmost sand is at 2. It cannot move down because a rock is in the way. At row y=1, the leftmost sand is at 3, and it can move down.
def sand_worm(grid, y):
x = 0
while x < grid.width and grid.get(x, y) != 's':
x += 1
if x == grid.width:
return grid
# In all cases, set the found square to be None
grid.set(x, y, None)
if grid.in_bounds(x, y + 1) and grid.(x, y + 1) == None:
grid.set(x, y + 1, 's')
This problem is similar to the Crypto homework. As a simplification, there will be no uppercase chars in this problem - the source, slug, and char will all contain lowercase chars, or chars like '$' which do not have an upper/lower case.
For this problem, there are two slug lists of the same length, and the source list is twice as long as each slug. Compute and return the encrypted form of a char as follows: if the char does not appear in the source list, return the char unchanged. If the char appears in the source list, consider the index where it appears. (a) If that index is a valid index into slug1, return the char at that index in slug1. (b) If the index is invalid (too large) for slug1, reduce the index by the slug1 length, yielding a smaller number. Return the char at that smaller index in slug2. In effect, depending on the index where the char is found in source, either slug1 or slug2 is used.
Say we have this len-4 source and 2 len-2 slugs: source = ['a', 'b', 'c', 'd'] slug1 = ['q', 'r'] slug2 = ['x', 'y'] encryption: 'a' -> 'q' 'b' -> 'r' 'c' -> 'x' 'd' -> 'y'
def encryption(source, slug1, slug2, char):
if char in source:
idx = source.index(char)
if idx < len(slug1):
return slug1[idx]
else:
new_idx = idx - len(slug1)
return slug2[new_idx]
return char
The hottest new cryptocurrency is Yottercoin. A Yottercoin address is marked with a '.yot' at its end. Before that there are always two digits. And before that is a series of zero or more of the three chars, 'y' 'o' 't', which make up the address to be returned. Find and return the first Yottercoin address in s, or None if there is none. If there is a '.yot' in the string, you can assume there is a valid Yottercoin address in the string.
'xx oyot97.yot xx' -> 'oyot' '.itoytoy22.yot33' -> 'toytoy' 'toytoy' -> None
def yottercoin(s):
yot_loc = s.find('.yot')
if yot_loc == -1:
return None
# skip over the digits
start = yot_loc - 3
while start >= 0 and (s[start] == 'y' or s[start] == 'o' or s[start] == 't'):
start -= 1
return [start+1:yot_loc-2]
Reminder: the canvas draw_line function:
canvas.draw_line(x1, y1, x2, y2) - draws a line from x1,y1 to x2,y2
This function takes in parameters (left, top, width, height, n, a) like the Quilt homework, with an additional int parameter a.
Like the Quilt homework, the drawing should have its upper left pixel at left,top, and extending to cover width,height pixels. Draw a blue rectangle at the outer edge (the draw-rect line of code is provided below).
Leave a "margin" area of width a at the left and right sides of the drawing with no lines drawn in it. The parameter n will be an int, 2 or more. Draw a series of n lines from the top edge to the bottom edge. The first line should start at the top edge, next to the left margin area, and end at the bottom edge next to the right margin area. The last line should start at the top next to the right margin, ending at the bottom next to the left margin, with the other lines distributed evenly in between.
def draw_a(canvas, left, top, width, height, n, a):
canvas.draw_rect(left, top, width, height, color='lightblue')
# your code here
for i in range(n):
x_add = i / (n - 1) * (width - 1 - (2 * a))
# to bottom-right
canvas.draw_line(left + a + x_add, top, left + width - a - 1 - x_add, top + height - 1)