def task_1(raw_data): data = list(utils.parse_int_data(raw_data)) freqs = get_difference_frequency(data) prod_1x3 = freqs[1] * freqs[3] print("Joltage differences: ", freqs) print(f"Product of 1 and 3 differences: {prod_1x3}") return prod_1x3
def test_add_number(example_lut_5, n, expected): data = parse_int_data(EXAMPLE_DATA) nn = NumberList(data, 5) nn.sums = example_lut_5 nn._add_number(n) for i, line_num in enumerate(nn.sums): for j, sum_val in enumerate(line_num): assert expected[i][j] == sum_val
def task_2(raw_data): data = list(utils.parse_int_data(raw_data)) tgt = max(data) + 3 data += [tgt] data.sort() scores = defaultdict(int) scores[0] = 1 for d in data: scores[d] = scores[d - 3] + scores[d - 2] + scores[d - 1] print(f"Total number of valid arrangements is {scores[data[-1]]}")
def test_has_sum(example_lut_5, n, expected): data = parse_int_data(EXAMPLE_DATA) nn = NumberList(data, 5) nn.sums = example_lut_5 assert nn._has_sum(n) is expected
def test_sum_lut_initialisation(size, expected): data = parse_int_data(EXAMPLE_DATA) nn = NumberList(data, size) for i, line_num in enumerate(nn.sums): for j, sum_val in enumerate(line_num): assert expected[i][j] == sum_val
def test_is_possible_limits(min_num, max_num, x, expected): data = parse_int_data(EXAMPLE_DATA) nn = NumberList(data, 5) nn.current_min = min_num nn.current_max = max_num assert nn._is_possible_with_limits(x) is expected
def test_get_diff_freq(raw_data, expected_freq_1, expected_freq_3): data = list(utils.parse_int_data(raw_data)) freq = get_difference_frequency(data) assert freq[1] == expected_freq_1 assert freq[3] == expected_freq_3
def task_2(raw_data, target): data = utils.parse_int_data(raw_data) cs = ConsecutiveSum(data, target) return cs.run()
def task_1(raw_data, preamble_length): data = utils.parse_int_data(raw_data) nn = NumberList(data, preamble_length) return nn.run()