-
Notifications
You must be signed in to change notification settings - Fork 0
/
Day2b.pl
60 lines (49 loc) · 1.11 KB
/
Day2b.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
use strict;
use warnings;
my $filename = 'Day2.source.txt';
open(my $fh, '<:encoding(UTF-8)', $filename)
or die "Could not open file '$filename' $!";
my $row = <$fh>;
my @OpCodes=split(',',$row);
my @OpCodesOrig=split(',',$row);
for (my $x=0; $x <=99; $x++)
{
for (my $y=0; $y<=99; $y++)
{
my $idx=0;
@OpCodes=@OpCodesOrig;
$OpCodes[1]=$x;
$OpCodes[2]=$y;
while ($OpCodes[$idx]!=99)
{
#print join(",",@OpCodes)."\n";
my $op=$OpCodes[$idx];
my $firstNumber=$OpCodes[$idx+1];
my $secondNumber=$OpCodes[$idx+2];
my $Destination=$OpCodes[$idx+3];
#print $op." ".$OpCodes[$firstNumber]." ".$OpCodes[$secondNumber]." ".$OpCodes[$Destination]."\n";
if ($op==1)
{
$OpCodes[$Destination]=$OpCodes[$firstNumber]+$OpCodes[$secondNumber];
#print $OpCodes[$Destination];
}
elsif ($op==2)
{
$OpCodes[$Destination]=$OpCodes[$firstNumber]*$OpCodes[$secondNumber];
#print $OpCodes[$Destination];
}
elsif ($op==99)
{
print $OpCodes[0];
}
$idx = $idx+4;
#print "\n\n\n";
}
#print $OpCodes[0];
if ($OpCodes[0]==19690720)
{
print $OpCodes[1]." ".$OpCodes[2]."\n";
print 100*$OpCodes[1]+$OpCodes[2];
}
}
}