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 colours to test runner

+10 -4
+10 -4
test.py
··· 15 15 16 16 def human_time(timespan): 17 17 """Formats the timespan in a human readable format""" 18 - if timespan >= 1.0: 19 - return '%.*g s' % (3, timespan * 1.0) 18 + if timespan >= 10.0: 19 + return '\033[91m%.3g s\033[0m' % timespan 20 + elif timespan >= 2.0: 21 + return '\033[93m%.3g s\033[0m' % (timespan * 1.0) 20 22 else: 21 - return '%.*g ms' % (3, timespan * 1e3) 23 + return '%.3g ms' % (timespan * 1e3) 22 24 23 25 24 26 def check_solution(program, input_file, output_file): ··· 37 39 return True, cpu_usr 38 40 39 41 42 + def mark(valid): 43 + return '\033[92m✓\033[0m' if valid else '\033[91m✗\033[0m' 44 + 45 + 40 46 def main(): 41 47 exit_code = 0 42 48 ··· 47 53 48 54 if os.path.exists(output_file): 49 55 valid, cpu_usr = check_solution(program, input_file, output_file) 50 - print '{} Day {:02} ({})'.format('✓' if valid else '✗', day, human_time(cpu_usr)) 56 + print '{} Day {:02} ({})'.format(mark(valid), day, human_time(cpu_usr)) 51 57 52 58 if not valid: 53 59 exit_code = 1