Skip to content

Instantly share code, notes, and snippets.

View gayalkuruppu's full-sized avatar
🏠
Working from home

gayalkuruppu

🏠
Working from home
View GitHub Profile
@gayalkuruppu
gayalkuruppu / gist:e54bd306cea630d3c41d80cb5387c054
Created November 2, 2019 15:33
Number partition in Python
def partition(n, c=[], k=1):
if n == 0:
yield c
for i in range(k, n + 1):
for p in partition(n - i, c + [i], i):
yield p
# Example: Partition 10 as a sum of integers
for j in partition(10):
print ' + '.join(map(str, j))