-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask2_1.pl
More file actions
57 lines (44 loc) · 1.06 KB
/
task2_1.pl
File metadata and controls
57 lines (44 loc) · 1.06 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/perl
#===============================================================================
#
# FILE: task2_1.pl
#
# USAGE: ./task2_1.pl
#
# DESCRIPTION: https://adventofcode.com/2018/day/2 part 1
#
# OPTIONS: ---
# REQUIREMENTS: ---
# BUGS: ---
# NOTES: ---
# AUTHOR: YOUR NAME (),
# ORGANIZATION:
# VERSION: 1.0
# CREATED: 12/02/2018 02:10:32 PM
# REVISION: ---
#===============================================================================
use strict;
use warnings;
use autodie;
use 5.026;
use List::Util;
open (my $infile, '<', 'input2_1.txt');
my %globalcounts;
while (<$infile>) {
chomp;
my %counts;
my $input = $_;
foreach my $char ( split //, $input ) { $counts{$char}++ };
my %counts2;
for my $key (keys %counts) {
$counts2{$counts{$key}} = 1 if $counts{$key} > 1;
}
for my $key (keys %counts2) {
$globalcounts{$key}++;
}
}
my $result = 1;
for my $key (keys %globalcounts) {
$result = $result * $globalcounts{$key}++;
}
say $result;