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.

Update test.py

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