first few days
This commit is contained in:
parent
8764f51187
commit
d3ae65f625
12 changed files with 343 additions and 0 deletions
35
2/1.pl
Normal file
35
2/1.pl
Normal file
|
@ -0,0 +1,35 @@
|
|||
#!/usr/bin/perl
|
||||
|
||||
use strict;
|
||||
|
||||
chomp (my @data = <STDIN>);
|
||||
|
||||
my ($ck2, $ck3);
|
||||
foreach my $w (@data) {
|
||||
my ($r2, $r3) = checksum($w);
|
||||
#print "$r2, $r3\n";
|
||||
$ck2 += $r2;
|
||||
$ck3 += $r3;
|
||||
}
|
||||
print $ck2 * $ck3 . "\n";
|
||||
|
||||
|
||||
sub checksum {
|
||||
my $word = shift;
|
||||
|
||||
my %seen;
|
||||
foreach my $letter (split //, $word) {
|
||||
$seen{$letter}++
|
||||
}
|
||||
|
||||
my $twos = 0;
|
||||
my $threes = 0;
|
||||
foreach my $k (keys %seen) {
|
||||
# print "$k $seen{$k}\n";
|
||||
$twos=1 if ($seen{$k} == 2);
|
||||
$threes=1 if ($seen{$k} == 3);
|
||||
}
|
||||
|
||||
return ($twos, $threes);
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue