for
loops or while
loops this week!hasConsecutiveDigits(n)
.maxOdd(L)
you cannot call oddsOnly(L) and then take the max of that list,
since that gratuitously creates an extraneous list (and, to be technical, uses O(N) space instead of
O(1) space as the problem requires). Instead, directly compute maxOdd(L)
with recursion.
In fact, that's the main point of asking you to solve both oddsOnly(L)
and maxOdd(L)
:
to encourage you to think about the structural differences in these problems and how that affects your
recursive logic.
def testHasConsecutiveDigits(): print("Beginning hasConsecutiveDigits test cases...") assert(hasConsecutiveDigits(1123) == True) assert(hasConsecutiveDigits(-1123) == True) assert(hasConsecutiveDigits(1234) == False) assert(hasConsecutiveDigits(0) == False) assert(hasConsecutiveDigits(1233) == True) print("Passed!")
from cmu_112_graphics import *
import math
def redrawAll(app, canvas):
cx = app.width / 2
cy = app.height / 2
x0 = cx - 100
x1 = cx + 100
y0 = cy - 50
y1 = cy + 50
e = -180
canvas.create_rectangle(x0, y0, x1, y1, outline = 'red')
canvas.create_oval(x0, y0, x1, y1, outline = 'blue')
canvas.create_arc(x0, y0, x1, y1,
outline="green", width = 5, style="arc", extent=e)
runApp(height = 400, width = 400)
'hit t for tetris bonus'
to the console when we run your Freddy Fractal Viewer.
And have fun!