-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask_11.pl
More file actions
97 lines (75 loc) · 2.16 KB
/
task_11.pl
File metadata and controls
97 lines (75 loc) · 2.16 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/perl
#===============================================================================
#
# FILE: task_11.pl
#
# USAGE: ./task_11.pl
#
# DESCRIPTION: www.adventofcode.com Task 11
#
# OPTIONS: ---
# REQUIREMENTS: ---
# BUGS: ---
# NOTES: ---
# AUTHOR: YOUR NAME (),
# ORGANIZATION:
# VERSION: 1.0
# CREATED: 12/11/2018 07:43:08 PM
# REVISION: ---
#===============================================================================
use strict;
use warnings;
use 5.026;
use Data::Dumper;
my $max_square = shift;
my $grid = shift;
my $grid_size = shift;
my %arr;
my %square_cache;
my $max = 0;
my $maxx = 0;
my $maxy = 0;
for my $x ( 1 .. $grid_size ) {
for my $y ( 1 .. $grid_size ) {
$arr{$x}{$y} = ( ( ( ( ( ( $x + 10 ) * $y ) + $grid ) * ( $x + 10 ) ) / 100 ) % 10 ) - 5;
$square_cache{$x}{$y}{1} = $arr{$x}{$y};
if ( $arr{$x}{$y} > $max ) {
$max = $arr{$x}{$y};
$maxx = $x;
$maxy = $y;
say "max $max $maxx $maxy";
}
}
}
for my $size ( 2 .. $max_square ) {
say "to do size $size";
# 2..3
for my $x ( 1 .. $grid_size - $size + 1 ) {
# 1 .. $grid_size -3 +1=298
# say "x $x";
for my $y ( 1 .. $grid_size - $size + 1 ) {
# say "y $y";
# say "arr " . $arr{$x}{$y};
# 1 .. $grid_size-3+1 = 298
my $value = $square_cache{$x}{$y}{ $size - 1 };
#add extra column
for my $dx ( $x .. $x + $size - 1 ) {
$value += $arr{$dx}{ $y + $size - 1 };
}
#add extra row
for my $dy ( $y .. $y + $size - 2 ) {
$value += $arr{ $x + $size - 1 }{$dy};
}
$square_cache{$x}{$y}{$size} = $value;
# say "size $size value $value square_cache" . $square_cache{$x}{$y}{$size};
if ( $value > $max ) {
$max = $value;
$maxx = $x;
$maxy = $y;
say "max $max $maxx $maxy size $size";
}
}
}
}
say "max $max $maxx $maxy";
return 1;