diff options
author | Yigit Sever | 2021-12-13 10:40:39 +0300 |
---|---|---|
committer | Yigit Sever | 2021-12-13 10:40:39 +0300 |
commit | bf16b19b1f6deffd1983efca059db576f3b60ee5 (patch) | |
tree | 1262f68d8eb2c326684d395aebcd5a1cc0b0f748 /2019/day2 | |
parent | 74b27ccca31bb757c737dd7fdc02f513f57561b2 (diff) | |
download | aoc-bf16b19b1f6deffd1983efca059db576f3b60ee5.tar.gz aoc-bf16b19b1f6deffd1983efca059db576f3b60ee5.tar.bz2 aoc-bf16b19b1f6deffd1983efca059db576f3b60ee5.zip |
2019, tracking
Diffstat (limited to '2019/day2')
-rw-r--r-- | 2019/day2/1202.in | 1 | ||||
-rw-r--r-- | 2019/day2/intcode.pl | 57 |
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 @@ | |||
1 | use strict; | ||
2 | use warnings; | ||
3 | use Data::Dumper; | ||
4 | # use Smart::Comments; | ||
5 | |||
6 | my $inputline = <STDIN>; | ||
7 | chomp $inputline; | ||
8 | my @memory = split /,/, $inputline; | ||
9 | |||
10 | @memory = map {int $_} @memory; | ||
11 | |||
12 | my $op_code_pos = 0; | ||
13 | my $pos_1 = 1; | ||
14 | my $pos_2 = 2; | ||
15 | my $loc_pos = 3; | ||
16 | my $pc = 4; | ||
17 | |||
18 | my @actions = (sub {print "noop"}, sub {return $_[0] + $_[1]}, sub {return $_[0] * $_[1]}); | ||
19 | |||
20 | my $output = 0; | ||
21 | |||
22 | my $one_inc = 0; | ||
23 | my $two_inc = 0; | ||
24 | my $turn = 0; | ||
25 | my @mem = @memory; | ||
26 | |||
27 | foreach 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; | ||
54 | END { | ||
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 | } | ||