Skip to content

Instantly share code, notes, and snippets.

@ariG23498
Created May 10, 2020 12:45
Show Gist options
  • Save ariG23498/9e8d6ea6f7e06e3661344773f2770f41 to your computer and use it in GitHub Desktop.
Save ariG23498/9e8d6ea6f7e06e3661344773f2770f41 to your computer and use it in GitHub Desktop.
Foobar problem on staircase
def print_util(mat):
for i in mat:
for j in i:
print(j, end=" ")
print()
def solution(number):
mat = [[0 for i in range(number+1)] for i in range(number+1)]
mat[0][0] = 1
# The first row is skipped
for summands in range(1,number+1):
for sums in range(number+1):
mat[summands][sums] = mat[summands-1][sums]
if sums >= summands:
mat[summands][sums] += mat[summands-1][sums - summands]
return mat[-1][-1] -1
print_util(mat)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment