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.

Add selective puzzle testing to test runner

+20 -9
+20 -9
test.py
··· 42 42 def main(): 43 43 exit_code = 0 44 44 45 - for program in glob.glob('2016/day*.py'): 46 - day = int(re.findall(r'(\d+).py', program)[0]) 47 - input_file = '2016/inputs/%02i.txt' % day 48 - output_file = '2016/outputs/%02i.txt' % day 45 + if len(sys.argv) > 1: 46 + years = [sys.argv[1]] 47 + else: 48 + years = ['2015', '2016'] 49 + 50 + for year in years: 51 + if len(sys.argv) > 2: 52 + programs = glob.glob('%s/day%02i.py' % (year, int(sys.argv[2]))) 53 + else: 54 + programs = glob.glob('%s/day*.py' % year) 55 + 56 + for program in programs: 57 + day = int(re.findall(r'(\d+).py', program)[0]) 58 + input_file = '%s/inputs/%02i.txt' % (year, day) 59 + output_file = '%s/outputs/%02i.txt' % (year, day) 49 60 50 - if os.path.exists(output_file): 51 - valid, cpu_usr = check_solution(program, input_file, output_file) 52 - print '{} Day {:02} ({})'.format('✓' if valid else '✗', day, format_time(cpu_usr)) 61 + if os.path.exists(output_file): 62 + valid, cpu_usr = check_solution(program, input_file, output_file) 63 + print '{} {} Day {:02} ({})'.format('✓' if valid else '✗', year, day, format_time(cpu_usr)) 53 64 54 - if not valid: 55 - exit_code = 1 65 + if not valid: 66 + exit_code = 1 56 67 57 68 sys.exit(exit_code) 58 69