From e2fca96cdb4778318cae541e0ebfc3a76370422a Mon Sep 17 00:00:00 2001 From: Leah Neukirchen Date: Fri, 6 Dec 2019 15:58:53 +0100 Subject: day04 --- day04.pl | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 day04.pl (limited to 'day04.pl') diff --git a/day04.pl b/day04.pl new file mode 100644 index 0000000..f1137dc --- /dev/null +++ b/day04.pl @@ -0,0 +1,21 @@ +#!/usr/bin/perl -w +use v5.16; + +my $d = "171309-643603"; + +my ($a, $b) = split "-", $d; + +my $p1 = 0; +my $p2 = 0; + +PASS: for ($a..$b) { + my @ds = split(''); + + if (join('',@ds) eq join('',sort(@ds))) { + $p1++ if /(\d)\1/; + while (/(\d)\1+/g) { $p2++, next PASS if length($&) == 2; } + } +} + +say $p1; # 1625 +say $p2; # 1111 -- cgit 1.4.1