Skip to content

Instantly share code, notes, and snippets.

@thepeopleseason
Last active December 2, 2024 15:41
Show Gist options
  • Select an option

  • Save thepeopleseason/1fbcd01cdfd547b925fe16e06664c3b7 to your computer and use it in GitHub Desktop.

Select an option

Save thepeopleseason/1fbcd01cdfd547b925fe16e06664c3b7 to your computer and use it in GitHub Desktop.
AOC 2024
#!/usr/bin/perl -pl
BEGIN {
my @ll, @rl;
my $sum, $sim;
}
END {
my ($sl, $sr) = ([sort {$a <=> $b} @ll], [sort {$a <=> $b} @rl]);
for ($x=0; $x<=$#ll; $x++) {
$sum += abs($sl->[$x] - $sr->[$x]);
$sim += $ll[$x] * scalar grep {$_ == $ll[$x]} @$sr;
}
print "Distance: $sum\tSimilarity: $sim";
}
($ll[$.-1], $rl[$.-1]) = split(/\s+/, $_);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment