#!/bin/env rdmd module aoc24_1; import std.stdio, std.conv, std.algorithm, std.range, std.math, std.parallelism, std.string; void main(){ long[] left, right; long[long] rightCount; foreach(line; stdin.byLine){ long l = line.parse!long; line = line.strip(); long r = line.parse!long; left ~= l; right ~= r; if(r !in rightCount) rightCount[r] = 0; rightCount[r]++; } foreach(x; iota(0, 2).parallel){ if(x == 0) left.sort(); else right.sort(); } foreach(x; iota(0, 2).parallel){ if(x == 0) writeln("Part one ", zip(left, right).map!(x => abs(x[0] - x[1])).reduce!"a+b"); else writeln("Part two ", left.map!(l => rightCount.get(l, 0) * l).reduce!"a+b"); } }