From 2a5f946613055b6d55466d6c77e8a85ecfd73942 Mon Sep 17 00:00:00 2001 From: Yanick Champoux Date: Sat, 20 Jan 2018 13:44:10 -0500 Subject: [PATCH] 2016-07 --- 2016/07/1.pl | 19 +++++++++++++++++++ 2016/07/2.pl | 26 ++++++++++++++++++++++++++ 2016/07/test | 3 +++ 3 files changed, 48 insertions(+) create mode 100644 2016/07/1.pl create mode 100644 2016/07/2.pl create mode 100644 2016/07/test diff --git a/2016/07/1.pl b/2016/07/1.pl new file mode 100644 index 0000000..387bc73 --- /dev/null +++ b/2016/07/1.pl @@ -0,0 +1,19 @@ +# 117 is too high +# 108 is too high + +use 5.20.0; +use experimental qw/ signatures /; +use List::AllUtils qw/ reduce none all any /; +use DDP; + +say scalar +grep { + any { has_sequence($_) } split /\[.*?\]/; +} +grep { + none { has_sequence($_) } /\[(.*?)\]/g; +} map { chomp; $_ } <>; + +sub has_sequence($s) { + return $s =~ /(.)(?!\1)(.)\2\1/; +} diff --git a/2016/07/2.pl b/2016/07/2.pl new file mode 100644 index 0000000..a2b8cef --- /dev/null +++ b/2016/07/2.pl @@ -0,0 +1,26 @@ +use 5.20.0; +use experimental qw/ signatures /; +use List::AllUtils qw/ reduce none all any /; +use DDP; + +say scalar +grep { + has_sequence($_) +} map { chomp; $_ } <>; + +sub has_sequence($s) { + my @inner = $s =~ /\[(.*?)\]/g; + + for ( split /\[.*?\]/ ) { + while( length($_) >= 3 ) { + my $sub = substr $_, 0, 3; + if( $sub =~ /(.)(?!\1)(.)\1/ ) { + my $code = "$2$1$2"; + return 1 if any { -1 < index $_, $code } @inner; + } + s/^.//; + } + } + + return; +} diff --git a/2016/07/test b/2016/07/test new file mode 100644 index 0000000..12c5063 --- /dev/null +++ b/2016/07/test @@ -0,0 +1,3 @@ +aaaa[qwer]tyui +ioxxoj[asdfgh]zxcvbn +