Created
February 8, 2021 08:06
-
-
Save ashleighbasil/97ad1d1113e5cfbe19e71461e0d62a00 to your computer and use it in GitHub Desktop.
ProductList solution to cassidoo puzzle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
class ProductList: | |
def __init__(self): | |
self.numbers = [] | |
def add(self, number): | |
self.numbers.append(number) | |
def product(self, m): | |
factors = self.numbers[::-1][:m] | |
return math.prod(factors) | |
pl = ProductList() | |
pl.add(1) | |
pl.add(2) | |
pl.add(3) | |
pl.add(4) | |
prod_3 = pl.product(3) | |
prod_2 = pl.product(2) | |
print(prod_2, prod_3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment