scy @scy@chaos.social · activity timestamp 21 min. ago Advent of Code 2026-12-01 solution in Python Show Hide I like this.#AdventOfCode #Python Read more Read less Translate Translate Media Hidden alt Screenshot of eleven lines of code: import collections import math import sys counts = collections.Counter(int(line) for line in sys.stdin) sorted_counts = {id: n for id, n in sorted(counts.items(), key=lambda item: item[1])} sorted_ids = list(sorted_counts.keys()) print(f"Part 1: {math.prod(sorted_ids[-3:])}") print(f"Part 2: {math.prod(sorted_ids[:3])}") Screenshot of eleven lines of code: import collections import math import sys counts = collections.Counter(int(line) for line in sys.stdin) sorted_counts = {id: n for id, n in sorted(counts.items(), key=lambda item: item[1])} sorted_ids = list(sorted_counts.keys()) print(f"Part 1: {math.prod(sorted_ids[-3:])}") print(f"Part 2: {math.prod(sorted_ids[:3])}") #adventofcode #python Reply Boost Quote Like More actions Copy link Share View remotely Get latest replies Flag this post Block
Media Hidden alt Screenshot of eleven lines of code: import collections import math import sys counts = collections.Counter(int(line) for line in sys.stdin) sorted_counts = {id: n for id, n in sorted(counts.items(), key=lambda item: item[1])} sorted_ids = list(sorted_counts.keys()) print(f"Part 1: {math.prod(sorted_ids[-3:])}") print(f"Part 2: {math.prod(sorted_ids[:3])}") Screenshot of eleven lines of code: import collections import math import sys counts = collections.Counter(int(line) for line in sys.stdin) sorted_counts = {id: n for id, n in sorted(counts.items(), key=lambda item: item[1])} sorted_ids = list(sorted_counts.keys()) print(f"Part 1: {math.prod(sorted_ids[-3:])}") print(f"Part 2: {math.prod(sorted_ids[:3])}")
scy @scy@chaos.social · activity timestamp 15 min. ago Advent of Code 2026-12-01 solution in Unix Shell Show Hide Part 1:sort -n input.txt | uniq -c | sort -nk 1 | tail -n 3 | awk 'BEGIN { prod = 1 }; { prod *= $2 }; END { print prod }'For part 2, replace tail with head.#AdventOfCode #ShellScript #bash Read more Read less Translate Translate Reply Boost Quote Like More actions Copy link Share Flag this comment Block
Part 1:
sort -n input.txt | uniq -c | sort -nk 1 | tail -n 3 | awk 'BEGIN { prod = 1 }; { prod *= $2 }; END { print prod }'
For part 2, replace tail with head.
#AdventOfCode #ShellScript #bash