def get_problems(days, parts, all_days_parts=False): problems = [] if all_days_parts: problems = get_all_problems() elif days and parts: problems = [ problem for problem in get_all_problems(days) if problem.part in parts ] elif days: problems = get_all_problems(days) elif parts: latest = get_latest_problem() if not latest: return [] problems = [ Problem(latest.day, part) for part in get_parts_for_day(latest.day) if part in parts ] else: latest = get_latest_problem() if latest: problems = [ Problem(latest.day, part) for part in get_parts_for_day(latest.day) ] return sorted(problems, key=lambda p: (p.day, p.part))
def get_parts_for_day(day): return sorted( list( map( lambda x: int(x[-1]), list( glob.glob( os.path.join(Problem.day_to_path(day), _PART_PATH_PATTERN))))))
def get_latest_problem(): days = get_all_days() if not days: return latest_day = days[-1] parts = get_parts_for_day(latest_day) if not parts: return latest_part = parts[-1] return Problem(latest_day, latest_part)
def get_all_problems(days=None): if not days: days = get_all_days() if not days: return [] problems = [] for day in days: for part in get_parts_for_day(day): problems.append(Problem(day, part)) return problems