This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 | |