From 1e20c2a640f52a07265c20dd940c6c0430461909 Mon Sep 17 00:00:00 2001 From: Yanick Champoux Date: Tue, 5 Dec 2017 12:47:11 -0500 Subject: [PATCH] day11 --- 2015/11/1.pl | 19 +++++++++++++++++++ 2015/11/2.pl | 20 ++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 2015/11/1.pl create mode 100644 2015/11/2.pl diff --git a/2015/11/1.pl b/2015/11/1.pl new file mode 100644 index 0000000..1fdb110 --- /dev/null +++ b/2015/11/1.pl @@ -0,0 +1,19 @@ +use 5.20.0; +use experimental 'signatures'; + +my $alpha = join '', 'a'..'z'; +my $seq = join '|', map { substr $alpha, $_, 3 } 0..length($alpha)-3; +$seq = qr/$seq/; + + +my $password = <>; +chomp($password); + +1 until is_valid(++$password); +say $password; + +sub is_valid($p) { + return 0 if $p =~ /[iol]/; + return 0 unless $p =~ /(.)\1.*?(.)\2/; + return $p =~ $seq; +} diff --git a/2015/11/2.pl b/2015/11/2.pl new file mode 100644 index 0000000..94f71c4 --- /dev/null +++ b/2015/11/2.pl @@ -0,0 +1,20 @@ +use 5.20.0; +use experimental 'signatures'; + +my $alpha = join '', 'a'..'z'; +my $seq = join '|', map { substr $alpha, $_, 3 } 0..length($alpha)-3; +$seq = qr/$seq/; + + +my $password = <>; +chomp($password); + +1 until is_valid(++$password); +1 until is_valid(++$password); +say $password; + +sub is_valid($p) { + return 0 if $p =~ /[iol]/; + return 0 unless $p =~ /(.)\1.*?(.)\2/; + return $p =~ $seq; +}