###############################################################################
# ---------------- 15-112 Recitation #19: Final Review 2 ---------------- #

# 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 :)

# --------------------------------------------------------------------------- #
###############################################################################
# nthPolyDivisibleNumber
###############################################################################
# LEARNING OBJECTIVES
# Review nth template and how to navigate numbers
'''
A polydivisible number (coined term) is a number without leading zeros 
(the number cannot start with a 0), such that the first digit of the number 
is divisible by 1, the first two digits together are divisible by 2, the first 
three digits together are divisible by 3, the first four digits together are 
divisible by 4 and so on. Note that this means that the number itself must be 
divisible by the number of digits in the number. For example 98765 is a 
polydivisible number, as 9 is divisible by 1, 98 is divisible by 2, 987 
is divisible by 3, 9876 is divisible by 4 and 98765 is divisible by 5. 
On the other hand 123456 is not polydivisible as 1234 is not divisible by 4. 

With this in mind, write the function nthPolydivisibleNum(n) that takes an 
input n and returns the n’th polydivisible number. (where we start counting 
n at 0).

For full credit on this problem, you may not use strings or lists. 

For your reference here are the first few polydivisible numbers. 
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28. 
(so nthPolydivisble(0) should return 1)

'''

def nthPolyDivisibleNumber(n):
    return 42


###############################################################################
# 2D List CT
###############################################################################
# LEARNING OBJECTIVES
# Review 2D list CT

import copy 
def ct1(L): 
    a = L 
    b = copy.copy(L) 
    a[0] = b[1] 
    c = copy.deepcopy(L) 
    c[1] = a.pop() 
    b[2][1] += 2 
    b[0][0] += a[1].pop() 
    L = c 
    return b + c
L = [[2],[3,9],[0,4]] 
#print(ct1(L)) 
#print(L)



###############################################################################
# Recursive ROC
###############################################################################
# LEARNING OBJECTIVES
# Review recursive ROC

def roc2Helper(L,z): 
    if L == []: 
        z[0] += 1 
        return 0 
    elif isinstance(L[0], list): 
        return roc2Helper(L[0],z) + roc2Helper(L[1:], z) 
    elif isinstance(L[0], int): 
        z[1] += 1 
        return L[0] + roc2Helper(L[1:], z)

def roc2(L): 
    z = [0,0] 
    n = roc2Helper(L,z) 
    return n == 12 and z[0] == 3 and z[1] == 6

#Hint: L is a 2D List


###############################################################################
# OOPy Space
###############################################################################
# LEARNING OBJECTIVES
# Review OOPy Animation

'''
Space - the ﬁnal frontier. In it, we have discovered the salubrious solar system 
    - a collection of planets known for their health-giving properties - 
    and our scientists insist that we model it for research purposes. Wary of the 
    work ahead but undeterred, we begin what may be our best work yet. In modeling 
    the salubrious solar system our scientists have informed us of certain properties 
    we should satisfy: 

• It has a single sun with mass ranging between 10**10 and 1.5*10**10 (random) and 
    a radius varying between 25 and 50 (also random). The sun is in the middle of 
    the screen, and does not move.
• Initially, 6 planets ﬂoat in space, generated in the following way: – Planets 
    are generated in the top left corner of the canvas – They have a random x 
    and y velocity (in any direction, with speed between 5 and 10 pixels per timer ﬁred) 
    – And a random mass between 6 * 10 **6 and 8 * 10**6 – And a random radius 
    between 5 and 20. 
• Every timer ﬁred, the planets move in the direction deﬁned by their x and y 
    velocities. However, because of gravity, their velocities increase by 1 in the 
    direction of the sun. For example, if a planet is to the left of the sun, its x 
    velocity increases to the right. This is the same for the other direction in addition 
    to the y velocity. 
• If a planet collides with the sun, the sun gets hungry and eats it (realistic, I know) 
    and gains half of the planets radius and mass and a new planet is spawned. 
• Every second, planets and the sun change color from white to some random color
    (either pink, purple, or green), or from non-white back to white. Also, display 
    the planet/suns mass in the middle of it. 
• Finally, the user can click inside a planet to stop it from moving every timer ﬁred, 
    and can press r to restart the simulation.

In order to receive full credit for this problem, you must have a parent class from 
which both the Sun and Planet classes inherit from, and use OOP in a meaningful way 
in your animation. You may assume that the run function has been written for you
'''

# Animation Starter Code, Focus on timerFired

from tkinter import *

####################################
# customize these functions
####################################

def init(data):
    # load data.xyz as appropriate
    pass

def mousePressed(event, data):
    # use event.x and event.y
    pass

def keyPressed(event, data):
    # use event.char and event.keysym
    pass

def timerFired(data):
    pass

def redrawAll(canvas, data):
    # draw in canvas
    pass

####################################
# use the run function as-is
####################################

def run(width=300, height=300):
    def redrawAllWrapper(canvas, data):
        canvas.delete(ALL)
        canvas.create_rectangle(0, 0, data.width, data.height,
                                fill='white', width=0)
        redrawAll(canvas, data)
        canvas.update()

    def mousePressedWrapper(event, canvas, data):
        mousePressed(event, data)
        redrawAllWrapper(canvas, data)

    def keyPressedWrapper(event, canvas, data):
        keyPressed(event, data)
        redrawAllWrapper(canvas, data)

    def timerFiredWrapper(canvas, data):
        timerFired(data)
        redrawAllWrapper(canvas, data)
        # pause, then call timerFired again
        canvas.after(data.timerDelay, timerFiredWrapper, canvas, data)
    # Set up data and call init
    class Struct(object): pass
    data = Struct()
    data.width = width
    data.height = height
    data.timerDelay = 100 # milliseconds
    root = Tk()
    init(data)
    # create the root and the canvas
    canvas = Canvas(root, width=data.width, height=data.height)
    canvas.configure(bd=0, highlightthickness=0)
    canvas.pack()
    # set up events
    root.bind("<Button-1>", lambda event:
                            mousePressedWrapper(event, canvas, data))
    root.bind("<Key>", lambda event:
                            keyPressedWrapper(event, canvas, data))
    timerFiredWrapper(canvas, data)
    # and launch the app
    root.mainloop()  # blocks until window is closed
    print("bye!")

#run(500, 500)








