diff --git a/2024/01/01.py b/2024/01/01.py new file mode 100755 index 0000000..f730c92 --- /dev/null +++ b/2024/01/01.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python3 + +INPUT_FILE = 'input.txt' + +def main(): + left, right = [], [] + contents = open(INPUT_FILE, 'r').readlines() + for line in contents: + fields = line.split(' ') + left.append(int(fields[0])) + right.append(int(fields[-1])) + left.sort() + right.sort() + diff_sum = 0 + for pair in list(zip(left, right)): + diff_sum += abs(pair[0] - pair[1]) + print(diff_sum) + + +if __name__ == '__main__': + main() diff --git a/2024/01/02.py b/2024/01/02.py new file mode 100755 index 0000000..2bbf4e7 --- /dev/null +++ b/2024/01/02.py @@ -0,0 +1,19 @@ +#!/usr/bin/env python3 + +INPUT_FILE = 'input.txt' + +def main(): + left, right = [], [] + contents = open(INPUT_FILE, 'r').readlines() + for line in contents: + fields = line.split(' ') + left.append(int(fields[0])) + right.append(int(fields[-1])) + similarity = 0 + for id in left: + similarity += id * right.count(id) + print(similarity) + + +if __name__ == '__main__': + main()