My Advent of Code solutions in Python. kevinyap.ca/2019/12/going-fast-in-advent-of-code/
advent-of-code python
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Print total runtime for multiple puzzles

+13 -3
+13 -3
advent.py
··· 52 52 end = clock() 53 53 cpu_usr = end - start 54 54 55 + valid = True 56 + 55 57 with open(output_file) as f: 56 58 for line in f: 57 59 if line.strip() not in stdout: 58 - return False, stdout, cpu_usr 59 - else: 60 - return True, stdout, cpu_usr 60 + valid = False 61 + break 62 + 63 + return valid, stdout, cpu_usr 61 64 62 65 63 66 if __name__ == '__main__': ··· 74 77 else: 75 78 programs = glob.glob('%s/day*.py' % year) 76 79 80 + total_runtime = 0 81 + 77 82 for program in programs: 78 83 day = int(re.findall(r'(\d+).py', program)[0]) 79 84 input_file = '%s/inputs/%02i.txt' % (year, day) ··· 81 86 82 87 if os.path.exists(output_file): 83 88 valid, stdout, cpu_usr = check_solution(program, day, input_file, output_file) 89 + total_runtime += cpu_usr 90 + 84 91 print '{}{}{} Day {:02} ({})'.format( 85 92 bcolors.OKGREEN if valid else bcolors.FAIL, 86 93 '✓' if valid else '✗', ··· 92 99 93 100 if not valid: 94 101 exit_code = 1 102 + 103 + if len(sys.argv) <= 2: 104 + print "Total runtime:", format_time(total_runtime) 95 105 96 106 sys.exit(exit_code)