pyramids.py - from time import perf_counter import sys...

This preview shows page 1 out of 1 page.

from time import perf_counter import sys cache = {} def weightOn(row, column, weight = 200): if row == 0: return 0.00 elif column == 0: if (row, column) in cache.keys(): return cache[(row,column)] else: newWeight = (weightOn(row-1, column, weight) + weight) / 2 cache[(row,column)] = newWeight return newWeight elif column == row: if (row, column) in cache.keys(): return cache[(row,column)] else: newWeight = (weightOn(row - 1, column - 1, weight) + weight) / 2 cache[(row,column)] = newWeight return newWeight else: if (row, column) in cache.keys(): return cache[(row,column)] else: newWeight = (weight + (weightOn(row - 1, column - 1, weight)/2) + (weightOn(row - 1, column, weight)) / 2) cache[(row,column)] = newWeight return newWeight def main(pyramidHeight):

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture