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.

Display spinner if Halo is installed

+19 -8
+19 -8
advent.py
··· 8 8 import resource 9 9 import subprocess 10 10 11 + try: 12 + from halo import Halo 13 + except ImportError: 14 + # Use a noop context manager if Halo isn't installed 15 + from contextlib import contextmanager 16 + 17 + @contextmanager 18 + def Halo(text): 19 + yield 20 + 11 21 12 22 class bcolors: 13 23 HEADER = '\033[95m' ··· 33 43 return '{:.3g} ms'.format(timespan * 1e3) 34 44 35 45 36 - def check_solution(program, input_file, output_file): 37 - cmd = ['python', program, input_file] 38 - start = clock() 39 - proc = subprocess.Popen(cmd, stdout=subprocess.PIPE) 40 - stdout = proc.communicate()[0] 41 - end = clock() 42 - cpu_usr = end - start 46 + def check_solution(program, day, input_file, output_file): 47 + with Halo(text='2017 Day {:02}'.format(day)): 48 + cmd = ['python', program, input_file] 49 + start = clock() 50 + proc = subprocess.Popen(cmd, stdout=subprocess.PIPE) 51 + stdout = proc.communicate()[0] 52 + end = clock() 53 + cpu_usr = end - start 43 54 44 55 with open(output_file) as f: 45 56 for line in f: ··· 69 80 output_file = '%s/outputs/%02i.txt' % (year, day) 70 81 71 82 if os.path.exists(output_file): 72 - valid, stdout, cpu_usr = check_solution(program, input_file, output_file) 83 + valid, stdout, cpu_usr = check_solution(program, day, input_file, output_file) 73 84 print '{}{}{} {} Day {:02} ({})'.format( 74 85 bcolors.OKGREEN if valid else bcolors.FAIL, 75 86 '✓' if valid else '✗',