-
Notifications
You must be signed in to change notification settings - Fork 0
/
day19b.pl
executable file
·74 lines (56 loc) · 1.27 KB
/
day19b.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env perl
#
# Size of map - 48 wide (including \n) x 65 = 3120
#
use strict;
use warnings;
use utf8;
use Path::Tiny;
use IntCode;
my $program = IntCode->new( 'input19.txt' );
{ package Beam;
my $size = $ARGV[0] || 100;
# Assume beam always goes to the right
sub bounds {
my ($self) = @_;
my $row = ++$self->{ row };
my $max_x = $self->{ max_x };
while ($program->init->run( $max_x, $row )->[0] == 0) {
$max_x++;
}
while ($program->init->run( $max_x, $row )->[0] == 1) {
$max_x++;
}
$self->{ max_x } = $max_x - 1;
return $self;
}
sub box {
my ($self) = @_;
while (1) {
$self->bounds();
next if ($self->{ max_x } < $size);
if ($program->init->run( $self->{ max_x } - $size + 1, $self->{ row } + $size - 1)->[0] == 1) {
return ($self->{ max_x } - $size + 1) * 10000 + $self->{ row };
}
}
return;
}
sub new {
my ($class, $start_x, $start_y) = @_;
my $self = {
max_x => $start_x,
row => $start_y,
};
bless $self, $class;
return $self;
}
}
use Data::Dumper;
my $count = 0;
#
# In graphing the tractor beam, it seems the beam skips the first two
# rows :-(
#
my $beam = Beam->new( 4, 3 );
print "The score is ", $beam->box(), "\n";
exit;