Last active
December 2, 2024 15:41
-
-
Save thepeopleseason/1fbcd01cdfd547b925fe16e06664c3b7 to your computer and use it in GitHub Desktop.
AOC 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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