]> www.fi.muni.cz Git - aoc.git/blobdiff - 2016/18.pl
Year 2016, days 1-10: so far pretty interesting
[aoc.git] / 2016 / 18.pl
diff --git a/2016/18.pl b/2016/18.pl
new file mode 100755 (executable)
index 0000000..c1eef09
--- /dev/null
@@ -0,0 +1,21 @@
+#!/usr/bin/perl -w
+
+use strict;
+use v5.30;
+
+sub str_len {
+       my ($in) = @_;
+       my $l = 0;
+       while ($in) {
+               $l++ while $in =~ s/\A[A-Z]//;
+               next if $in !~ /\A\((\d+)x(\d+)\)/;
+               my $str = substr($in, length("($1x$2)"), $1);
+               substr($in, 0, length("($1x$2)") + $1) = '';
+               my $c = $2;
+               $l += $c * str_len($str);
+       }
+       return $l;
+}
+
+chomp (my $in = <>);
+say str_len($in);