-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask3_1.pl
53 lines (44 loc) · 1.09 KB
/
task3_1.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/perl
#===============================================================================
#
# FILE: t1.pl
#
# USAGE: ./t1.pl
#
# DESCRIPTION: https://adventofcode.com/2018/day/3
#
# OPTIONS: ---
# REQUIREMENTS: ---
# BUGS: ---
# NOTES: ---
# AUTHOR: Lubos Kolouch
# ORGANIZATION:
# VERSION: 1.0
# CREATED: 12/02/2018 02:10:32 PM
# REVISION: ---
#===============================================================================
use strict;
use warnings;
use autodie;
use 5.026;
use Data::Dumper;
open (my $infile, '<', 'input3.txt');
my %fields;
while (<$infile>) {
chomp;
my ($shift, $dimensions) = split /:/msx;
my ($shiftx, $shifty) = $shift =~ /(\d+),(\d+)/msx;
my ($dimensionx, $dimensiony) = $dimensions =~ /(\d+)x(\d+)/msx;
for my $x (1 .. $dimensionx) {
for my $y (1 .. $dimensiony) {
$fields{$shiftx + $x}{$shifty + $y}++;
}
}
}
my $result;
for my $key (keys %fields) {
for my $key2 (keys %{$fields{$key}}) {
$result++ if $fields{$key}{$key2}>1;
}
}
say $result;