From dc163fd4a2f087d7aa4f35291a92d5efcd22c9ae Mon Sep 17 00:00:00 2001 From: vicfred Date: Wed, 4 Dec 2024 22:03:16 -0800 Subject: [PATCH] advent of code 2024 day 1 problem 2 --- ...ria.d => aoc2024day01historianhysteria1.d} | 0 aoc/aoc2024day01historianhysteria2.d | 27 +++++++++++++++++++ 2 files changed, 27 insertions(+) rename aoc/{aoc2024day01historianhysteria.d => aoc2024day01historianhysteria1.d} (100%) create mode 100644 aoc/aoc2024day01historianhysteria2.d diff --git a/aoc/aoc2024day01historianhysteria.d b/aoc/aoc2024day01historianhysteria1.d similarity index 100% rename from aoc/aoc2024day01historianhysteria.d rename to aoc/aoc2024day01historianhysteria1.d diff --git a/aoc/aoc2024day01historianhysteria2.d b/aoc/aoc2024day01historianhysteria2.d new file mode 100644 index 0000000..d533bd4 --- /dev/null +++ b/aoc/aoc2024day01historianhysteria2.d @@ -0,0 +1,27 @@ +import std.algorithm; +import std.stdio; + +long abs(long x) { + if(x < 0) { + return -x; + } + return x; +} + +void main() { + long MAXN = 1000; + auto input = File("input.txt"); + long[1000] u; + long[1000000] v; + long answer = 0; + for(long i = 0; i < MAXN; ++i) { + long x, y; + readf("%d %d\n", &x, &y); + u[i] = x; + v[y] += 1; + } + for(long i = 0; i < MAXN; ++i) { + answer += u[i]*v[u[i]]; + } + answer.writeln; +}