commit 29df2e335cb55dba93041e45c05e50a2a9ce0fd6
parent 85a4de52f53459ef3f5015785f9deaf5a74564f1
Author: Samir Parikh <noreply@samirparikh.com>
Date: Fri, 4 Nov 2022 20:40:22 +0000
start to solve part 1 of day 13
Diffstat:
A | day13/day13.pl | | | 51 | +++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 file changed, 51 insertions(+), 0 deletions(-)
diff --git a/day13/day13.pl b/day13/day13.pl
@@ -0,0 +1,51 @@
+#!/usr/local/bin/perl
+# day 2015-13
+
+use strict;
+use warnings;
+use v5.32;
+
+@ARGV = "input" unless @ARGV;
+
+chomp( my $input = do { local $/; <> } );
+
+use List::Util qw( min sum product );
+use Algorithm::Permute;
+use Data::Dumper;
+
+my @deltas = split /\n/, $input;
+my %people;
+my %hap_units;
+
+foreach ( @deltas ) {
+# say;
+# my @matches =
+# m/(\w+) would (gain|lose) (\d+) happiness units by sitting next to (\w+)./;
+ my ( $person, $gain_lose, $units, $neighbor ) =
+ m/(\w+) would (gain|lose) (\d+) happiness units by sitting next to (\w+)./;
+# say join " | ", @matches;
+# $hap_units{ $matches[0] }{ $matches[3] } = $matches[1] eq 'gain' ? $matches[2] : -1 * $matches[2];
+ $hap_units{ $person }{ $neighbor } =
+ $gain_lose eq 'gain' ? $units : -1 * $units;
+ $people{ $person } += 1;
+}
+
+my @people = sort keys %people;
+#say "part 1: ";
+#say "part 2: ";
+
+#say Dumper \%hap_units;
+
+foreach my $person ( keys %hap_units ) {
+ foreach my $neighbor ( keys %{ $hap_units{ $person } } ) {
+ say "sitting $person next to $neighbor would net ",
+ $hap_units{ $person }{ $neighbor }, " points.";
+ }
+}
+
+say @people;
+say "-------------";
+
+Algorithm::Permute::permute {
+ say @people;
+} @people;