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 usage documentation to test.py

+26 -26
+26 -26
test.py
··· 52 52 def main(): 53 53 exit_code = 0 54 54 55 - if len(sys.argv) > 1: 56 - years = [sys.argv[1]] 57 - else: 58 - years = ['2015', '2016'] 55 + if len(sys.argv) == 1: 56 + print "Usage: ./test.py <year> [problem]" 57 + sys.exit() 59 58 60 - for year in years: 61 - if len(sys.argv) > 2: 62 - programs = glob.glob('%s/day%02i.py' % (year, int(sys.argv[2]))) 63 - else: 64 - programs = glob.glob('%s/day*.py' % year) 59 + year = sys.argv[1] 65 60 66 - for program in programs: 67 - day = int(re.findall(r'(\d+).py', program)[0]) 68 - input_file = '%s/inputs/%02i.txt' % (year, day) 69 - output_file = '%s/outputs/%02i.txt' % (year, day) 61 + if len(sys.argv) > 2: 62 + programs = glob.glob('%s/day%02i.py' % (year, int(sys.argv[2]))) 63 + else: 64 + programs = glob.glob('%s/day*.py' % year) 70 65 71 - if os.path.exists(output_file): 72 - valid, stdout, cpu_usr = check_solution(program, input_file, output_file) 73 - print '{}{}{} {} Day {:02} ({})'.format( 74 - bcolors.OKGREEN if valid else bcolors.FAIL, 75 - '✓' if valid else '✗', 76 - bcolors.ENDC, 77 - year, 78 - day, 79 - format_time(cpu_usr), 80 - ) 81 - print stdout 66 + for program in programs: 67 + day = int(re.findall(r'(\d+).py', program)[0]) 68 + input_file = '%s/inputs/%02i.txt' % (year, day) 69 + output_file = '%s/outputs/%02i.txt' % (year, day) 82 70 83 - if not valid: 84 - exit_code = 1 71 + if os.path.exists(output_file): 72 + valid, stdout, cpu_usr = check_solution(program, input_file, output_file) 73 + print '{}{}{} {} Day {:02} ({})'.format( 74 + bcolors.OKGREEN if valid else bcolors.FAIL, 75 + '✓' if valid else '✗', 76 + bcolors.ENDC, 77 + year, 78 + day, 79 + format_time(cpu_usr), 80 + ) 81 + print stdout 82 + 83 + if not valid: 84 + exit_code = 1 85 85 86 86 sys.exit(exit_code) 87 87