def validate_eyr(self): min_value = 2020 max_value = 2030 value = self.fields.get(EYR) if len(value) == 4 and is_int(value): return min_value <= int(value) <= max_value return False
def validate_byr(self): min_value = 1920 max_value = 2002 value = self.fields.get(BYR) if len(value) == 4 and is_int(value): return min_value <= int(value) <= max_value return False
def build_combo(data): buses = [] bus_data = data.split(",") for i in range(len(bus_data)): if is_int(bus_data[i]): buses.append(ComboBus(int(bus_data[i]), i, 0)) return buses
def validate_hgt(self): value = self.fields.get(HGT) if len(value) >= 4: if value[-2:] == "cm": min_value = 150 max_value = 193 elif value[-2:] == "in": min_value = 59 max_value = 76 else: return False if is_int(value[:-2]): return min_value <= int(value[:-2]) <= max_value
def calculate_expression(exp, index): result = 0 operation = OPERATIONS["+"] i = index while i < len(exp): arg = exp[i] if is_int(arg): result = operation(result, int(arg)) elif arg == OPEN_EXP: new_result, new_index = calculate_expression(exp, i + 1) result = operation(result, new_result) i = new_index elif arg == CLOSE_EXP: return result, i else: operation = OPERATIONS[arg] i += 1 return result, index
def calculate_expression_b(exp, index): # TODO - convert args and operation in single line expression args = [] operations = [] i = index while i < len(exp): arg = exp[i] if is_int(arg): args.append(int(arg)) elif arg == OPEN_EXP: exp_result, new_index = calculate_expression(exp, i + 1) args.append(int(exp_result)) i = new_index elif arg == CLOSE_EXP: return calculate(args, operations), i else: operations.append(arg) i += 1 return calculate(args, operations), i
def validate_pid(self): value = self.fields.get(PID) return len(value) == 9 and is_int(value)
def run_a(input_data): client_time = int(input_data[0]) buses = [Bus(int(arg)) for arg in input_data[1].split(",") if is_int(arg)] bus, depart_time = get_earliest_depart(buses, client_time) result = (depart_time - client_time) * bus.interval return [result]