###############################################################################
# ---------------- 15-112 Recitation #5: 1D lists ---------------- #

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

# --------------------------------------------------------------------------- #
###############################################################################
# Code Tracing
###############################################################################
# LEARNING OBJECTIVES
# What are lists?
# How do we do a code tracing problem with lists?
# What is aliasing?
# What is copying?
# How does indexing and slicing work with lists?
# What are destructive vs. non-destructive functions?
# What is list comprehension?

import copy
def ct(a):
	b = copy.copy(a)
	c = a[1:3]
	d = [2*i for i in range(len(a))]
	a[0] = 4
	b[0] = a[2]
	c[0] = b[0]
	d[0] = a[0]
	print(a[0], b[0], c[0], d[0])
	c = a
	d += [5]
	c[1] = "yeet"
	d = d + c[:2]
	b[0] += 8
	a[2] = 12
	c[3] = a[0] + d[0]
	d[1] = "summer"
	print(a)
	print(b)
	print(c)
	print(d)

a = [1, 2, 3, 4]
# print(ct(a))
# print(a)

###############################################################################
# Longest Odd Run
###############################################################################
# LEARNING OBJECTIVES
# How do we evaluate a list input?
# How do we use tuples?

'''
Write the function longestOddRun(L) that takes in a 1D list L and returns a tuple 
containing the length of the longest run of odd numbers and a list containing the 
elements in the longest run of odd numbers. So, longestOddRun([2, 3, 9, 5, 6, 1, 7]) 
should return (3, [3, 9, 5]).
'''

def longestOddRun(L):
	return (42, [42])

###############################################################################
# Multiply Polynomials
###############################################################################
# LEARNING OBJECTIVES
# How do we work in python with lists?
# How do we use indexing as a tool?
# How do we problem-solve with lists?

'''
Write the function multiplyPolynomials(p1, p2) which takes two polynomials 
(represented as lists) and returns a third polynomial which is the product of the two. 
For example, multiplyPolynomials([2,0,3], [4,5]) represents the multiplication
(2x^2+ 3)(4x + 5), which is evaluated as:
(2x^2 + 3)(4x + 5) = 8x^3 + 10x^2 + 12x + 15
And so this returns [8, 10, 12, 15].
'''

def multiplyPolynomials(p1, p2):
	return [42]
	

###############################################################################
# Multiply Polynomials
###############################################################################
#LEARNING OBJECTIVES
#How to do roc with 1D lists?


def rc1(M):
  assert(isinstance(M,  list) and (len(M) ==  5))
  for i in range(-1, 3):
    assert(M[i] == M[i-1] + i)
  return  (sum(M) ==  15)

print(rc1("42"))