jumboframe

Untitled

Jun 24th, 2021
499
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def get_magic_triangle(n):
  2.     inner_matrix = []
  3.  
  4.     def upper_sum(r, c):
  5.         if r == 0: return 1
  6.         if c == 0: return 1
  7.         if c == len(inner_matrix[r-1]): return 1
  8.  
  9.         return inner_matrix[r-1][c-1] + inner_matrix[r - 1][c]
  10.  
  11.     for row in range(n):
  12.         inner_matrix.append([1])
  13.         for col in range(1, row + 1):
  14.             inner_matrix[row].append(upper_sum(row, col))
  15.     return inner_matrix
RAW Paste Data