Skip to content

Commit

Permalink
advent of code 2024 day 1 problem 1
Browse files Browse the repository at this point in the history
  • Loading branch information
Vicfred committed Dec 5, 2024
1 parent a25ee4a commit 6e855d5
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions aoc/aoc2024day01historianhysteria.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import std.algorithm;
import std.stdio;

long abs(long x) {
if(x < 0) {
return -x;
}
return x;
}

void main() {
auto input = File("input.txt");
long[] u;
long[] v;
long answer = 0;
while(!input.eof()) {
long x, y;
input.readf("%d %d\n", &x, &y);
if(!input.eof()) {
u ~= x;
v ~= y;
}
}
u.sort;
v.sort;
for(long i = 0; i < 1000; ++i) {
answer += abs(u[i] - v[i]);
}
answer.writeln;
}

0 comments on commit 6e855d5

Please sign in to comment.