From 4bb6f8d06c0e384f3394012b1d48da58ed28cc5e Mon Sep 17 00:00:00 2001 From: Yigit Sever Date: Sun, 12 Dec 2021 01:24:32 +0300 Subject: 2020, tracking --- 2020/day2/pwindexcheck.pl | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 2020/day2/pwindexcheck.pl (limited to '2020/day2/pwindexcheck.pl') diff --git a/2020/day2/pwindexcheck.pl b/2020/day2/pwindexcheck.pl new file mode 100644 index 0000000..69a26b5 --- /dev/null +++ b/2020/day2/pwindexcheck.pl @@ -0,0 +1,19 @@ +use strict; +use warnings; + +open my $fh, '<', "input" or die "no input present, $!"; + +my $valid = 0; + +while (my $line = <$fh>) { + chomp $line; + if ($line =~ m/(?\d+)-(?\d+) (?\w): (?\w+)/) { + + my $first = substr( $+{rest}, $+{idx_1} - 1 , 1 ); + my $second = substr( $+{rest}, $+{idx_2} - 1 , 1 ); + + $valid++ if $first eq $+{char} xor $second eq $+{char}; + } +} + +print("$valid"); -- cgit v1.2.3-70-g09d2