-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay5-2.pl
33 lines (30 loc) · 899 Bytes
/
Day5-2.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/perl
use strict;
my @nice;
my ($O, $P) = 0;
open (IN, $ARGV[0]);
while (my $string = <IN>) {
#my @test=("qjhvhtzxzqqjkmpb", "xxyxx", "uurcxstgmygtbstg", "ieodomkazucvgmuy");
#foreach my $string (@test) {
my($repeatPair, $oneBetween);
chomp $string;
while ($string =~ /(..)/g) {
my $target = $1;
my $query = $`. " " . $';
#print "$string\t$target\t$query\n";
if ($query =~ /$target/) { $repeatPair = 1; last; }
pos $string -= 1;
}
my @char = split//, $string;
for (my $i=0; $i<@char; $i++) {
if (defined $char[$i+2] && $char[$i] eq $char[$i+2]) { $oneBetween = 1; last; }
}
if ($oneBetween && $repeatPair) {
print "$string\tNice\n";
push @nice, $string; }
else { print "$string\tNaughty\t$repeatPair\t$oneBetween\n"; }
$P+=$repeatPair;
$O+= $oneBetween;
}
print "Nice: " . @nice . "\n";
print "repeatPair: $P\noneBetween: $O\n";