This was a challenging prelim! If you have done well, congratulations! If you have not done well, be sure to catch up and then you can show us at the next exams what you have learned! Remember, Prelim 1 is worth only 20% so you have plenty of opportunities to improve.
v
and later in the loop just ended up using
the original vector values instead of the updated values.
for
-loop detail,
linear interpolation)Part (b): This question on linear interpolation was mostly well done. The given code does NOT correctly interpolate the colors from colA to colB. Look closely at the calculation of the fraction... remember our discussion during lecture on moving from the continuous space to the discrete space? In part 2 of the question where you were to modify the code according to your answer in part 1, you got full credit as long as you wrote code correctly to match your part 1 answer and according to the specifications.
if
-construct,
boolean expression, random number generation)if
-construct to branch four ways,
but the organization of the branches was problematic for some
students. When this problem wasn't done well, the most typical issue was
incorrect (and too complicated) boolean expressions that resulted from the
choice of the order of the four cases. Use the order in which you
check for the different cases to your advantage to make your life easier!
For example, the "completely inside" and "completely outside" cases are
straightforward to define using boolean expressions, so starting with those
cases would be a good choice because you can then just leave the
difficult case (in terms of writing boolean expressions)
of crossing the edge of the black square to the else
-branch where
no boolean expression is required!!! Students who chose to deal with the difficult
(crossing the edge) case as the first or second branch had a really tough
time--we saw few correct boolean expressions and many, many wrong and long ones for
these two difficult ways of organizing the branches. Important lesson:
When approaching a problem with multiple cases that are to be determined in an
if
-statement, look for the easiest cases and check for those
first; then use the else
branch to your advantage for the most
complicated case!
x
and y
as the
lower-left corner even though the problem statement specified x
and y
to be the center of the square. Read
carefully!
s
and h
for the side length and half-side length, respectively, than to hard-code the
literal values. For example, the
expression x+h<1
is more descriptive ("right edge of small
square is less than 1") than x<0.6
. You can more easily check
your expressions to avoid mistakes (and we can more easily read your logic)
if you use meaningful variable names.
rem
, division, and
truncation (floor
) was challenging for many.
(a) Writing a function, algorithm to count and sum the digits
input
statements
to obtain values for the input parameters, which was wrong.
floor(log10(num))+1
seen in
discussion to get the number of digits and then divide by an appropriate power
of 10 and round down to extract the digits starting from the left.
Some students devised schemes that worked only for specific ranges of
integers (e.g., integers greater than 10, integers less than a million, or ...),
which did not solve the problem posed.
floor
function after
dividing the input number by 10 to round down. This would cause the input number
to have a
fractional component, which would often mean the final sum would be incorrectly
computed. Some students used ceil
and subtracted 1 instead, but this
does not work for all cases.
(b) Indefinite iteration, generating random integers, calling a function
D
to be exceeded: (1) After generating an integer do NOT include it in the
sequence until AFTER you check the impact on the total digit count. (2)
Always include the generated integer in the sequence but after the loop
ends check the total digit count against D
and get rid of the
last integer if D
is exceeded.
floor
or ceil
to round the real value to
an integer.
ATemp(k)
and LTemp(k)
for some range of
k
instead of considering all combinations of the
elements in the two vectors. You need to pair
ATemp(1)
with LTemp(1)
, LTemp(2)
, ..., etc., then pair
ATemp(2)
with LTemp(1)
, LTemp(2)
, ..., etc.,
ATemp
and a different index variable for LTemp
! By using a single loop,
one also cannot deal
with the different lengths of ATemp
and LTemp
properly: if your single loop iterates through the shorter vector then the
last elements in the longer vector are unaccounted for, or if your single
loop iterates through the longer vector then there's an index out of bound
error. But the main issue is that in order to
get all combinations of the elements in the two vectors you need
nested loops with two index variables, one for each vector.
% Action to take after prelim if yourScore > 85 toDo= celebrate + later look at the solution elseif yourScore > 65 toDo= redo problems + later check solution else toDo= meet with course staff to go over exam ... + stay caught up from now on ... + do NOT just read the solution--must redo problems end