copy pasting the rules from last year’s thread:
Rules: no spoilers.
The other rules are made up aswe go along.
Share code by link to a forge, home page, pastebin (Eric Wastl has one here) or code section in a comment.
copy pasting the rules from last year’s thread:
Rules: no spoilers.
The other rules are made up aswe go along.
Share code by link to a forge, home page, pastebin (Eric Wastl has one here) or code section in a comment.
Advent of Code is one of these things I wanna do every year and then I end up in fucking end-of-the-year crunch time every December and work for 10-12 hours and really don’t wanna code after work anymore.
But hey, here’s a quick solution for day 1. Let’s see how far I make it.
Day 1
use strict; use List::Util qw( min max ); open(FH, '<', $ARGV[0]) or die $!; my @left; my @right; while (<FH>) { my @nums = split /\s+/, $_; push(@left, $nums[0]); push(@right, $nums[1]); } @left = sort { $b <=> $a } @left; @right = sort { $b <=> $a } @right; my $dist = 0; my $sim = 0; my $i = 0; foreach my $lnum (@left) { $sim += $lnum * grep { $_ == $lnum } @right; my $rnum = $right[$i++]; $dist += max($lnum, $rnum) - min($lnum, $rnum); } print 'Part 1: ', $dist, "\n"; print 'Part 2: ', $sim, "\n"; close(FH);