aboutsummaryrefslogtreecommitdiff
path: root/2018/02/puzzle-1.pl
blob: 85a533b5633059038cc7196cc630c4357fd1119e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/usr/bin/perl

use strict;
use warnings;

my $file = "input";
open my $in, "<", $file or die "Failed to open ‘$file’: $!";

my ($x, $y) = (0) x 2;
while (<$in>) {
	chomp;
	my %freq;
	$freq{$_}++ for split //;
	$x++ if grep { $_ == 2 } values %freq;
	$y++ if grep { $_ == 3 } values %freq;
}

close $in;
printf "%d\n", $x * $y;