import numpy as np
with open("/Users/vlandeiro/Downloads/input.txt") as fd:
input = np.array([int(line) for line in fd])
input = np.sort(input)
input
input_removed_once = 2020 - input
input_removed_once
set(2020 - input) & set(input)
456 * 1564
input_removed_twice = np.repeat([2020 - input], input.size, axis=0)
input_removed_twice = (input_removed_twice - input.reshape(-1, 1)).ravel()
input_removed_twice = input_removed_twice[input_removed_twice > 0]
input_removed_twice
set(input_removed_twice) & set(input)
399 * 764 * 857
import numpy as np
from collections import Counter
with open("/Users/vlandeiro/Downloads/day2_input.txt") as fd:
valid_count = 0
for line in fd:
parts = line.strip().split(" ")
min_count, max_count = [int(x) for x in parts[0].split("-")]
letter = parts[1][0]
password = parts[2]
letter_counts = Counter(password)
if letter_counts[letter] >= min_count and letter_counts[letter] <= max_count:
valid_count += 1
print(valid_count)
import numpy as np
with open("/Users/vlandeiro/Downloads/day2_input.txt") as fd:
valid_count = 0
for line in fd:
parts = line.strip().split(" ")
pos1, pos2 = [int(x) - 1 for x in parts[0].split("-")]
letter = parts[1][0]
password = parts[2]
if (password[pos1] == letter) != (password[pos2] == letter):
valid_count += 1
print(valid_count)