From bf16b19b1f6deffd1983efca059db576f3b60ee5 Mon Sep 17 00:00:00 2001 From: Yigit Sever Date: Mon, 13 Dec 2021 10:40:39 +0300 Subject: 2019, tracking --- 2019/day2/1202.in | 1 + 2019/day2/intcode.pl | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 2019/day2/1202.in create mode 100644 2019/day2/intcode.pl (limited to '2019/day2') 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 @@ +use strict; +use warnings; +use Data::Dumper; +# use Smart::Comments; + +my $inputline = ; +chomp $inputline; +my @memory = split /,/, $inputline; + +@memory = map {int $_} @memory; + +my $op_code_pos = 0; +my $pos_1 = 1; +my $pos_2 = 2; +my $loc_pos = 3; +my $pc = 4; + +my @actions = (sub {print "noop"}, sub {return $_[0] + $_[1]}, sub {return $_[0] * $_[1]}); + +my $output = 0; + +my $one_inc = 0; +my $two_inc = 0; +my $turn = 0; +my @mem = @memory; + +foreach my $x (0..99) { + foreach my $y (0..99) { + + @mem = @memory; + $mem[1] = $x; + $mem[2] = $y; + + for (my $add = 0; $add < scalar @mem; $add += $pc) { + + my $op_code = $mem[$add + $op_code_pos]; + last if ($op_code == 99); + + my $op_1 = $mem[$mem[$add + $pos_1]]; + my $op_2 = $mem[$mem[$add + $pos_2]]; + my $loc = $mem[$add + $loc_pos]; + my $res = $actions[$op_code]->($op_1, $op_2); + + $mem[$loc] = $res; + } + $output = $mem[0]; + ### $output + exit if $output == 19690720; + } +} + +# print Dumper \@mem; +# print join ',', @mem; +END { + print STDERR "Output: >$mem[0]<\nFor mem[1] = $mem[1] and mem[2] = $mem[2]\n"; + print 100 * $mem[1] + $mem[2]; +} -- cgit v1.2.3-70-g09d2