###############################################################################
# --------------------- 15-112 Recitation Week 2: Loops --------------------- #

# This is a starter file of the problems we did in recitation. A good way to
# use this file is to try to re-write problems you saw in recitation from
# scratch. This way, you can test your understanding and ask on Piazza or
# office hours if you have questions :)

# Note: this starter file does not contain solutions, because we want you to learn
# the process of how to solve a problem live from the TAs. Reading a pre-written
# solution is much less helpful than watching someone else solve a problem
# and re-solving it yourself!

# --------------------------------------------------------------------------- #
###############################################################################
# Code Tracing
###############################################################################

def ct2(n):
    k = 0
    total = 0
    while (n >= k):
        print('k =', k)
        for i in range(k):
            total += n%10
            n //= 10
            print(i, n%10, total)
        k += 1 
    print('total =', total)

print(ct2(123))


###############################################################################
# longestDigitRun
###############################################################################

'''
Write the function longestDigitRun(n) that takes a possibly-negative
int value n and returns the digit that has the longest consecutive run,
or the smallest such digit if there is a tie. So, longestDigitRun(117773732)
returns 7 (because there is a run of 3 consecutive 7's),
as does longestDigitRun(-677886).
'''

def longestDigitRun(n):
    return 42

def testLongestDigitRun():
    assert(longestDigitRun(117773732) == 7)
    assert(longestDigitRun(-677886) == 7)
    # other test cases here


###############################################################################
# nthRightTruncatablePrime
###############################################################################
'''
A right-truncatable prime is a prime which remains prime when the last
("right") digit is successively removed. 7393 is an example of a
right-truncatable prime, since 7393, 739, 73, 7 are all prime.
Write the function nthRightTruncatablePrime(n). So nthRightTruncatablePrime(0)
returns 2, and nthRightTruncatablePrime(10) returns 71.
'''

def nthRightTruncatablePrime(n):
    return 42

def testRTP():
    assert(nthRightTruncatablePrime(0) == 2)
    assert(nthRightTruncatablePrime(10) == 71)
    # other test cases here


###############################################################################
# zeroTriangle
###############################################################################
'''
Given a specific height (where height is a non-negative int),
the function prints out (not returns!) an isosceles triangle
with the specified height. There should be no spaces between the zeroes
that make up the triangle, nor should there be any "extra" spaces on any row
(so no extra spaces to the right).

zeroTriangle(3)
  0
 000
00000

zeroTriangle(5)
    0
   000
  00000
 0000000
000000000
'''

def zeroTriangle(height):
    return 42
