aoc2015

Advent of Code 2015 solutions in Perl.
git clone git://git.samirparikh.com/aoc2015
Log | Files | Refs | README

Day11.pm (686B) - raw


      1 package Day11;
      2 
      3 use strict;
      4 use warnings;
      5 use v5.32;
      6 
      7 use Exporter qw( import );
      8 our @EXPORT = qw( is_valid_password );
      9 
     10 # create expression to match one increasing straight of at least three
     11 # letters, like abc, bcd, cde, and so on, up to xyz.
     12 my $number = ord( 'a' );
     13 my $inc_straight = join "|", map { chr ( $number + $_ ) .
     14                                    chr ( $number + $_ + 1 ) .
     15                                    chr ( $number + $_ + 2 ) } ( 0 .. 23 );
     16 
     17 sub is_valid_password {
     18     my $string = shift;
     19     return 0 if ( $string !~ m/$inc_straight/ ) ||
     20                 ( $string =~ m/[iol]/ )         ||
     21                 ( $string !~ m/(\w)\1.*(\w)\2/ );
     22     return 1;
     23 }
     24 
     25 1;