Skip to content

Instantly share code, notes, and snippets.

@pyrofolium
Last active June 12, 2020 06:17
Show Gist options
  • Save pyrofolium/c3a32e8220c3a20c0dc001f232733b1a to your computer and use it in GitHub Desktop.
Save pyrofolium/c3a32e8220c3a20c0dc001f232733b1a to your computer and use it in GitHub Desktop.
from typing import List
#lengths
def test_max_prod(total: int, acc = None) -> List[int]:
if acc is None:
acc = []
if total == 0:
return acc
else:
max_list = []
for i in range(1, total + 1):
current_list = test_max_prod(total - i, acc + [i])
max_list = max(max_list, current_list, key = lambda x: (product(x), -len(x)))
return max_list
#product
def test_max_prod(total: int) -> int:
return 1 if total == 0 else max([i * test_max_prod(total - i) for i in range(1, total + 1)])
#number of cuts
def test_max_prod3(total: int) -> int:
return 0 if total == 0 else max([1 + test_max_prod(total - i) for i in range(1, total + 1)])
def product(x: List[int]) -> int:
if len(x) == 0:
return 1
else:
return x[0] * product(x[1:])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment