]> www.fi.muni.cz Git - aoc.git/blobdiff - 2022/35.pl
Day 18: interesting
[aoc.git] / 2022 / 35.pl
diff --git a/2022/35.pl b/2022/35.pl
new file mode 100755 (executable)
index 0000000..4a32d29
--- /dev/null
@@ -0,0 +1,19 @@
+#!/usr/bin/perl -w
+
+use v5.36;
+use strict;
+
+my @cubes = map { [ /(\d+)/g ] } <>;
+my %cubes = map { join(',', @$_) => 1 } @cubes;
+
+my $common;
+for my $cube (@cubes) {
+       for my $axis (0 .. 2) {
+               for my $add (-1, 1) {
+                       my @neigh = @$cube;
+                       $neigh[$axis] += $add;
+                       $common++ if $cubes{join(',', @neigh)};
+               }
+       }
+}
+say 6*@cubes - $common;