-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask3_2.pl
More file actions
66 lines (54 loc) · 1.47 KB
/
task3_2.pl
File metadata and controls
66 lines (54 loc) · 1.47 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
58
59
60
61
62
63
64
#!/usr/bin/perl
#===============================================================================
#
# FILE: task3_2.pl
#
# USAGE: ./task3_2.pl
#
# DESCRIPTION: https://adventofcode.com/2018/day/3 part 2
#
# 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 Data::Dumper;
open (my $infile, '<', 'input3.txt');
my %fields;
while (<$infile>) {
chomp;
my ($order) = $_ =~ /\#(\d+)/msx;
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}++;
}
}
}
close $infile;
open ($infile, '<', 'input3.txt');
while (<$infile>) {
chomp;
my ($order) = $_ =~ /\#(\d+)/msx;
my ($shift, $dimensions) = split /:/msx;
my ($shiftx, $shifty) = $shift =~ /(\d+),(\d+)/msx;
my ($dimensionx, $dimensiony) = $dimensions =~ /(\d+)x(\d+)/msx;
my $ok = 1;
for my $x (1 .. $dimensionx) {
for my $y (1 .. $dimensiony) {
$ok = 0 if $fields{$shiftx + $x}{$shifty + $y}>1;
}
}
say $order if $ok;
}