This commit is contained in:
Yanick Champoux 2017-12-14 14:41:37 -05:00
parent 1f0c8ef911
commit b34285bcf9
3 changed files with 129 additions and 0 deletions

40
2015/23/1.pl Normal file
View File

@ -0,0 +1,40 @@
use 5.20.0;
my @code = <>;
my $i = 0;
my %t;
while( $i < @code ) {
warn join ' ', $i, $t{a}, $t{b}, $code[$i];
# my $dummy = <>;
if( $code[$i] =~ /inc (.)/ ) {
$t{$1}++;
$i++;
}
elsif( $code[$i] =~ /tpl (.)/ ) {
$t{$1} *= 3;
$i++;
}
elsif( $code[$i] =~ /hlf (.)/ ) {
$t{$1} /= 2;
warn $t{$1};
$i++;
}
elsif( $code[$i] =~ /jmp ([+-]\d+)/ ) {
$i+=$1;
}
elsif( $code[$i] =~ /jie (.), ([+-]\d+)/ ) {
$i+= ($t{$1} % 2) ? 1 : $2;
}
elsif( $code[$i] =~ /jio (.), ([+-]\d+)/ ) {
$i+= ($t{$1} != 1) ? 1 : $2;
warn $i;
}
}
use DDP;
p %t;

40
2015/23/2.pl Normal file
View File

@ -0,0 +1,40 @@
use 5.20.0;
my @code = <>;
my $i = 0;
my %t = ( a => 1 );
while( $i < @code ) {
warn join ' ', $i, $t{a}, $t{b}, $code[$i];
# my $dummy = <>;
if( $code[$i] =~ /inc (.)/ ) {
$t{$1}++;
$i++;
}
elsif( $code[$i] =~ /tpl (.)/ ) {
$t{$1} *= 3;
$i++;
}
elsif( $code[$i] =~ /hlf (.)/ ) {
$t{$1} /= 2;
warn $t{$1};
$i++;
}
elsif( $code[$i] =~ /jmp ([+-]\d+)/ ) {
$i+=$1;
}
elsif( $code[$i] =~ /jie (.), ([+-]\d+)/ ) {
$i+= ($t{$1} % 2) ? 1 : $2;
}
elsif( $code[$i] =~ /jio (.), ([+-]\d+)/ ) {
$i+= ($t{$1} != 1) ? 1 : $2;
warn $i;
}
}
use DDP;
p %t;

49
2015/23/input.txt Normal file
View File

@ -0,0 +1,49 @@
jio a, +19
inc a
tpl a
inc a
tpl a
inc a
tpl a
tpl a
inc a
inc a
tpl a
tpl a
inc a
inc a
tpl a
inc a
inc a
tpl a
jmp +23
tpl a
tpl a
inc a
inc a
tpl a
inc a
inc a
tpl a
inc a
tpl a
inc a
tpl a
inc a
tpl a
inc a
inc a
tpl a
inc a
inc a
tpl a
tpl a
inc a
jio a, +8
inc b
jie a, +4
tpl a
inc a
jmp +2
hlf a
jmp -7