Skip to content

Instantly share code, notes, and snippets.

View nlehrer's full-sized avatar

Nathan Lehrer nlehrer

  • Google
  • New York, NY
View GitHub Profile
# Nathan Lehrer
# CracklePop
for i in range(1,101):
output = ''
if i%3 == 0:
output += 'Crackle'
if i%5 == 0:
output += 'Pop'
if output == '':
output = i
@nlehrer
nlehrer / best_path.py
Created May 16, 2016 23:46
Best path through a grid of point values
# Nathan Lehrer
def get_best_path(grid):
# Finds the best path through an M x N grid of point values, and that path's score
# Input: grid = grid of point values = M x N list of lists
# Returns: best_score = best possible score = int, path = best possible path = string
M,N = len(grid),len(grid[0])
scores = {(0,0):grid[0][0]} # best score for a path to each cell; score of (0,0) is grid value
trace = {} # whether we optimally come from up ('U') or left ('L') into each cell