summaryrefslogtreecommitdiffstats
path: root/2019/day2
diff options
context:
space:
mode:
authorYigit Sever2021-12-13 10:40:39 +0300
committerYigit Sever2021-12-13 10:40:39 +0300
commitbf16b19b1f6deffd1983efca059db576f3b60ee5 (patch)
tree1262f68d8eb2c326684d395aebcd5a1cc0b0f748 /2019/day2
parent74b27ccca31bb757c737dd7fdc02f513f57561b2 (diff)
downloadaoc-bf16b19b1f6deffd1983efca059db576f3b60ee5.tar.gz
aoc-bf16b19b1f6deffd1983efca059db576f3b60ee5.tar.bz2
aoc-bf16b19b1f6deffd1983efca059db576f3b60ee5.zip
2019, tracking
Diffstat (limited to '2019/day2')
-rw-r--r--2019/day2/1202.in1
-rw-r--r--2019/day2/intcode.pl57
2 files changed, 58 insertions, 0 deletions
diff --git a/2019/day2/1202.in b/2019/day2/1202.in
new file mode 100644
index 0000000..6bbbce6
--- /dev/null
+++ b/2019/day2/1202.in
@@ -0,0 +1 @@
1,0,0,3,1,1,2,3,1,3,4,3,1,5,0,3,2,6,1,19,1,5,19,23,2,6,23,27,1,27,5,31,2,9,31,35,1,5,35,39,2,6,39,43,2,6,43,47,1,5,47,51,2,9,51,55,1,5,55,59,1,10,59,63,1,63,6,67,1,9,67,71,1,71,6,75,1,75,13,79,2,79,13,83,2,9,83,87,1,87,5,91,1,9,91,95,2,10,95,99,1,5,99,103,1,103,9,107,1,13,107,111,2,111,10,115,1,115,5,119,2,13,119,123,1,9,123,127,1,5,127,131,2,131,6,135,1,135,5,139,1,139,6,143,1,143,6,147,1,2,147,151,1,151,5,0,99,2,14,0,0
diff --git a/2019/day2/intcode.pl b/2019/day2/intcode.pl
new file mode 100644
index 0000000..984784a
--- /dev/null
+++ b/2019/day2/intcode.pl
@@ -0,0 +1,57 @@
1use strict;
2use warnings;
3use Data::Dumper;
4# use Smart::Comments;
5
6my $inputline = <STDIN>;
7chomp $inputline;
8my @memory = split /,/, $inputline;
9
10@memory = map {int $_} @memory;
11
12my $op_code_pos = 0;
13my $pos_1 = 1;
14my $pos_2 = 2;
15my $loc_pos = 3;
16my $pc = 4;
17
18my @actions = (sub {print "noop"}, sub {return $_[0] + $_[1]}, sub {return $_[0] * $_[1]});
19
20my $output = 0;
21
22my $one_inc = 0;
23my $two_inc = 0;
24my $turn = 0;
25my @mem = @memory;
26
27foreach my $x (0..99) {
28 foreach my $y (0..99) {
29
30 @mem = @memory;
31 $mem[1] = $x;
32 $mem[2] = $y;
33
34 for (my $add = 0; $add < scalar @mem; $add += $pc) {
35
36 my $op_code = $mem[$add + $op_code_pos];
37 last if ($op_code == 99);
38
39 my $op_1 = $mem[$mem[$add + $pos_1]];
40 my $op_2 = $mem[$mem[$add + $pos_2]];
41 my $loc = $mem[$add + $loc_pos];
42 my $res = $actions[$op_code]->($op_1, $op_2);
43
44 $mem[$loc] = $res;
45 }
46 $output = $mem[0];
47 ### $output
48 exit if $output == 19690720;
49 }
50}
51
52# print Dumper \@mem;
53# print join ',', @mem;
54END {
55 print STDERR "Output: >$mem[0]<\nFor mem[1] = $mem[1] and mem[2] = $mem[2]\n";
56 print 100 * $mem[1] + $mem[2];
57}