# Read lines lines = [] with open("10.input") as f: for line in f.readlines(): lines.append(int(line.strip())) lines.sort() current = 0 diffs = [0, 0, 0, 0] for next in lines: diffs[next - current] += 1 current = next diffs[3] += 1 # Device joltage print("Answer 1: " + str(diffs[1] * diffs[3])) count_from = {} count_from[max(lines)] = 1 lines.reverse() lines.pop(0) for current in lines + [0]: count_from[current] = 0 for i in range(1, 4): count_from[current] += count_from.get(current + i, 0) print("Answer 2: " + str(count_from[0]))